<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,5 @@
+* Support enter and exit actions on states
+
 * Use named_scope in AR persistence layer, if available [Jan De Poorter]
 
 * Incremented version number</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
 Before Next Release:
 
-* Add state actions (enter, exit, after)
 * Add #aasm_next_state_for_event
 * Add #aasm_next_states_for_event
 </diff>
      <filename>TODO</filename>
    </modified>
    <modified>
      <diff>@@ -96,9 +96,18 @@ module AASM
     @aasm_current_state = state
   end
 
+  def aasm_state_object_for_state(name)
+    self.class.aasm_states.find {|s| s == name}
+  end
+
   def aasm_fire_event(name, persist)
+    aasm_state_object_for_state(aasm_current_state).call_action(:exit, self)
+
     new_state = self.class.aasm_events[name].fire(self)
+    
     unless new_state.nil?
+      aasm_state_object_for_state(new_state).call_action(:enter, self)
+      
       if self.respond_to?(:aasm_event_fired)
         self.aasm_event_fired(self.aasm_current_state, new_state)
       end</diff>
      <filename>lib/aasm.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,8 +3,8 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
 class Foo
   include AASM
   aasm_initial_state :open
-  aasm_state :open
-  aasm_state :closed
+  aasm_state :open, :exit =&gt; :exit
+  aasm_state :closed, :enter =&gt; :enter
 
   aasm_event :close, :success =&gt; :success_callback do
     transitions :to =&gt; :closed, :from =&gt; [:open]
@@ -20,6 +20,11 @@ class Foo
 
   def success_callback
   end
+
+  def enter
+  end
+  def exit
+  end
 end
 
 class Bar
@@ -231,4 +236,18 @@ describe AASM, '- event callbacks' do
   end
 end
 
+describe AASM, '- state actions' do
+  it &quot;should call enter when entering state&quot; do
+    foo = Foo.new
+    foo.should_receive(:enter)
+
+    foo.close
+  end
+
+  it &quot;should call exit when exiting state&quot; do
+    foo = Foo.new
+    foo.should_receive(:exit)
 
+    foo.close
+  end
+end</diff>
      <filename>spec/unit/aasm_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2bb30ee84bfd17972872fb567759323639147142</id>
    </parent>
  </parents>
  <author>
    <name>Scott Barron</name>
    <email>scott@elitists.net</email>
  </author>
  <url>http://github.com/al2o3cr/aasm/commit/3ccbeaca883f7eadf5e80622bf6a48b2c678e280</url>
  <id>3ccbeaca883f7eadf5e80622bf6a48b2c678e280</id>
  <committed-date>2008-05-31T15:08:12-07:00</committed-date>
  <authored-date>2008-05-31T15:08:12-07:00</authored-date>
  <message>Support enter and exit actions on states</message>
  <tree>6adb2c2b40a4a945ee7c50c0ae411c339fc94a70</tree>
  <committer>
    <name>Scott Barron</name>
    <email>scott@elitists.net</email>
  </committer>
</commit>
