diff options
-rw-r--r-- | billing/test/integration/subscription_test.rb | 31 | ||||
-rw-r--r-- | billing/test/support/customer_test_helper.rb | 4 |
2 files changed, 18 insertions, 17 deletions
diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb index c53131e..b893896 100644 --- a/billing/test/integration/subscription_test.rb +++ b/billing/test/integration/subscription_test.rb @@ -5,32 +5,31 @@ require 'capybara/rails' class SubscriptionTest < ActionDispatch::IntegrationTest include Warden::Test::Helpers include Capybara::DSL + include CustomerTestHelper + include StubRecordHelper setup do Warden.test_mode! - @admin = User.find_by_login('admin') || FactoryGirl.create(:user, login: 'admin') - @customer = FactoryGirl.create(:customer) - @braintree_customer = FactoryGirl.create(:braintree_customer) - @customer.braintree_customer_id = @braintree_customer.id - @customer.save + @admin = stub_record :user, :admin => true + @customer = stub_customer + @braintree_customer = @customer.braintree_customer + response = Braintree::Subscription.create plan_id: '5', + payment_method_token: @braintree_customer.credit_cards.first.token + @subscription = response.subscription + Capybara.current_driver = Capybara.javascript_driver end teardown do Warden.test_reset! - @admin.destroy - @customer.destroy end - test "can create subscription" do - @subscription = FakeBraintree::Subscription.new({:payment_method_token => @braintree_customer.credit_cards.first, :plan_id => '5'}, {:id => @braintree_customer.id, :merchant_id => Braintree::Configuration.merchant_id}) - assert @braintree_customer.credit_cards.first.subscriptions.present? - end - - test "admin can cancel subscription for another" do - skip "not sure about testing admin cancelling subscription with fake_braintree" + test "admin can see subscription for another" do login_as @admin - #visit user_subscriptions_path(@customer.user_id) - #delete :destroy, :id => @subscription.id + @customer.stubs(:subscriptions).returns([@subscription]) + visit user_subscriptions_path(@customer.user_id) + assert page.has_content?("Subscriptions") + assert page.has_content?("Status: Active") + page.save_screenshot('/tmp/subscriptions.png') end #test "admin cannot add subscription for another" do diff --git a/billing/test/support/customer_test_helper.rb b/billing/test/support/customer_test_helper.rb index ad72edd..adac00a 100644 --- a/billing/test/support/customer_test_helper.rb +++ b/billing/test/support/customer_test_helper.rb @@ -2,7 +2,9 @@ module CustomerTestHelper def stub_customer(user = nil) user ||= find_record :user - customer = stub_record :customer_with_payment_info, user: user + customer = stub_record :customer_with_payment_info, + user: user, + user_id: user.id Customer.stubs(:find_by_user_id).with(user.id).returns(customer) return customer end |