From e4460bffe2e6a2a4b4edb663332aa57ac17b3370 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 3 Jul 2013 12:55:19 +0200 Subject: billing: fix integration test This actually required three little fixes: * couchrest_session_store updated to 0.1.2 to make sure we store sessions * use BraintreeTestApp to proxy braintree requests that RackTest assumes are local * do not attempt to read status after a capybara request Also refactored the test a bit to set @user and login during setup. --- billing/test/integration/customer_creation_test.rb | 36 ++++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'billing/test/integration/customer_creation_test.rb') diff --git a/billing/test/integration/customer_creation_test.rb b/billing/test/integration/customer_creation_test.rb index 50116db..3ab2e4f 100644 --- a/billing/test/integration/customer_creation_test.rb +++ b/billing/test/integration/customer_creation_test.rb @@ -8,17 +8,32 @@ class CustomerCreationTest < ActionDispatch::IntegrationTest setup do Warden.test_mode! + @user = FactoryGirl.create(:user) + login_as @user end teardown do Warden.test_reset! end + # Let's test both steps together with capybara + # + # This test is nice and clean but also a bit fragil: + # RackTest assumes all requests to be local. So we need + # BraintreeTestApp for the braintree transparent redirect to work. + test "create customer with braintree" do + visit '/customer/new' + assert_difference("Customer.count") do + click_button 'Save Payment Info' + end + + assert customer = Customer.find_by_user_id(@user.id) + assert customer.braintree_customer + end + # We only test the confirmation here. - # The first request to Braintree is triggered outside of rails + # The request to Braintree is triggered outside of rails test "successfully confirms customer creation" do - user = FactoryGirl.create(:user) - login_as user response = post_transparent_redirect :create_customer_data, customer: FactoryGirl.attributes_for(:braintree_customer), redirect_url: confirm_customer_url @@ -28,20 +43,7 @@ class CustomerCreationTest < ActionDispatch::IntegrationTest end assert_equal 200, status - assert customer = Customer.find_by_user_id(user.id) - assert customer.braintree_customer - end - - # let's test both steps together with capybara - test "create customer with braintree" do - user = FactoryGirl.create(:user) - login_as user - visit '/customer/new' - assert_difference("Customer.count") do - click_button 'Save Payment Info' - end - assert_equal 200, status - assert customer = Customer.find_by_user_id(user.id) + assert customer = Customer.find_by_user_id(@user.id) assert customer.braintree_customer end -- cgit v1.2.3