diff --git a/lib/auxiliary_rails/concerns/performable.rb b/lib/auxiliary_rails/concerns/performable.rb index 81f0683..1a01548 100644 --- a/lib/auxiliary_rails/concerns/performable.rb +++ b/lib/auxiliary_rails/concerns/performable.rb @@ -94,7 +94,7 @@ def ensure_execution! def failure!(message = nil, options = {}) ensure_empty_status! - errors.add(:base, message, options) if message.present? + errors.add(:base, message, **options) if message.present? self.performable_status = :failure self diff --git a/spec/sample_commands_spec.rb b/spec/sample_commands_spec.rb index dadc81d..e85525c 100644 --- a/spec/sample_commands_spec.rb +++ b/spec/sample_commands_spec.rb @@ -72,4 +72,16 @@ end end end + + describe 'FailureMessageErrorsCommand' do + subject(:cmd) { SampleCommands::FailureMessageErrorsCommand.new } + + describe '#call' do + it do + expect(cmd.call).to be_failure + expect(cmd.errors.first.options).to eq foo: :bar + expect(cmd.errors.full_messages.join(', ')).to eq 'Custom failure message!' + end + end + end end diff --git a/spec/support/sample_classes/sample_commands.rb b/spec/support/sample_classes/sample_commands.rb index 3281c5e..214aae5 100644 --- a/spec/support/sample_classes/sample_commands.rb +++ b/spec/support/sample_classes/sample_commands.rb @@ -32,4 +32,10 @@ def perform success! end end + + class FailureMessageErrorsCommand < AuxiliaryRails::Application::Command + def perform + failure!('Custom failure message!', { foo: :bar }) + end + end end