Skip to content

Commit 98dca6d

Browse files
authored
Merge pull request payolapayments#246 from peterkeen/bugfix/payola-can-methods-raise-245
[payolapayments#245] Raise error if methods not implemented
2 parents 9beb977 + f53a6d3 commit 98dca6d

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

app/controllers/payola/cards_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def check_modify_permissions
3131
return_to,
3232
alert: t('payola.cards.not_authorized')
3333
) and return unless self.payola_can_modify_customer?(params[:customer_id])
34+
else
35+
raise NotImplementedError.new("Please implement ApplicationController#payola_can_modify_customer?")
3436
end
3537
end
3638

app/controllers/payola/customers_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def check_modify_permissions
2727
return_to,
2828
alert: t('payola.customers.not_authorized')
2929
) and return unless self.payola_can_modify_customer?(params[:id])
30+
else
31+
raise NotImplementedError.new("Please implement ApplicationController#payola_can_modify_customer?")
3032
end
3133
end
3234

app/controllers/payola/subscriptions_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def check_modify_permissions
7878
confirm_subscription_path(subscription),
7979
alert: t('payola.subscriptions.not_authorized')
8080
) and return unless self.payola_can_modify_subscription?(subscription)
81+
else
82+
raise NotImplementedError.new("Please implement ApplicationController#payola_can_modify_subscription?")
8183
end
8284
end
8385

spec/controllers/payola/cards_controller_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ module Payola
136136
expect(response).to redirect_to "/my/cards"
137137
expect(flash[:alert]).to eq "You cannot modify this customer."
138138
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
139147
end
140148

141149
it "should raise error when no referrer to redirect to" do

spec/controllers/payola/subscriptions_controller_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ module Payola
227227
expect(response).to redirect_to "/subdir/payola/confirm_subscription/#{@subscription.guid}"
228228
expect(request.flash[:alert]).to eq 'You cannot modify this subscription.'
229229
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
230239
end
231240

232241
end

spec/dummy/app/controllers/application_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ class ApplicationController < ActionController::Base
66
def payola_can_modify_subscription?(subscription)
77
true
88
end
9+
10+
def payola_can_modify_customer?(customer)
11+
true
12+
end
913
end

0 commit comments

Comments
 (0)