Skip to content

Commit 9beb977

Browse files
authored
Merge pull request payolapayments#250 from eliotsykes/instrument-quantity-changed-fix
Call `instrument_quantity_changed` from `ChangeSubscriptionQuantity`. Closes payolapayments#235.
2 parents a7b175d + 7b4ab3a commit 9beb977

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ All notable changes to Payola will be documented in this file.
77
## Unreleased
88
[Full Changelog](https://github.com/peterkeen/payola/compare/v1.4.0...HEAD)
99

10+
### Bug Fixes
11+
- Call `instrument_quantity_changed` from `ChangeSubscriptionQuantity`. #235
12+
1013
## v1.4.0 - 2016-01-28
1114
[Full Changelog](https://github.com/peterkeen/payola/compare/v1.3.2...v1.4.0)
1215

app/services/payola/change_subscription_quantity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.call(subscription, quantity)
1313
subscription.quantity = quantity
1414
subscription.save!
1515

16-
subscription.instrument_plan_changed(old_quantity)
16+
subscription.instrument_quantity_changed(old_quantity)
1717

1818
rescue RuntimeError, Stripe::StripeError => e
1919
subscription.errors[:base] << e.message

spec/services/payola/change_subscription_quantity_spec.rb

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,44 @@ module Payola
55
let(:stripe_helper) { StripeMock.create_test_helper }
66

77
describe "#call" do
8+
let(:original_quantity) { 1 }
9+
let(:new_quantity) { original_quantity + 1 }
10+
811
before(:each) do
912
@plan = create(:subscription_plan)
1013
expect(@plan.errors).to be_blank
1114

1215
token = StripeMock.generate_card_token({})
13-
@subscription = create(:subscription, quantity: 1, stripe_token: token, plan: @plan, state: 'processing')
16+
@subscription = create(:subscription, quantity: original_quantity, stripe_token: token, plan: @plan, state: 'processing')
1417
StartSubscription.call(@subscription)
1518
expect(@subscription.error).to be_nil
1619
expect(@subscription.active?).to be_truthy
17-
@subscription = Payola::ChangeSubscriptionQuantity.call(@subscription, 2)
18-
expect(@subscription.errors).to be_blank
20+
end
21+
22+
it "should not produce any subscription errors" do
23+
subscription = Payola::ChangeSubscriptionQuantity.call(@subscription, new_quantity)
24+
25+
expect(subscription.errors).to be_blank
1926
end
2027

2128
it "should change the quantity on the stripe subscription" do
22-
customer = Stripe::Customer.retrieve(@subscription.stripe_customer_id)
23-
sub = customer.subscriptions.retrieve(@subscription.stripe_id)
29+
subscription = Payola::ChangeSubscriptionQuantity.call(@subscription, new_quantity)
2430

25-
expect(sub.quantity).to eq 2
31+
customer = Stripe::Customer.retrieve(subscription.stripe_customer_id)
32+
sub = customer.subscriptions.retrieve(subscription.stripe_id)
33+
expect(sub.quantity).to eq new_quantity
2634
end
2735

2836
it "should change the quantity on the payola subscription" do
29-
expect(@subscription.reload.quantity).to eq 2
37+
subscription = Payola::ChangeSubscriptionQuantity.call(@subscription, new_quantity)
38+
39+
expect(subscription.reload.quantity).to eq new_quantity
40+
end
41+
42+
it "should notify quantity has changed" do
43+
expect(@subscription).to receive(:instrument_quantity_changed).with(original_quantity)
44+
45+
Payola::ChangeSubscriptionQuantity.call(@subscription, new_quantity)
3046
end
3147
end
3248
end

0 commit comments

Comments
 (0)