summaryrefslogtreecommitdiff
path: root/billing/test
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-02 12:52:16 +0200
committerAzul <azul@leap.se>2013-07-17 10:47:14 +0200
commit968448cea22364f1fd423cedc54cf6d8a0f2e09e (patch)
treec3d2f02ea7bf7b32dbabefd80800696e03105d7c /billing/test
parent5589ef858a19f1c46e7e8aa5b364914a5f14352a (diff)
billing: update customer records - do not create new ones
Diffstat (limited to 'billing/test')
-rw-r--r--billing/test/functional/customer_controller_test.rb29
-rw-r--r--billing/test/functional/customers_controller_test.rb4
2 files changed, 29 insertions, 4 deletions
diff --git a/billing/test/functional/customer_controller_test.rb b/billing/test/functional/customer_controller_test.rb
index 86d40fd..af09a41 100644
--- a/billing/test/functional/customer_controller_test.rb
+++ b/billing/test/functional/customer_controller_test.rb
@@ -20,10 +20,10 @@ class CustomerControllerTest < ActionController::TestCase
assert_redirected_to login_path
end
- test "edit uses current_user" do
+ test "edit uses params[:id]" do
customer = FactoryGirl.create :customer_with_payment_info
login customer.user
- get :edit, id: :unused
+ get :edit, id: customer.id
assert_response :success
assert assigns(:tr_data)
@@ -37,7 +37,10 @@ class CustomerControllerTest < ActionController::TestCase
to_confirm = prepare_confirmation :create_customer_data,
customer: FactoryGirl.attributes_for(:braintree_customer),
redirect_url: confirm_customer_url
- post :confirm, to_confirm
+
+ assert_difference("Customer.count") do
+ post :confirm, to_confirm
+ end
assert_response :success
assert result = assigns(:result)
@@ -45,6 +48,21 @@ class CustomerControllerTest < ActionController::TestCase
assert result.customer.id
end
+ test "customer update" do
+ @customer = FactoryGirl.create :customer_with_payment_info
+ login @customer.user
+ Braintree::TransparentRedirect.expects(:confirm).returns(success_response)
+
+ assert_no_difference("Customer.count") do
+ post :confirm, query: :from_braintree
+ end
+
+ assert_response :success
+ assert result = assigns(:result)
+ assert result.success?
+ assert_equal @customer, result.customer
+ end
+
test "failed user creation" do
skip "can't get user creation to fail"
login
@@ -89,6 +107,11 @@ class CustomerControllerTest < ActionController::TestCase
params: {}
end
+ def success_response
+ stub success?: true,
+ customer: @customer.with_braintree_data!
+ end
+
def post_transparent_redirect(type, data)
params = data.dup
params[:tr_data] = Braintree::TransparentRedirect.send(type, params)
diff --git a/billing/test/functional/customers_controller_test.rb b/billing/test/functional/customers_controller_test.rb
index 45a14ed..58b6155 100644
--- a/billing/test/functional/customers_controller_test.rb
+++ b/billing/test/functional/customers_controller_test.rb
@@ -1,6 +1,8 @@
require 'test_helper'
+require 'fake_braintree'
class CustomersControllerTest < ActionController::TestCase
+ tests CustomerController
setup do
@user = FactoryGirl.create :user
@@ -43,7 +45,7 @@ class CustomersControllerTest < ActionController::TestCase
login @other_user
get :new
assert_response :redirect
- assert_equal edit_customer_url(@customer.braintree_customer_id), response.header['Location']
+ assert_equal edit_customer_url(@customer), response.header['Location']
end