<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -5,4 +5,23 @@ class Vote &lt; ActiveRecord::Base
   validates_presence_of :user_id
   validates_presence_of :pain_point_id
   validates_uniqueness_of :user_id, :scope =&gt; [:pain_point_id]
+
+  acts_as_state_machine :initial =&gt; :neutral
+  state :neutral
+  state :up
+  state :down
+
+  event :up_vote do
+    transitions :from =&gt; :neutral, :to =&gt; :up
+    transitions :from =&gt; :down, :to =&gt; :up
+    transitions :from =&gt; :up, :to =&gt; :neutral
+  end
+  alias_method :up_vote, :up_vote!
+
+  event :down_vote do
+    transitions :from =&gt; :neutral, :to =&gt; :down
+    transitions :from =&gt; :up, :to =&gt; :down
+    transitions :from =&gt; :down, :to =&gt; :neutral
+  end
+  alias_method :down_vote, :down_vote!
 end</diff>
      <filename>app/models/vote.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@ class CreateVotes &lt; ActiveRecord::Migration
     create_table :votes do |t|
       t.integer :user_id
       t.integer :pain_point_id
+      t.column :state, :string, :null =&gt; :no, :default =&gt; 'neutral'
       t.timestamps
     end
   end</diff>
      <filename>db/migrate/003_create_votes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -36,6 +36,7 @@ ActiveRecord::Schema.define(:version =&gt; 3) do
   create_table &quot;votes&quot;, :force =&gt; true do |t|
     t.integer  &quot;user_id&quot;
     t.integer  &quot;pain_point_id&quot;
+    t.string   &quot;state&quot;,         :default =&gt; &quot;neutral&quot;
     t.datetime &quot;created_at&quot;
     t.datetime &quot;updated_at&quot;
   end</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -32,4 +32,85 @@ describe Vote do
       end
     end
   end
+
+  describe &quot;State Transitions&quot; do
+    attr_reader :vote
+    before do
+      @vote = votes(:quentin_slow_tests)
+    end
+
+    describe &quot;#up_vote&quot; do
+      describe &quot;when in neutral state&quot; do
+        before do
+          vote.state.should == 'neutral'
+        end
+
+        it &quot;transitions to up state&quot; do
+          vote.up_vote
+          vote.state.should == 'up'
+        end
+      end
+
+      describe &quot;when in down state&quot; do
+        before do
+          vote.state = 'down'
+          vote.save!
+        end
+
+        it &quot;transitions to up state&quot; do
+          vote.up_vote
+          vote.state.should == 'up'
+        end
+      end
+
+      describe &quot;when in up state&quot; do
+        before do
+          vote.state = 'up'
+          vote.save!
+        end
+
+        it &quot;transitions to neutral state&quot; do
+          vote.up_vote
+          vote.state.should == 'neutral'
+        end
+      end
+    end
+
+    describe &quot;#down_vote&quot; do
+      describe &quot;when in neutral state&quot; do
+        before do
+          vote.state.should == 'neutral'
+        end
+
+        it &quot;transitions to down state&quot; do
+          vote.down_vote
+          vote.state.should == 'down'
+        end
+      end
+
+      describe &quot;when in down state&quot; do
+        before do
+          vote.state = 'down'
+          vote.save!
+        end
+
+        it &quot;transitions to neutral state&quot; do
+          vote.down_vote
+          vote.state.should == 'neutral'
+        end
+      end
+
+      describe &quot;when in up state&quot; do
+        before do
+          vote.state = 'up'
+          vote.save!
+        end
+
+        it &quot;transitions to down state&quot; do
+          vote.down_vote
+          vote.state.should == 'down'
+        end
+      end
+    end
+  end
 end</diff>
      <filename>spec/models/vote_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>298d61ec249fabef62906ebb8b88e36f19e0dbcb</id>
    </parent>
  </parents>
  <author>
    <name>Brian Takita</name>
    <email>brian.takita@gmail.com</email>
  </author>
  <url>http://github.com/btakita/pain-point/commit/33d3ab1b9b874120d0ec81de515a041403524d32</url>
  <id>33d3ab1b9b874120d0ec81de515a041403524d32</id>
  <committed-date>2008-04-20T23:54:14-07:00</committed-date>
  <authored-date>2008-04-20T23:54:14-07:00</authored-date>
  <message>Vote has a state machine with up, down, and neutral states. Vote also has the up_vote and down_vote state transitions available.</message>
  <tree>d5d07a704628071654ee6c87c0d333f5510b7852</tree>
  <committer>
    <name>Brian Takita</name>
    <email>brian.takita@gmail.com</email>
  </committer>
</commit>
