mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
DEV: Show parameters on a service contract failure
Now, when calling `StepsInspector#error` on a contract failure, the output will contain the parameters provided to the contract.
This commit is contained in:
parent
47540fb4e0
commit
c790c57415
@ -177,7 +177,7 @@ module Service
|
||||
context[contract_name] = contract
|
||||
context[result_key] = Context.build
|
||||
if contract.invalid?
|
||||
context[result_key].fail(errors: contract.errors)
|
||||
context[result_key].fail(errors: contract.errors, parameters: contract.raw_attributes)
|
||||
context.fail!
|
||||
end
|
||||
end
|
||||
@ -218,6 +218,10 @@ module Service
|
||||
include ActiveModel::Attributes
|
||||
include ActiveModel::AttributeMethods
|
||||
include ActiveModel::Validations::Callbacks
|
||||
|
||||
def raw_attributes
|
||||
@attributes.values_before_type_cast
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,7 +73,7 @@ class StepsInspector
|
||||
# @!visibility private
|
||||
class Contract < Step
|
||||
def error
|
||||
step_result.errors.inspect
|
||||
"#{step_result.errors.inspect}\n\nProvided parameters: #{step_result.parameters.pretty_inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -219,6 +219,10 @@ RSpec.describe StepsInspector do
|
||||
it "returns an error related to the contract" do
|
||||
expect(error).to match(/ActiveModel::Error attribute=parameter, type=blank, options={}/)
|
||||
end
|
||||
|
||||
it "returns the provided paramaters" do
|
||||
expect(error).to match(/{"parameter"=>nil}/)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the policy step is failing" do
|
||||
|
Loading…
Reference in New Issue
Block a user