summaryrefslogtreecommitdiff
path: root/billing/test/functional
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-09-19 12:07:25 -0700
committerjessib <jessib@riseup.net>2013-09-19 12:07:25 -0700
commit3a2e64c75f67af89ffd78dbf80dd947896d85d22 (patch)
treeea17ee32d763bb875e4814b09ed1f443c112980c /billing/test/functional
parente8a2db42813dc3f5d1ebb95eb896455d7a922505 (diff)
parent890c9e170fc038eccb46eca3c1ddcf6f05eaa53f (diff)
Merge branch 'develop' into feature/only_lower_case_aliases
Diffstat (limited to 'billing/test/functional')
-rw-r--r--billing/test/functional/customer_controller_test.rb23
-rw-r--r--billing/test/functional/payments_controller_test.rb5
-rw-r--r--billing/test/functional/subsciptions_controller_test.rb16
3 files changed, 27 insertions, 17 deletions
diff --git a/billing/test/functional/customer_controller_test.rb b/billing/test/functional/customer_controller_test.rb
index 878ed48..d943e23 100644
--- a/billing/test/functional/customer_controller_test.rb
+++ b/billing/test/functional/customer_controller_test.rb
@@ -2,6 +2,7 @@ require 'test_helper'
require 'fake_braintree'
class CustomerControllerTest < ActionController::TestCase
+ include CustomerTestHelper
test "new assigns redirect url" do
login
@@ -21,9 +22,7 @@ class CustomerControllerTest < ActionController::TestCase
end
test "edit uses params[:id]" do
- user = find_record :user
- customer = stub_record :customer_with_payment_info, user: user
- Customer.stubs(:find_by_user_id).with(user.id).returns(customer)
+ customer = stub_customer
login customer.user
get :edit, id: customer.user.id
@@ -34,7 +33,7 @@ class CustomerControllerTest < ActionController::TestCase
assert_equal confirm_customer_url, tr_data[:redirect_url]
end
- test "confirm user creation" do
+ test "confirm customer creation" do
login
Braintree::TransparentRedirect.expects(:confirm).returns(success_response)
# to_confirm = prepare_confirmation :create_customer_data,
@@ -52,10 +51,8 @@ class CustomerControllerTest < ActionController::TestCase
end
test "customer update" do
- user = find_record :user
- customer = stub_record :customer_with_payment_info, user: user
+ customer = stub_customer
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))
@@ -70,8 +67,8 @@ class CustomerControllerTest < ActionController::TestCase
assert_equal customer.braintree_customer, result.customer
end
- test "failed user creation" do
- skip "can't get user creation to fail"
+ test "failed customer creation" do
+ skip "can't get customer creation to fail"
login
FakeBraintree.decline_all_cards!
# what is prepare_confirmation ?? this method isn't found
@@ -86,7 +83,7 @@ class CustomerControllerTest < ActionController::TestCase
assert !result.success?
end
- test "failed user creation with stubbing" do
+ test "failed customer creation with stubbing" do
login
Braintree::TransparentRedirect.expects(:confirm).returns(failure_response)
post :confirm, bla: :blub
@@ -95,10 +92,8 @@ class CustomerControllerTest < ActionController::TestCase
assert_template :new
end
- test "failed user update with stubbing" do
- user = find_record :user
- customer = stub_record :customer_with_payment_info, user: user
- Customer.stubs(:find_by_user_id).with(user.id).returns(customer)
+ test "failed customer update with stubbing" do
+ customer = stub_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 055a990..655aa16 100644
--- a/billing/test/functional/payments_controller_test.rb
+++ b/billing/test/functional/payments_controller_test.rb
@@ -2,6 +2,7 @@ require 'test_helper'
require 'fake_braintree'
class PaymentsControllerTest < ActionController::TestCase
+ include CustomerTestHelper
test "payment when unauthorized" do
get :new
@@ -17,9 +18,7 @@ class PaymentsControllerTest < ActionController::TestCase
end
test "payment when authenticated as customer" do
- user = find_record :user
- customer = stub_record :customer_with_payment_info, user: user
- Customer.stubs(:find_by_user_id).with(user.id).returns(customer)
+ customer = stub_customer
login customer.user
get :new
assert_not_nil assigns(:tr_data)
diff --git a/billing/test/functional/subsciptions_controller_test.rb b/billing/test/functional/subsciptions_controller_test.rb
new file mode 100644
index 0000000..a6a1057
--- /dev/null
+++ b/billing/test/functional/subsciptions_controller_test.rb
@@ -0,0 +1,16 @@
+require 'test_helper'
+require 'fake_braintree'
+
+class SubscriptionsControllerTest < ActionController::TestCase
+ include CustomerTestHelper
+
+ test "destroy cancels subscription" do
+ customer = stub_customer
+ login customer.user
+ result = Braintree::Subscription.create plan_id: 'my_plan',
+ payment_method_token: customer.braintree_customer.credit_cards.first.token
+ subscription = result.subscription
+ delete :destroy, id: subscription.id, user_id: customer.user.id
+ assert_equal "Canceled", Braintree::Subscription.find(subscription.id).status
+ end
+end