mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 22:47:46 +08:00
DEV: Fix policy classes delegating their #call
method in services
There’s currently a bug when using a dedicated class as a policy in services: if that class delegates its `#call` method (to an underlying strategy object for example), then an error will be raised saying steps aren’t allowed to provide default parameters. This should not happen, and this patch fixes that issue.
This commit is contained in:

committed by
Loïc Guitaut

parent
9812407f76
commit
133a648d9b
@ -38,6 +38,36 @@ RSpec.describe Service do
|
||||
expect { service_class.call }.to raise_error(/In policy 'my_policy': default values/)
|
||||
end
|
||||
end
|
||||
|
||||
context "when providing a class which delegates its `#call` method" do
|
||||
before do
|
||||
service_class.class_eval do
|
||||
class MyPolicy < Service::PolicyBase
|
||||
class MyStrategy
|
||||
def call
|
||||
end
|
||||
|
||||
def reason
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :strategy
|
||||
|
||||
delegate :call, :reason, to: :strategy
|
||||
|
||||
def initialize(*)
|
||||
@strategy = MyStrategy.new
|
||||
end
|
||||
end
|
||||
|
||||
policy :my_policy, class_name: MyPolicy
|
||||
end
|
||||
end
|
||||
|
||||
it "does not raise an error" do
|
||||
expect { service_class.call }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Generic step" do
|
||||
|
Reference in New Issue
Block a user