Permalink
Browse files

Fix event attributes not being processed when saved via association a…

…utosaving. Closes #157
  • Loading branch information...
1 parent 5660706 commit 79b697644e17280715cc4d4d61ae7669e111e6da @obrie obrie committed Mar 19, 2013
View
@@ -55,6 +55,14 @@ if RUBY_VERSION < "1.9.1"
end
end
+if RUBY_VERSION < "1.9.2"
+ appraise "active_record-2.3.5" do
+ gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
+ gem "activerecord", "2.3.5"
+ gem "activerecord-jdbcsqlite3-adapter", "1.2.7", :platform => :jruby
+ end
+end
+
if RUBY_VERSION < "2.0.0"
appraise "active_record-2.3.12" do
gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
View
@@ -1,5 +1,6 @@
# master
+* Fix event attributes not being processed when saved via association autosaving
* Fix Mongoid integration not setting initial state attributes properly for associations
* Completely rewrite ORM action hooks to behave more consistently across the board
* Change transitions to be executed the same whether using ORM save actions or not
@@ -0,0 +1,9 @@
+# This file was generated by Appraisal
+
+source "http://www.rubygems.org"
+
+gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
+gem "activerecord", "2.3.5"
+gem "activerecord-jdbcsqlite3-adapter", "1.2.7", :platform=>:jruby
+
+gemspec :path=>"../"
@@ -0,0 +1,39 @@
+PATH
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
+ specs:
+ state_machine (1.1.2)
+
+GEM
+ remote: http://www.rubygems.org/
+ specs:
+ activerecord (2.3.5)
+ activesupport (= 2.3.5)
+ activerecord-jdbc-adapter (1.2.8)
+ activerecord-jdbcsqlite3-adapter (1.2.7)
+ activerecord-jdbc-adapter (~> 1.2.7)
+ jdbc-sqlite3 (~> 3.7.2)
+ activesupport (2.3.5)
+ appraisal (0.4.1)
+ bundler
+ rake
+ jdbc-sqlite3 (3.7.2.1)
+ multi_json (1.6.1)
+ rake (10.0.3)
+ simplecov (0.7.1)
+ multi_json (~> 1.0)
+ simplecov-html (~> 0.7.1)
+ simplecov-html (0.7.1)
+ sqlite3-ruby (1.3.1)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ activerecord (= 2.3.5)
+ activerecord-jdbcsqlite3-adapter (= 1.2.7)
+ appraisal (~> 0.4.0)
+ rake
+ simplecov
+ sqlite3-ruby (= 1.3.1)
+ state_machine!
@@ -486,6 +486,10 @@ def save(*)
def save!(*)
self.class.state_machine(#{name.inspect}).send(:around_save, self) { super } || raise(ActiveRecord::RecordInvalid.new(self))
end
+
+ def changed_for_autosave?
+ super || self.class.state_machines.any? {|name, machine| machine.action == :save && machine.read(self, :event)}
+ end
end_eval
else
super
@@ -1711,6 +1711,55 @@ def test_should_return_nil_on_manual_rollback
end
end
+ if ActiveRecord::VERSION::MAJOR >= 3 || ActiveRecord::VERSION::MINOR >= 3
+ class MachineWithEventAttributesOnAutosaveTest < BaseTestCase
+ def setup
+ @vehicle_model = new_model(:vehicle) do
+ connection.add_column table_name, :owner_id, :integer
+ end
+ ActiveRecordTest.const_set('Vehicle', @vehicle_model)
+
+ @owner_model = new_model(:owner)
+ ActiveRecordTest.const_set('Owner', @owner_model)
+
+ machine = StateMachine::Machine.new(@vehicle_model)
+ machine.event :ignite do
+ transition :parked => :idling
+ end
+
+ @owner = @owner_model.create
+ @vehicle = @vehicle_model.create(:state => 'parked', :owner_id => @owner.id)
+ end
+
+ def test_should_persist_has_one_autosave
+ @owner_model.has_one :vehicle, :class_name => 'ActiveRecordTest::Vehicle', :autosave => true
+ @owner.vehicle.state_event = 'ignite'
+ @owner.save
+
+ @vehicle.reload
+ assert_equal 'idling', @vehicle.state
+ end
+
+ def test_should_persist_has_many_autosave
+ @owner_model.has_many :vehicles, :class_name => 'ActiveRecordTest::Vehicle', :autosave => true
+ @owner.vehicles[0].state_event = 'ignite'
+ @owner.save
+
+ @vehicle.reload
+ assert_equal 'idling', @vehicle.state
+ end
+
+ def teardown
+ ActiveRecordTest.class_eval do
+ remove_const('Vehicle')
+ remove_const('Owner')
+ end
+ ActiveSupport::Dependencies.clear if defined?(ActiveSupport::Dependencies)
+ super
+ end
+ end
+ end
+
class MachineWithEventAttributesOnSaveBangTest < BaseTestCase
def setup
@model = new_model

0 comments on commit 79b6976

Please sign in to comment.