Skip to content

Commit f2b194e

Browse files
author
Nicholas Firth-McCoy
committed
Don't set a stripe_customer_id in subscription factory by default
Now if a subscription has a stripe_customer_id present when it is created it is treated differently - we attempt to look up and use the existing Stripe customer. In our specs, we normally don't want this to be the case. We only want a stripe_customer_id to be present when testing the new functionality, or when we're dealing with a subscription that's already active (eg. when updating it or cancelling it). Stop setting the stripe_customer_id by default in the factory, and set it explicitly when we expect it to be present.
1 parent b5e7a2a commit f2b194e

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

app/models/payola/subscription.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def redirector
128128
end
129129

130130
def conditional_stripe_token
131+
# Don't require a Stripe token if we're creating a subscription for an existing Stripe customer
132+
return true if stripe_customer_id.present?
131133
return true if plan.nil?
132134
if (plan.amount > 0 )
133135
if plan.respond_to?(:trial_period_days) and (plan.trial_period_days.nil? or ( plan.trial_period_days and !(plan.trial_period_days > 0) ))

spec/controllers/payola/subscriptions_controller_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module Payola
9797

9898
describe '#destroy' do
9999
before :each do
100-
@subscription = create(:subscription, :state => :active)
100+
@subscription = create(:subscription, state: :active, stripe_customer_id: Stripe::Customer.create.id)
101101
end
102102
it "call Payola::CancelSubscription and redirect" do
103103
Payola::CancelSubscription.should_receive(:call)
@@ -124,7 +124,7 @@ module Payola
124124

125125
describe '#change_plan' do
126126
before :each do
127-
@subscription = create(:subscription, state: :active)
127+
@subscription = create(:subscription, state: :active, stripe_customer_id: Stripe::Customer.create.id)
128128
@plan = create(:subscription_plan)
129129
end
130130

@@ -158,7 +158,7 @@ module Payola
158158

159159
describe '#change_quantity' do
160160
before :each do
161-
@subscription = create(:subscription, state: :active)
161+
@subscription = create(:subscription, state: :active, stripe_customer_id: Stripe::Customer.create.id)
162162
@plan = create(:subscription_plan)
163163
end
164164

@@ -192,7 +192,7 @@ module Payola
192192

193193
describe "#update_card" do
194194
before :each do
195-
@subscription = create(:subscription, state: :active)
195+
@subscription = create(:subscription, state: :active, stripe_customer_id: Stripe::Customer.create.id)
196196
@plan = create(:subscription_plan)
197197
end
198198

spec/factories/payola_subscriptions.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
status "MyString"
99
owner_type "Owner"
1010
owner_id 1
11-
stripe_customer_id "MyString"
1211
cancel_at_period_end false
1312
current_period_start "2014-11-04 22:34:39"
1413
current_period_end "2014-11-04 22:34:39"

0 commit comments

Comments
 (0)