Module: Trailblazer::Test::Operation::Helper
- Defined in:
- lib/trailblazer/test/operation/helper.rb
Defined Under Namespace
Classes: OperationFailedError
Instance Method Summary
collapse
Instance Method Details
#call(operation_class, **args, &block) ⇒ Object
3
4
5
|
# File 'lib/trailblazer/test/operation/helper.rb', line 3
def call(operation_class, **args, &block)
call!(operation_class, args, &block)
end
|
#call!(operation_class, raise_on_failure: false, **args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/trailblazer/test/operation/helper.rb', line 12
def call!(operation_class, raise_on_failure: false, **args)
operation_class.trace(**args).tap do |result|
unless result.success?
msg = "factory(#{operation_class}) has failed"
unless result["contract.default"].nil? if result["contract.default"].errors.messages.any?
msg += " due to validation errors: #{result["contract.default"].errors.messages}"
end
end
if raise_on_failure
result.wtf?
raise OperationFailedError, msg
end
end
yield result if block_given?
result
end
end
|
#factory(operation_class, **args, &block) ⇒ Object
7
8
9
|
# File 'lib/trailblazer/test/operation/helper.rb', line 7
def factory(operation_class, **args, &block)
call!(operation_class, args.merge(raise_on_failure: true), &block)
end
|