summaryrefslogtreecommitdiff
path: root/billing/test/integration
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-03 12:55:19 +0200
committerAzul <azul@leap.se>2013-07-17 10:47:14 +0200
commite4460bffe2e6a2a4b4edb663332aa57ac17b3370 (patch)
treefc47e214106765bc2937fde58b232dbea1b1ca5f /billing/test/integration
parentb51f300fe374e9eecf7e98266c96631fa3c8a278 (diff)
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.
Diffstat (limited to 'billing/test/integration')
-rw-r--r--billing/test/integration/customer_creation_test.rb36
1 files changed, 19 insertions, 17 deletions
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