From 214ef762a970989e09be1960c5551c0a4d3f4421 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 31 Aug 2013 15:15:53 +0200 Subject: do not leave behind users in billing unit and functional tests --- billing/test/functional/customer_controller_test.rb | 13 ++++++++++--- billing/test/functional/payments_controller_test.rb | 4 +++- billing/test/unit/customer_test.rb | 4 +++- billing/test/unit/customer_with_payment_info_test.rb | 5 ++++- 4 files changed, 20 insertions(+), 6 deletions(-) (limited to 'billing/test') diff --git a/billing/test/functional/customer_controller_test.rb b/billing/test/functional/customer_controller_test.rb index d62ee95..878ed48 100644 --- a/billing/test/functional/customer_controller_test.rb +++ b/billing/test/functional/customer_controller_test.rb @@ -21,7 +21,9 @@ class CustomerControllerTest < ActionController::TestCase end test "edit uses params[:id]" do - customer = FactoryGirl.create :customer_with_payment_info + user = find_record :user + customer = stub_record :customer_with_payment_info, user: user + Customer.stubs(:find_by_user_id).with(user.id).returns(customer) login customer.user get :edit, id: customer.user.id @@ -50,7 +52,10 @@ class CustomerControllerTest < ActionController::TestCase end test "customer update" do - customer = FactoryGirl.create :customer_with_payment_info + user = find_record :user + customer = stub_record :customer_with_payment_info, user: user + customer.expects(:save) + Customer.stubs(:find_by_user_id).with(user.id).returns(customer) login customer.user Braintree::TransparentRedirect.expects(:confirm). returns(success_response(customer)) @@ -91,7 +96,9 @@ class CustomerControllerTest < ActionController::TestCase end test "failed user update with stubbing" do - customer = FactoryGirl.create :customer_with_payment_info + user = find_record :user + customer = stub_record :customer_with_payment_info, user: user + Customer.stubs(:find_by_user_id).with(user.id).returns(customer) login customer.user Braintree::TransparentRedirect.expects(:confirm).returns(failure_response) post :confirm, bla: :blub diff --git a/billing/test/functional/payments_controller_test.rb b/billing/test/functional/payments_controller_test.rb index 8f3bfe7..055a990 100644 --- a/billing/test/functional/payments_controller_test.rb +++ b/billing/test/functional/payments_controller_test.rb @@ -17,7 +17,9 @@ class PaymentsControllerTest < ActionController::TestCase end test "payment when authenticated as customer" do - customer = FactoryGirl.create :customer_with_payment_info + user = find_record :user + customer = stub_record :customer_with_payment_info, user: user + Customer.stubs(:find_by_user_id).with(user.id).returns(customer) login customer.user get :new assert_not_nil assigns(:tr_data) diff --git a/billing/test/unit/customer_test.rb b/billing/test/unit/customer_test.rb index 2ea0b5e..6156f87 100644 --- a/billing/test/unit/customer_test.rb +++ b/billing/test/unit/customer_test.rb @@ -1,9 +1,11 @@ require 'test_helper' class CustomerTest < ActiveSupport::TestCase + include StubRecordHelper setup do - @customer = FactoryGirl.build(:customer) + @user = find_record :user + @customer = FactoryGirl.build(:customer, user: @user) end test "test set of attributes should be valid" do diff --git a/billing/test/unit/customer_with_payment_info_test.rb b/billing/test/unit/customer_with_payment_info_test.rb index ca89e65..0589a59 100644 --- a/billing/test/unit/customer_with_payment_info_test.rb +++ b/billing/test/unit/customer_with_payment_info_test.rb @@ -2,9 +2,11 @@ require 'test_helper' require 'fake_braintree' class CustomerWithPaymentInfoTest < ActiveSupport::TestCase + include StubRecordHelper setup do - @customer = FactoryGirl.build(:customer_with_payment_info) + @user = find_record :user + @customer = FactoryGirl.build(:customer_with_payment_info, user: @user) end test "has payment_info" do @@ -28,6 +30,7 @@ class CustomerWithPaymentInfoTest < ActiveSupport::TestCase assert_equal 'Spender', @customer.last_name assert_equal 1, @customer.credit_cards.size assert_equal Hash.new, @customer.custom_fields + @customer.destroy end test "sets default_credit_card" do -- cgit v1.2.3 From a4ab73f54dcfa6e5da85a20eba27034af4496269 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 31 Aug 2013 16:04:18 +0200 Subject: different tests need different names --- billing/test/integration/admin_customer_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'billing/test') diff --git a/billing/test/integration/admin_customer_test.rb b/billing/test/integration/admin_customer_test.rb index 5169d85..58a7557 100644 --- a/billing/test/integration/admin_customer_test.rb +++ b/billing/test/integration/admin_customer_test.rb @@ -2,7 +2,7 @@ require 'test_helper' require 'fake_braintree' require 'capybara/rails' -class CustomerCreationTest < ActionDispatch::IntegrationTest +class AdminCustomerTest < ActionDispatch::IntegrationTest include Warden::Test::Helpers include Capybara::DSL -- cgit v1.2.3 From 2de9e85111b9a4bbc76bd3e141bec4f48a52ae12 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 31 Aug 2013 16:04:42 +0200 Subject: remove the user after integration testing customer creation --- billing/test/integration/customer_creation_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'billing/test') diff --git a/billing/test/integration/customer_creation_test.rb b/billing/test/integration/customer_creation_test.rb index 5e3734c..aabd9b6 100644 --- a/billing/test/integration/customer_creation_test.rb +++ b/billing/test/integration/customer_creation_test.rb @@ -13,6 +13,7 @@ class CustomerCreationTest < ActionDispatch::IntegrationTest end teardown do + @user.destroy Warden.test_reset! end -- cgit v1.2.3