Permalink
Browse files

Add tests validating association autosave behavior for mongomapper, m…

…ongoid, and sequel integrations
  • Loading branch information...
1 parent 79b6976 commit e7019e70366455a5cbc8a3c3c6fd7052f6beeca4 @obrie obrie committed Mar 19, 2013
View
@@ -312,28 +312,42 @@ if RUBY_VERSION > "1.9.2"
end
# Sequel integrations
-appraise "sequel-2.8.0" do
- gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
- gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
- gem "sequel", "2.8.0"
-end
+if RUBY_VERSION < "1.9.2"
+ appraise "sequel-2.8.0" do
+ gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
+ gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
+ gem "sequel", "2.8.0"
+ end
-appraise "sequel-2.11.0" do
- gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
- gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
- gem "sequel", "2.11.0"
-end
+ appraise "sequel-2.11.0" do
+ gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
+ gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
+ gem "sequel", "2.11.0"
+ end
-appraise "sequel-2.12.0" do
- gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
- gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
- gem "sequel", "2.12.0"
+ appraise "sequel-2.12.0" do
+ gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
+ gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
+ gem "sequel", "2.12.0"
+ end
+
+ appraise "sequel-3.0.0" do
+ gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
+ gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
+ gem "sequel", "3.0.0"
+ end
+
+ appraise "sequel-3.4.0" do
+ gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
+ gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
+ gem "sequel", "3.4.0"
+ end
end
-appraise "sequel-3.0.0" do
+appraise "sequel-3.10.0" do
gem "sqlite3-ruby", "1.3.1", :platform => [:ruby, :mswin, :mingw]
gem "jdbc-sqlite3", "3.7.2", :platform => :jruby
- gem "sequel", "3.0.0"
+ gem "sequel", "3.10.0"
end
appraise "sequel-3.13.0" do
@@ -455,16 +469,17 @@ appraise "data_mapper-1.0.2" do
gem "dm-sqlite-adapter", "1.0.2"
end
-appraise "data_mapper-1.1.0" do
- gem "dm-core", "1.1.0"
- gem "dm-migrations", "1.1.0"
- gem "dm-validations", "1.1.0"
- gem "dm-observer", "1.1.0"
- gem "dm-transactions", "1.1.0"
- gem "dm-sqlite-adapter", "1.1.0"
-end
if RUBY_VERSION > "1.8.6"
+ appraise "data_mapper-1.1.0" do
+ gem "dm-core", "1.1.0"
+ gem "dm-migrations", "1.1.0"
+ gem "dm-validations", "1.1.0"
+ gem "dm-observer", "1.1.0"
+ gem "dm-transactions", "1.1.0"
+ gem "dm-sqlite-adapter", "1.1.0"
+ end
+
appraise "data_mapper-1.2.0" do
gem "dm-core", "1.2.0"
gem "dm-migrations", "1.2.0"
@@ -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 "jdbc-sqlite3", "3.7.2", :platform=>:jruby
+gem "sequel", "3.10.0"
+
+gemspec :path=>"../"
@@ -0,0 +1,33 @@
+PATH
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
+ specs:
+ state_machine (1.1.2)
+
+GEM
+ remote: http://www.rubygems.org/
+ specs:
+ appraisal (0.4.1)
+ bundler
+ rake
+ jdbc-sqlite3 (3.7.2)
+ multi_json (1.6.1)
+ rake (10.0.3)
+ sequel (3.10.0)
+ 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
+ appraisal (~> 0.4.0)
+ jdbc-sqlite3 (= 3.7.2)
+ rake
+ sequel (= 3.10.0)
+ simplecov
+ sqlite3-ruby (= 1.3.1)
+ state_machine!
@@ -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 "jdbc-sqlite3", "3.7.2", :platform=>:jruby
+gem "sequel", "3.4.0"
+
+gemspec :path=>"../"
@@ -0,0 +1,33 @@
+PATH
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
+ specs:
+ state_machine (1.1.2)
+
+GEM
+ remote: http://www.rubygems.org/
+ specs:
+ appraisal (0.4.1)
+ bundler
+ rake
+ jdbc-sqlite3 (3.7.2)
+ multi_json (1.6.1)
+ rake (10.0.3)
+ sequel (3.4.0)
+ 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
+ appraisal (~> 0.4.0)
+ jdbc-sqlite3 (= 3.7.2)
+ rake
+ sequel (= 3.4.0)
+ simplecov
+ sqlite3-ruby (= 1.3.1)
+ state_machine!
@@ -1560,6 +1560,45 @@ def test_should_allow_additional_transitions_to_previous_state_in_after_transiti
end
end
+ if defined?(MongoMapper::Version) && MongoMapper::Version !~ /^0\.[5-8]\./
+ class MachineWithEventAttributesOnAutosaveTest < BaseTestCase
+ def setup
+ @vehicle_model = new_model(:vehicle) do
+ belongs_to :owner, :class_name => 'MongoMapperTest::Owner'
+ end
+ MongoMapperTest.const_set('Vehicle', @vehicle_model)
+
+ @owner_model = new_model(:owner)
+ MongoMapperTest.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_many_association
+ @owner_model.many :vehicles, :class_name => 'MongoMapperTest::Vehicle', :autosave => true
+ @owner.vehicles[0].state_event = 'ignite'
+ @owner.save
+
+ @vehicle.reload
+ assert_equal 'idling', @vehicle.state
+ end
+
+ def teardown
+ MongoMapperTest.class_eval do
+ remove_const('Vehicle')
+ remove_const('Owner')
+ end
+ super
+ end
+ end
+ end
+
class MachineWithEventAttributesOnSaveBangTest < BaseTestCase
def setup
@model = new_model
@@ -1625,6 +1625,57 @@ def test_should_allow_additional_transitions_to_previous_state_in_after_transiti
end
end
+ if Mongoid::VERSION >= '2.1.0'
+ class MachineWithEventAttributesOnAutosaveTest < BaseTestCase
+ def setup
+ @vehicle_model = new_model(:vehicle) do
+ belongs_to :owner, :class_name => 'MongoidTest::Owner'
+ end
+ MongoidTest.const_set('Vehicle', @vehicle_model)
+
+ @owner_model = new_model(:owner)
+ MongoidTest.const_set('Owner', @owner_model)
+
+ machine = StateMachine::Machine.new(@vehicle_model)
+ machine.event :ignite do
+ transition :parked => :idling
+ end
+
+ @owner = @owner_model.create
+ end
+
+ def test_should_persist_many_association
+ @owner_model.has_many :vehicles, :class_name => 'MongoidTest::Vehicle', :autosave => true
+ @vehicle = @vehicle_model.create(:state => 'parked', :owner_id => @owner.id)
+
+ @owner.vehicles[0].state_event = 'ignite'
+ @owner.save
+
+ @vehicle.reload
+ assert_equal 'idling', @vehicle.state
+ end
+
+ def test_should_persist_one_association
+ @owner_model.has_one :vehicle, :class_name => 'MongoidTest::Vehicle', :autosave => true
+ @vehicle = @vehicle_model.create(:state => 'parked', :owner_id => @owner.id)
+
+ @owner.vehicle.state_event = 'ignite'
+ @owner.save
+
+ @vehicle.reload
+ assert_equal 'idling', @vehicle.state
+ end
+
+ def teardown
+ MongoidTest.class_eval do
+ remove_const('Vehicle')
+ remove_const('Owner')
+ end
+ super
+ end
+ end
+ end
+
class MachineWithEventAttributesOnSaveBangTest < BaseTestCase
def setup
@model = new_model
@@ -1643,6 +1643,64 @@ def test_should_return_nil_on_manual_rollback
end
end
+ if defined?(Sequel::VERSION) && Gem::Version.new(Sequel::VERSION) >= Gem::Version.new('3.4.0')
+ class MachineWithEventAttributesOnAutosaveTest < BaseTestCase
+ def setup
+ @vehicle_model = new_model(:vehicle)
+ DB.alter_table(@vehicle_model.table_identifier) do
+ add_column :owner_id, :integer
+ end
+ @vehicle_model.class_eval { get_db_schema(true) }
+ SequelTest.const_set('Vehicle', @vehicle_model)
+
+ @owner_model = new_model(:owner) do
+ plugin :nested_attributes
+ end
+ SequelTest.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_many_association
+ @owner_model.one_to_many :vehicles, :class_name => 'SequelTest::Vehicle'
+ @owner_model.nested_attributes :vehicles
+
+ @owner.vehicles_attributes = [{:id => @vehicle.id, :state_event => 'ignite'}]
+ @owner.save
+
+ @vehicle.reload
+ assert_equal 'idling', @vehicle.state
+ end
+
+ if Gem::Version.new(Sequel::VERSION) >= Gem::Version.new('3.10.0')
+ def test_should_persist_one_association
+ @owner_model.one_to_one :vehicle, :class_name => 'SequelTest::Vehicle'
+ @owner_model.nested_attributes :vehicle
+
+ @owner.vehicle_attributes = {:id => @vehicle.id, :state_event => 'ignite'}
+ @owner.save
+
+ @vehicle.reload
+ assert_equal 'idling', @vehicle.state
+ end
+ end
+
+ def teardown
+ SequelTest.class_eval do
+ remove_const('Vehicle')
+ remove_const('Owner')
+ end
+ super
+ end
+ end
+ end
+
class MachineWithEventAttributesOnCustomActionTest < BaseTestCase
def setup
@superclass = new_model do

0 comments on commit e7019e7

Please sign in to comment.