From dbb8bc8310b9be709fd7468e37e669bcb83c84a6 Mon Sep 17 00:00:00 2001 From: Nathaniel Bibler Date: Fri, 19 Sep 2008 00:02:31 -0400 Subject: [PATCH] State :exit is now only called if a transition actually occurs. --- lib/aasm.rb | 3 +-- spec/unit/aasm_spec.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/aasm.rb b/lib/aasm.rb index c182d00..ff607f6 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -115,11 +115,10 @@ module AASM end def aasm_fire_event(name, persist, *args) - aasm_state_object_for_state(aasm_current_state).call_action(:exit, self) - new_state = self.class.aasm_events[name].fire(self, *args) unless new_state.nil? + aasm_state_object_for_state(aasm_current_state).call_action(:exit, self) aasm_state_object_for_state(new_state).call_action(:enter, self) if self.respond_to?(:aasm_event_fired) diff --git a/spec/unit/aasm_spec.rb b/spec/unit/aasm_spec.rb index 33e9d9b..beca996 100644 --- a/spec/unit/aasm_spec.rb +++ b/spec/unit/aasm_spec.rb @@ -13,7 +13,7 @@ class Foo aasm_event :null do transitions :to => :closed, :from => [:open], :guard => :always_false end - + def always_false false end @@ -258,6 +258,13 @@ describe AASM, '- state actions' do foo.close end + + it "should not call exit when all transitions fail" do + foo = Foo.new + foo.should_not_receive(:exit) + + foo.null + end end -- 1.5.5.1