From 7a59852f537d028c2a249adba2e374cd65af7e1e Mon Sep 17 00:00:00 2001 From: Zino Date: Fri, 2 Feb 2018 23:05:06 -0600 Subject: [PATCH] Always return false when error callback is invoked --- lib/aasm/aasm.rb | 1 + spec/unit/callbacks_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/aasm/aasm.rb b/lib/aasm/aasm.rb index 63fc216..b0e07ca 100644 --- a/lib/aasm/aasm.rb +++ b/lib/aasm/aasm.rb @@ -130,6 +130,7 @@ private event.fire_callbacks(:error, self, e, *process_args(event, aasm(state_machine_name).current_state, *args)) || event.fire_global_callbacks(:error_on_all_events, self, e, *process_args(event, aasm(state_machine_name).current_state, *args)) || raise(e) + false ensure event.fire_callbacks(:ensure, self, *process_args(event, aasm(state_machine_name).current_state, *args)) event.fire_global_callbacks(:ensure_on_all_events, self, *process_args(event, aasm(state_machine_name).current_state, *args)) diff --git a/spec/unit/callbacks_spec.rb b/spec/unit/callbacks_spec.rb index 86e0aee..62086c5 100644 --- a/spec/unit/callbacks_spec.rb +++ b/spec/unit/callbacks_spec.rb @@ -3,14 +3,14 @@ Dir[File.dirname(__FILE__) + "/../models/callbacks/*.rb"].sort.each { |f| requir shared_examples 'an implemented callback that accepts error' do context 'with callback defined' do - it "should run error_callback if an exception is raised" do + it "should run error_callback if an exception is raised and always return false" do aasm_model.class.send(:define_method, callback_name) do |e| @data = [e] end allow(aasm_model).to receive(:before_enter).and_raise(e = StandardError.new) - aasm_model.safe_close! + expect(aasm_model.safe_close!).to be false expect(aasm_model.data).to eql [e] end