mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
afdb1ac0a0
With the current implementation, a service step can be written as: ```ruby def my_step(a_default_value: 2) … end ``` That’s a pattern we want to avoid as default values (if needed) should be probably defined in a contract. This patch makes a service raise an exception if a default value is encountered.
62 lines
1.5 KiB
Ruby
62 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Service do
|
|
let(:service_class) { Class.new { include Service::Base } }
|
|
|
|
describe "Steps" do
|
|
describe "Model step" do
|
|
context "when providing default values to step implementation" do
|
|
before do
|
|
service_class.class_eval do
|
|
model :my_model
|
|
|
|
def fetch_my_model(default_arg: 2)
|
|
true
|
|
end
|
|
end
|
|
end
|
|
|
|
it "raises an error" do
|
|
expect { service_class.call }.to raise_error(/In model 'my_model': default values/)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "Policy step" do
|
|
context "when providing default values to step implementation" do
|
|
before do
|
|
service_class.class_eval do
|
|
policy :my_policy
|
|
|
|
def my_policy(default_arg: 2)
|
|
true
|
|
end
|
|
end
|
|
end
|
|
|
|
it "raises an error" do
|
|
expect { service_class.call }.to raise_error(/In policy 'my_policy': default values/)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "Generic step" do
|
|
context "when providing default values to step implementation" do
|
|
before do
|
|
service_class.class_eval do
|
|
step :generic_step
|
|
|
|
def generic_step(default_arg: 2)
|
|
true
|
|
end
|
|
end
|
|
end
|
|
|
|
it "raises an error" do
|
|
expect { service_class.call }.to raise_error(/In step 'generic_step': default values/)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|