require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class Muck::BillingInformationsControllerTest < ActionController::TestCase tests Muck::BillingInformationsController context "billing informations controller" do should_require_login :show => :get, :edit => :get, :update => :put context "when logged in" do setup do @user = Factory(:user) @billing_information = Factory(:billing_information, :billable => @user) activate_authlogic login_as @user @transaction_response = OrderTransaction.new @transaction_response.stubs(:success?).returns(true) OrderTransaction.stubs(:cim_create_update).returns(@transaction_response) end context "GET to edit" do setup do get :edit, :id => @billing_information end should_respond_with :success end context "PUT to update" do context "new BillingInformation - update billing information" do setup do put :update, :billing_information => default_billing end should_respond_with :success should_not_set_the_flash end context "user tries with bad credit card number" do setup do put :update, :billing_information => default_billing(:credit_card_number => 2) end should_respond_with :success should "fail" do assert assigns(:billing_information).errors end end context "user tries without a credit card number" do setup do put :update, :billing_information => default_billing(:credit_card_number => nil) end should_respond_with :success should "fail" do assert assigns(:billing_information).errors end end context "user record is invalid" do setup do put :update, :billing_information => default_billing(:credit_card_number => 3) end should_respond_with :success should "fail" do assert assigns(:billing_information).errors end end end end end end