payola-payments 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +200 -0
- data/LICENSE +6 -0
- data/README.md +80 -0
- data/Rakefile +5 -4
- data/app/assets/javascripts/payola/application.js +3 -3
- data/app/assets/javascripts/payola/checkout_button.js +29 -19
- data/app/assets/javascripts/payola/subscription_checkout_button.js +7 -1
- data/app/assets/javascripts/payola/subscription_form_onestep.js +27 -0
- data/app/assets/stylesheets/payola/application.css +4 -4
- data/app/controllers/concerns/payola/affiliate_behavior.rb +1 -1
- data/app/controllers/concerns/payola/status_behavior.rb +1 -1
- data/app/controllers/payola/application_controller.rb +8 -0
- data/app/controllers/payola/cards_controller.rb +14 -14
- data/app/controllers/payola/customers_controller.rb +11 -12
- data/app/controllers/payola/subscriptions_controller.rb +16 -8
- data/app/controllers/payola/transactions_controller.rb +1 -1
- data/app/models/concerns/payola/plan.rb +2 -1
- data/app/models/payola/subscription.rb +5 -0
- data/app/services/payola/cancel_subscription.rb +6 -5
- data/app/services/payola/change_subscription_plan.rb +3 -1
- data/app/services/payola/change_subscription_quantity.rb +1 -1
- data/app/services/payola/create_sale.rb +12 -2
- data/app/services/payola/create_subscription.rb +1 -1
- data/app/services/payola/start_subscription.rb +9 -1
- data/app/services/payola/update_customer.rb +1 -1
- data/app/views/payola/subscriptions/_change_plan.html.erb +2 -0
- data/app/views/payola/subscriptions/_checkout.html.erb +1 -1
- data/app/views/payola/transactions/_checkout.html.erb +4 -2
- data/config/locales/en.yml +17 -0
- data/db/migrate/20151205004838_change_tax_percent_format_in_payola_subscriptions.rb +9 -0
- data/lib/payola.rb +6 -0
- data/lib/payola/version.rb +1 -1
- data/spec/concerns/plan_spec.rb +16 -4
- data/spec/controllers/payola/cards_controller_spec.rb +92 -8
- data/spec/controllers/payola/customers_controller_spec.rb +47 -4
- data/spec/controllers/payola/subscriptions_controller_spec.rb +59 -46
- data/spec/controllers/payola/transactions_controller_spec.rb +33 -30
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/javascripts/application.js +3 -3
- data/spec/dummy/app/assets/stylesheets/application.css +4 -4
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +27 -11
- data/spec/dummy/bin/rails +1 -1
- data/spec/dummy/config.ru +2 -1
- data/spec/dummy/config/application.rb +1 -2
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +1 -37
- data/spec/dummy/config/environments/production.rb +1 -82
- data/spec/dummy/config/environments/rails_4/development.rb +37 -0
- data/spec/dummy/config/environments/rails_4/production.rb +82 -0
- data/spec/dummy/config/environments/rails_4/test.rb +45 -0
- data/spec/dummy/config/environments/rails_5/development.rb +54 -0
- data/spec/dummy/config/environments/rails_5/production.rb +86 -0
- data/spec/dummy/config/environments/rails_5/test.rb +44 -0
- data/spec/dummy/config/environments/test.rb +1 -45
- data/spec/dummy/config/initializers/assets.rb +3 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -1
- data/spec/dummy/config/initializers/new_framework_defaults.rb +26 -0
- data/spec/dummy/config/secrets.yml +1 -1
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/db/schema.rb +9 -12
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +134732 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/models/payola/env_wrapper_spec.rb +13 -0
- data/spec/models/payola/sale_spec.rb +7 -7
- data/spec/models/payola/subscription_spec.rb +8 -3
- data/spec/payola_spec.rb +8 -8
- data/spec/services/payola/cancel_subscription_spec.rb +20 -4
- data/spec/services/payola/change_subscription_plan_spec.rb +2 -1
- data/spec/services/payola/change_subscription_quantity_spec.rb +23 -7
- data/spec/services/payola/charge_card_spec.rb +30 -25
- data/spec/services/payola/invoice_failed_spec.rb +1 -0
- data/spec/services/payola/invoice_paid_spec.rb +1 -0
- data/spec/services/payola/start_subscription_spec.rb +15 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/support/http_methods_with_keyword_args.rb +21 -0
- data/spec/support/params_helper.rb +9 -0
- data/spec/worker_spec.rb +2 -2
- metadata +41 -13
- data/config/database.yml.ci +0 -6
data/lib/payola.rb
CHANGED
@@ -139,6 +139,12 @@ module Payola
|
|
139
139
|
def ==(other)
|
140
140
|
to_s == other.to_s
|
141
141
|
end
|
142
|
+
|
143
|
+
# This is a nasty hack to counteract Stripe checking if the API key is_a String
|
144
|
+
# See https://github.com/peterkeen/payola/issues/256 for details
|
145
|
+
def is_a?(other)
|
146
|
+
ENV[@key].is_a?(other)
|
147
|
+
end
|
142
148
|
end
|
143
149
|
|
144
150
|
self.reset!
|
data/lib/payola/version.rb
CHANGED
data/spec/concerns/plan_spec.rb
CHANGED
@@ -28,12 +28,24 @@ module Payola
|
|
28
28
|
expect(subscription_plan.valid?).to be false
|
29
29
|
end
|
30
30
|
|
31
|
+
context "with an associated subscription" do
|
32
|
+
let :subscription do
|
33
|
+
create(:subscription, plan: create(:subscription_plan))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should fail when attempting to destroy it" do
|
37
|
+
expect {
|
38
|
+
subscription.plan.destroy
|
39
|
+
}.to raise_error(ActiveRecord::DeleteRestrictionError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
31
43
|
context "with Payola.create_stripe_plans set to true" do
|
32
44
|
before { Payola.create_stripe_plans = true }
|
33
45
|
|
34
46
|
it "should create the plan at stripe before the model is created" do
|
35
47
|
subscription_plan = build(:subscription_plan)
|
36
|
-
Payola::CreatePlan.
|
48
|
+
expect(Payola::CreatePlan).to receive(:call)
|
37
49
|
subscription_plan.save!
|
38
50
|
end
|
39
51
|
|
@@ -42,7 +54,7 @@ module Payola
|
|
42
54
|
subscription_plan.save!
|
43
55
|
subscription_plan.name = "new name"
|
44
56
|
|
45
|
-
Payola::CreatePlan.
|
57
|
+
expect(Payola::CreatePlan).to_not receive(:call)
|
46
58
|
subscription_plan.save!
|
47
59
|
end
|
48
60
|
end
|
@@ -53,7 +65,7 @@ module Payola
|
|
53
65
|
|
54
66
|
it "should not try to create the plan at stripe before the model is created" do
|
55
67
|
subscription_plan = build(:subscription_plan)
|
56
|
-
Payola::CreatePlan.
|
68
|
+
expect(Payola::CreatePlan).to_not receive(:call)
|
57
69
|
subscription_plan.save!
|
58
70
|
end
|
59
71
|
|
@@ -62,7 +74,7 @@ module Payola
|
|
62
74
|
subscription_plan.save!
|
63
75
|
subscription_plan.name = "new name"
|
64
76
|
|
65
|
-
Payola::CreatePlan.
|
77
|
+
expect(Payola::CreatePlan).to_not receive(:call)
|
66
78
|
subscription_plan.save!
|
67
79
|
end
|
68
80
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module Payola
|
4
4
|
describe CardsController do
|
5
5
|
routes { Payola::Engine.routes }
|
6
|
-
|
6
|
+
|
7
7
|
before do
|
8
8
|
Payola.secret_key = 'sk_test_12345'
|
9
9
|
request.env["HTTP_REFERER"] = "/my/cards"
|
@@ -20,17 +20,17 @@ module Payola
|
|
20
20
|
|
21
21
|
it "should pass args to CreateCard" do
|
22
22
|
expect(CreateCard).to receive(:call)
|
23
|
-
post :create, customer_id: customer.id, stripeToken: StripeMock.generate_card_token({})
|
23
|
+
post :create, params: { customer_id: customer.id, stripeToken: StripeMock.generate_card_token({}) }
|
24
24
|
|
25
25
|
expect(response.status).to eq 302
|
26
26
|
expect(response).to redirect_to "/my/cards"
|
27
|
-
expect(flash[:notice]).to eq "
|
27
|
+
expect(flash[:notice]).to eq "Successfully created new card"
|
28
28
|
expect(flash[:alert]).to_not be_present
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should fail when missing a token" do
|
32
32
|
expect(CreateCard).to_not receive(:call)
|
33
|
-
post :create, customer_id: customer.id, stripeToken: nil
|
33
|
+
post :create, params: { customer_id: customer.id, stripeToken: nil }
|
34
34
|
|
35
35
|
expect(response.status).to eq 302
|
36
36
|
expect(response).to redirect_to "/my/cards"
|
@@ -39,11 +39,44 @@ module Payola
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should return to the passed return path" do
|
42
|
-
post :create, customer_id: customer.id, stripeToken: StripeMock.generate_card_token({}), return_to: "/another/path"
|
42
|
+
post :create, params: { customer_id: customer.id, stripeToken: StripeMock.generate_card_token({}), return_to: "/another/path" }
|
43
43
|
|
44
44
|
expect(response.status).to eq 302
|
45
45
|
expect(response).to redirect_to "/another/path"
|
46
46
|
end
|
47
|
+
|
48
|
+
context "authorization" do
|
49
|
+
it "should permit authorized requests" do
|
50
|
+
allow(controller).to receive(:payola_can_modify_customer?).with(customer.id).and_return(true)
|
51
|
+
expect(controller).to receive(:create).and_call_original
|
52
|
+
|
53
|
+
post :create, params: { customer_id: customer.id, stripeToken: StripeMock.generate_card_token({}) }
|
54
|
+
|
55
|
+
expect(response).to redirect_to "/my/cards"
|
56
|
+
expect(flash[:alert]).to_not be_present
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should deny unauthorized requests" do
|
60
|
+
allow(controller).to receive(:payola_can_modify_customer?).with(customer.id).and_return(false)
|
61
|
+
expect(controller).to_not receive(:create)
|
62
|
+
|
63
|
+
post :create, params: { customer_id: customer.id, stripeToken: StripeMock.generate_card_token({}) }
|
64
|
+
|
65
|
+
expect(response).to redirect_to "/my/cards"
|
66
|
+
expect(flash[:alert]).to eq "You cannot modify this customer."
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should raise error when no referrer to redirect to" do
|
71
|
+
request.env.delete("HTTP_REFERER")
|
72
|
+
|
73
|
+
expect do
|
74
|
+
post :create, params: {
|
75
|
+
customer_id: customer.id,
|
76
|
+
stripeToken: StripeMock.generate_card_token({})
|
77
|
+
}
|
78
|
+
end.to raise_error(ActionController::RedirectBackError)
|
79
|
+
end
|
47
80
|
end
|
48
81
|
|
49
82
|
describe '#destroy' do
|
@@ -58,20 +91,71 @@ module Payola
|
|
58
91
|
|
59
92
|
it "should pass args to DestroyCard" do
|
60
93
|
expect(DestroyCard).to receive(:call)
|
61
|
-
delete :destroy, id: customer.sources.first.id, customer_id: customer.id
|
94
|
+
delete :destroy, params: { id: customer.sources.first.id, customer_id: customer.id }
|
62
95
|
|
63
96
|
expect(response.status).to eq 302
|
64
97
|
expect(response).to redirect_to "/my/cards"
|
65
|
-
expect(flash[:notice]).to eq "
|
98
|
+
expect(flash[:notice]).to eq "Successfully removed the card"
|
66
99
|
expect(flash[:alert]).to_not be_present
|
67
100
|
end
|
68
101
|
|
102
|
+
it "should not call DestroyCard when params blank" do
|
103
|
+
expect(DestroyCard).to_not receive(:call)
|
104
|
+
delete :destroy, params: { id: "", customer_id: "" }
|
105
|
+
|
106
|
+
expect(response.status).to eq 302
|
107
|
+
expect(response).to redirect_to "/my/cards"
|
108
|
+
expect(flash[:alert]).to eq "Could not remove the card"
|
109
|
+
expect(flash[:notice]).to_not be_present
|
110
|
+
end
|
111
|
+
|
69
112
|
it "should return to the passed return path" do
|
70
|
-
delete :destroy, id: customer.sources.first.id, customer_id: customer.id, return_to: "/another/path"
|
113
|
+
delete :destroy, params: { id: customer.sources.first.id, customer_id: customer.id, return_to: "/another/path" }
|
71
114
|
|
72
115
|
expect(response.status).to eq 302
|
73
116
|
expect(response).to redirect_to "/another/path"
|
74
117
|
end
|
118
|
+
|
119
|
+
context "authorization" do
|
120
|
+
it "should permit authorized requests" do
|
121
|
+
allow(controller).to receive(:payola_can_modify_customer?).with(customer.id).and_return(true)
|
122
|
+
expect(controller).to receive(:destroy).and_call_original
|
123
|
+
|
124
|
+
delete :destroy, params: { id: customer.sources.first.id, customer_id: customer.id }
|
125
|
+
|
126
|
+
expect(response).to redirect_to "/my/cards"
|
127
|
+
expect(flash[:alert]).to_not be_present
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should deny unauthorized requests" do
|
131
|
+
allow(controller).to receive(:payola_can_modify_customer?).with(customer.id).and_return(false)
|
132
|
+
expect(controller).to_not receive(:destroy)
|
133
|
+
|
134
|
+
delete :destroy, params: { id: customer.sources.first.id, customer_id: customer.id }
|
135
|
+
|
136
|
+
expect(response).to redirect_to "/my/cards"
|
137
|
+
expect(flash[:alert]).to eq "You cannot modify this customer."
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should throw error if controller doesn't define payola_can_modify_customer?" do
|
141
|
+
controller.instance_eval('undef :payola_can_modify_customer?')
|
142
|
+
|
143
|
+
expect {
|
144
|
+
delete :destroy, params: { id: customer.sources.first.id, customer_id: customer.id }
|
145
|
+
}.to raise_error(NotImplementedError)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should raise error when no referrer to redirect to" do
|
150
|
+
request.env.delete("HTTP_REFERER")
|
151
|
+
|
152
|
+
expect do
|
153
|
+
delete :destroy, params: {
|
154
|
+
id: customer.sources.first.id, customer_id: customer.id
|
155
|
+
}
|
156
|
+
end.to raise_error(ActionController::RedirectBackError)
|
157
|
+
end
|
158
|
+
|
75
159
|
end
|
76
160
|
|
77
161
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module Payola
|
4
4
|
describe CustomersController do
|
5
5
|
routes { Payola::Engine.routes }
|
6
|
-
|
6
|
+
|
7
7
|
before do
|
8
8
|
Payola.secret_key = 'sk_test_12345'
|
9
9
|
request.env["HTTP_REFERER"] = "/my/cards"
|
@@ -21,21 +21,64 @@ module Payola
|
|
21
21
|
|
22
22
|
it "should pass args to UpdateCustomer" do
|
23
23
|
expect(UpdateCustomer).to receive(:call)
|
24
|
-
post :update, id: customer.id, customer: { default_source: "1234" }
|
24
|
+
post :update, params: { id: customer.id, customer: { default_source: "1234" } }
|
25
25
|
|
26
26
|
expect(response.status).to eq 302
|
27
27
|
expect(response).to redirect_to "/my/cards"
|
28
|
-
expect(flash[:notice]).to eq "
|
28
|
+
expect(flash[:notice]).to eq "Successfully updated customer"
|
29
29
|
expect(flash[:alert]).to_not be_present
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should return to the passed return path" do
|
33
|
-
post :update, id: customer.id, customer: { default_source: "1234" }, return_to: "/another/path"
|
33
|
+
post :update, params: { id: customer.id, customer: { default_source: "1234" }, return_to: "/another/path" }
|
34
34
|
|
35
35
|
expect(response.status).to eq 302
|
36
36
|
expect(response).to redirect_to "/another/path"
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should not invoke UpdateCustomer if id param is not present" do
|
40
|
+
expect(UpdateCustomer).to_not receive(:call)
|
41
|
+
|
42
|
+
post :update, params: { id: "" }
|
43
|
+
|
44
|
+
expect(response.status).to eq 302
|
45
|
+
expect(response).to redirect_to "/my/cards"
|
46
|
+
expect(flash[:alert]).to eq "Could not update customer"
|
47
|
+
expect(flash[:notice]).to_not be_present
|
48
|
+
end
|
49
|
+
|
50
|
+
context "authorization" do
|
51
|
+
it "should permit authorized requests" do
|
52
|
+
allow(controller).to receive(:payola_can_modify_customer?).with(customer.id).and_return(true)
|
53
|
+
expect(controller).to receive(:update).and_call_original
|
54
|
+
|
55
|
+
post :update, params: { id: customer.id, customer: { default_source: "1234" } }
|
56
|
+
|
57
|
+
expect(response).to redirect_to "/my/cards"
|
58
|
+
expect(flash[:alert]).to_not be_present
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should deny unauthorized requests" do
|
62
|
+
allow(controller).to receive(:payola_can_modify_customer?).with(customer.id).and_return(false)
|
63
|
+
expect(controller).to_not receive(:update)
|
64
|
+
|
65
|
+
post :update, params: { id: customer.id, customer: { default_source: "1234" } }
|
66
|
+
|
67
|
+
expect(response).to redirect_to "/my/cards"
|
68
|
+
expect(flash[:alert]).to eq "You cannot modify this customer."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should raise error when no referrer to redirect to" do
|
73
|
+
request.env.delete("HTTP_REFERER")
|
74
|
+
|
75
|
+
expect do
|
76
|
+
post :update, params: {
|
77
|
+
id: customer.id, customer: { default_source: "1234" }
|
78
|
+
}
|
79
|
+
end.to raise_error(ActionController::RedirectBackError)
|
80
|
+
end
|
81
|
+
|
39
82
|
end
|
40
83
|
end
|
41
84
|
end
|
@@ -15,27 +15,29 @@ module Payola
|
|
15
15
|
|
16
16
|
it "should pass args to CreateSubscription" do
|
17
17
|
subscription = double
|
18
|
-
subscription.
|
19
|
-
subscription.
|
20
|
-
subscription.
|
18
|
+
expect(subscription).to receive(:save).and_return(true)
|
19
|
+
expect(subscription).to receive(:guid).at_least(1).times.and_return(1)
|
20
|
+
expect(subscription).to receive(:error).and_return(nil)
|
21
21
|
errors = double
|
22
|
-
errors.
|
23
|
-
subscription.
|
24
|
-
subscription.
|
25
|
-
|
26
|
-
CreateSubscription.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
expect(errors).to receive(:full_messages).and_return([])
|
23
|
+
expect(subscription).to receive(:errors).and_return(errors)
|
24
|
+
expect(subscription).to receive(:state).and_return('pending')
|
25
|
+
|
26
|
+
expect(CreateSubscription).to receive(:call).with(
|
27
|
+
permitted_params(
|
28
|
+
'plan_class' => 'subscription_plan',
|
29
|
+
'plan_id' => @plan.id.to_s,
|
30
|
+
'tax_percent' => tax_percent.to_s,
|
31
|
+
'controller' => 'payola/subscriptions',
|
32
|
+
'action' => 'create',
|
33
|
+
'plan' => @plan,
|
34
|
+
'coupon' => nil,
|
35
|
+
'quantity' => 1,
|
36
|
+
'affiliate' => nil
|
37
|
+
)
|
36
38
|
).and_return(subscription)
|
37
39
|
|
38
|
-
post :create, plan_class: @plan.plan_class, plan_id: @plan.id, tax_percent: tax_percent
|
40
|
+
post :create, params: { plan_class: @plan.plan_class, plan_id: @plan.id, tax_percent: tax_percent }
|
39
41
|
|
40
42
|
expect(response.status).to eq 200
|
41
43
|
parsed_body = JSON.load(response.body)
|
@@ -45,19 +47,19 @@ module Payola
|
|
45
47
|
describe "with an error" do
|
46
48
|
it "should return an error in json" do
|
47
49
|
subscription = double
|
48
|
-
subscription.
|
50
|
+
expect(subscription).to receive(:save).and_return(false)
|
49
51
|
error = double
|
50
|
-
error.
|
51
|
-
subscription.
|
52
|
-
subscription.
|
53
|
-
subscription.
|
54
|
-
subscription.
|
52
|
+
expect(error).to receive(:full_messages).and_return(['done did broke'])
|
53
|
+
expect(subscription).to receive(:errors).and_return(error)
|
54
|
+
expect(subscription).to receive(:state).and_return('errored')
|
55
|
+
expect(subscription).to receive(:error).and_return('')
|
56
|
+
expect(subscription).to receive(:guid).and_return('blah')
|
55
57
|
|
56
58
|
|
57
|
-
CreateSubscription.
|
58
|
-
Payola.
|
59
|
+
expect(CreateSubscription).to receive(:call).and_return(subscription)
|
60
|
+
expect(Payola).to_not receive(:queue!)
|
59
61
|
|
60
|
-
post :create, plan_class: @plan.plan_class, plan_id: @plan.id
|
62
|
+
post :create, params: { plan_class: @plan.plan_class, plan_id: @plan.id }
|
61
63
|
|
62
64
|
expect(response.status).to eq 400
|
63
65
|
parsed_body = JSON.load(response.body)
|
@@ -67,13 +69,14 @@ module Payola
|
|
67
69
|
end
|
68
70
|
|
69
71
|
describe '#status' do
|
70
|
-
it "should return 404 if it can't find the subscription" do
|
71
|
-
get :status, guid: 'doesnotexist'
|
72
|
+
it "should return 404 with no response body if it can't find the subscription" do
|
73
|
+
get :status, params: { guid: 'doesnotexist' }
|
72
74
|
expect(response.status).to eq 404
|
75
|
+
expect(response.body).to be_blank
|
73
76
|
end
|
74
77
|
it "should return json with properties" do
|
75
78
|
subscription = create(:subscription)
|
76
|
-
get :status, guid: subscription.guid
|
79
|
+
get :status, params: { guid: subscription.guid }
|
77
80
|
|
78
81
|
expect(response.status).to eq 200
|
79
82
|
|
@@ -89,7 +92,7 @@ module Payola
|
|
89
92
|
it "should redirect to the product's redirect path" do
|
90
93
|
plan = create(:subscription_plan)
|
91
94
|
subscription = create(:subscription, :plan => plan)
|
92
|
-
get :show, guid: subscription.guid
|
95
|
+
get :show, params: { guid: subscription.guid }
|
93
96
|
|
94
97
|
expect(response).to redirect_to '/'
|
95
98
|
end
|
@@ -100,8 +103,8 @@ module Payola
|
|
100
103
|
@subscription = create(:subscription, state: :active, stripe_customer_id: Stripe::Customer.create.id)
|
101
104
|
end
|
102
105
|
it "call Payola::CancelSubscription and redirect" do
|
103
|
-
Payola::CancelSubscription.
|
104
|
-
delete :destroy, guid: @subscription.guid
|
106
|
+
expect(Payola::CancelSubscription).to receive(:call)
|
107
|
+
delete :destroy, params: { guid: @subscription.guid }
|
105
108
|
# TODO : Figure out why this needs to be a hardcoded path.
|
106
109
|
# Why doesn't subscription_path(@subscription) work?
|
107
110
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
@@ -111,14 +114,14 @@ module Payola
|
|
111
114
|
expect(Payola::CancelSubscription).to_not receive(:call)
|
112
115
|
expect_any_instance_of(::ApplicationController).to receive(:payola_can_modify_subscription?).and_return(false)
|
113
116
|
|
114
|
-
delete :destroy, guid: @subscription.guid
|
117
|
+
delete :destroy, params: { guid: @subscription.guid }
|
115
118
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
116
119
|
expect(request.flash[:alert]).to eq 'You cannot modify this subscription.'
|
117
120
|
end
|
118
121
|
|
119
122
|
it "coerce the at_period_end param to a boolean, and pass it through to Payola::CancelSubscription" do
|
120
|
-
Payola::CancelSubscription.
|
121
|
-
delete :destroy, guid: @subscription.guid, at_period_end: 'true'
|
123
|
+
expect(Payola::CancelSubscription).to receive(:call).with(instance_of(Payola::Subscription), at_period_end: true)
|
124
|
+
delete :destroy, params: { guid: @subscription.guid, at_period_end: 'true' }
|
122
125
|
end
|
123
126
|
end
|
124
127
|
|
@@ -126,12 +129,13 @@ module Payola
|
|
126
129
|
before :each do
|
127
130
|
@subscription = create(:subscription, state: :active, stripe_customer_id: Stripe::Customer.create.id)
|
128
131
|
@plan = create(:subscription_plan)
|
132
|
+
@quantity = 1
|
129
133
|
end
|
130
134
|
|
131
135
|
it "should call Payola::ChangeSubscriptionPlan and redirect" do
|
132
|
-
expect(Payola::ChangeSubscriptionPlan).to receive(:call).with(@subscription, @plan)
|
136
|
+
expect(Payola::ChangeSubscriptionPlan).to receive(:call).with(@subscription, @plan, @quantity)
|
133
137
|
|
134
|
-
post :change_plan, guid: @subscription.guid, plan_class: @plan.plan_class, plan_id: @plan.id
|
138
|
+
post :change_plan, params: { guid: @subscription.guid, plan_class: @plan.plan_class, plan_id: @plan.id }
|
135
139
|
|
136
140
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
137
141
|
expect(request.flash[:notice]).to eq 'Subscription plan updated'
|
@@ -140,7 +144,7 @@ module Payola
|
|
140
144
|
it "should show error if Payola::ChangeSubscriptionPlan fails" do
|
141
145
|
StripeMock.prepare_error(Stripe::StripeError.new('There was a problem changing the subscription'))
|
142
146
|
|
143
|
-
post :change_plan, guid: @subscription.guid, plan_class: @plan.plan_class, plan_id: @plan.id
|
147
|
+
post :change_plan, params: { guid: @subscription.guid, plan_class: @plan.plan_class, plan_id: @plan.id }
|
144
148
|
|
145
149
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
146
150
|
expect(request.flash[:alert]).to eq 'There was a problem changing the subscription'
|
@@ -150,7 +154,7 @@ module Payola
|
|
150
154
|
expect(Payola::ChangeSubscriptionPlan).to_not receive(:call)
|
151
155
|
expect_any_instance_of(::ApplicationController).to receive(:payola_can_modify_subscription?).and_return(false)
|
152
156
|
|
153
|
-
post :change_plan, guid: @subscription.guid, plan_class: @plan.plan_class, plan_id: @plan.id
|
157
|
+
post :change_plan, params: { guid: @subscription.guid, plan_class: @plan.plan_class, plan_id: @plan.id }
|
154
158
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
155
159
|
expect(request.flash[:alert]).to eq 'You cannot modify this subscription.'
|
156
160
|
end
|
@@ -165,7 +169,7 @@ module Payola
|
|
165
169
|
it "should call Payola::ChangeSubscriptionQuantity and redirect" do
|
166
170
|
expect(Payola::ChangeSubscriptionQuantity).to receive(:call).with(@subscription, 5)
|
167
171
|
|
168
|
-
post :change_quantity, guid: @subscription.guid, quantity: 5
|
172
|
+
post :change_quantity, params: { guid: @subscription.guid, quantity: 5 }
|
169
173
|
|
170
174
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
171
175
|
expect(request.flash[:notice]).to eq 'Subscription quantity updated'
|
@@ -174,7 +178,7 @@ module Payola
|
|
174
178
|
it "should show error if Payola::ChangeSubscriptionQuantity fails" do
|
175
179
|
StripeMock.prepare_error(Stripe::StripeError.new('There was a problem changing the subscription quantity'))
|
176
180
|
|
177
|
-
post :change_quantity, guid: @subscription.guid, quantity: 5
|
181
|
+
post :change_quantity, params: { guid: @subscription.guid, quantity: 5 }
|
178
182
|
|
179
183
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
180
184
|
expect(request.flash[:alert]).to eq 'There was a problem changing the subscription quantity'
|
@@ -184,7 +188,7 @@ module Payola
|
|
184
188
|
expect(Payola::ChangeSubscriptionQuantity).to_not receive(:call)
|
185
189
|
expect_any_instance_of(::ApplicationController).to receive(:payola_can_modify_subscription?).and_return(false)
|
186
190
|
|
187
|
-
post :change_quantity, guid: @subscription.guid, quantity: 5
|
191
|
+
post :change_quantity, params: { guid: @subscription.guid, quantity: 5 }
|
188
192
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
189
193
|
expect(request.flash[:alert]).to eq 'You cannot modify this subscription.'
|
190
194
|
end
|
@@ -199,7 +203,7 @@ module Payola
|
|
199
203
|
it "should call UpdateCard and redirect" do
|
200
204
|
expect(Payola::UpdateCard).to receive(:call).with(@subscription, 'tok_1234')
|
201
205
|
|
202
|
-
post :update_card, guid: @subscription.guid, stripeToken: 'tok_1234'
|
206
|
+
post :update_card, params: { guid: @subscription.guid, stripeToken: 'tok_1234' }
|
203
207
|
|
204
208
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
205
209
|
expect(request.flash[:notice]).to eq 'Card updated'
|
@@ -208,7 +212,7 @@ module Payola
|
|
208
212
|
it "should show error if Payola::UpdateCare fails" do
|
209
213
|
StripeMock.prepare_error(Stripe::StripeError.new('There was a problem updating the card'))
|
210
214
|
|
211
|
-
post :update_card, guid: @subscription.guid, stripeToken: 'tok_1234'
|
215
|
+
post :update_card, params: { guid: @subscription.guid, stripeToken: 'tok_1234' }
|
212
216
|
|
213
217
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
214
218
|
expect(request.flash[:alert]).to eq 'There was a problem updating the card'
|
@@ -218,11 +222,20 @@ module Payola
|
|
218
222
|
expect(Payola::UpdateCard).to receive(:call).never
|
219
223
|
expect_any_instance_of(::ApplicationController).to receive(:payola_can_modify_subscription?).and_return(false)
|
220
224
|
|
221
|
-
post :update_card, guid: @subscription.guid, stripeToken: 'tok_1234'
|
225
|
+
post :update_card, params: { guid: @subscription.guid, stripeToken: 'tok_1234' }
|
222
226
|
|
223
227
|
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
|
224
228
|
expect(request.flash[:alert]).to eq 'You cannot modify this subscription.'
|
225
229
|
end
|
230
|
+
|
231
|
+
it "should throw error if controller doesn't define payola_can_modify_subscription?" do
|
232
|
+
expect(Payola::UpdateCard).to receive(:call).never
|
233
|
+
controller.instance_eval('undef :payola_can_modify_subscription?')
|
234
|
+
|
235
|
+
expect {
|
236
|
+
post :update_card, params: { guid: @subscription.guid, stripeToken: 'tok_1234' }
|
237
|
+
}.to raise_error(NotImplementedError)
|
238
|
+
end
|
226
239
|
end
|
227
240
|
|
228
241
|
end
|