tenacity 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/EXTEND.rdoc +9 -13
- data/Rakefile +6 -0
- data/history.txt +17 -0
- data/lib/tenacity.rb +13 -9
- data/lib/tenacity/associate_proxy.rb +56 -0
- data/lib/tenacity/associates_proxy.rb +5 -3
- data/lib/tenacity/association.rb +81 -9
- data/lib/tenacity/associations/belongs_to.rb +28 -16
- data/lib/tenacity/associations/has_many.rb +113 -53
- data/lib/tenacity/associations/has_one.rb +33 -14
- data/lib/tenacity/class_methods.rb +117 -9
- data/lib/tenacity/errors.rb +9 -0
- data/lib/tenacity/instance_methods.rb +40 -3
- data/lib/tenacity/orm_ext/activerecord.rb +114 -95
- data/lib/tenacity/orm_ext/couchrest.rb +132 -113
- data/lib/tenacity/orm_ext/datamapper.rb +138 -112
- data/lib/tenacity/orm_ext/helpers.rb +36 -0
- data/lib/tenacity/orm_ext/mongo_mapper.rb +102 -84
- data/lib/tenacity/orm_ext/mongoid.rb +106 -87
- data/lib/tenacity/orm_ext/sequel.rb +137 -110
- data/lib/tenacity/version.rb +1 -1
- data/tenacity.gemspec +2 -1
- data/test/association_features/belongs_to_test.rb +46 -1
- data/test/association_features/has_many_test.rb +187 -2
- data/test/association_features/has_one_test.rb +57 -2
- data/test/associations/belongs_to_test.rb +41 -7
- data/test/associations/has_many_test.rb +59 -10
- data/test/associations/has_one_test.rb +57 -2
- data/test/fixtures/active_record_car.rb +5 -4
- data/test/fixtures/active_record_climate_control_unit.rb +1 -0
- data/test/fixtures/active_record_engine.rb +1 -0
- data/test/fixtures/active_record_has_many_target.rb +7 -0
- data/test/fixtures/active_record_has_one_target.rb +7 -0
- data/test/fixtures/active_record_object.rb +19 -0
- data/test/fixtures/couch_rest_has_many_target.rb +7 -0
- data/test/fixtures/couch_rest_has_one_target.rb +7 -0
- data/test/fixtures/couch_rest_object.rb +14 -0
- data/test/fixtures/data_mapper_has_many_target.rb +23 -3
- data/test/fixtures/data_mapper_has_one_target.rb +23 -3
- data/test/fixtures/data_mapper_object.rb +14 -0
- data/test/fixtures/mongo_mapper_air_filter.rb +6 -0
- data/test/fixtures/mongo_mapper_alternator.rb +7 -0
- data/test/fixtures/mongo_mapper_autosave_false_has_many_target.rb +8 -0
- data/test/fixtures/mongo_mapper_autosave_false_has_one_target.rb +8 -0
- data/test/fixtures/mongo_mapper_autosave_true_has_many_target.rb +8 -0
- data/test/fixtures/mongo_mapper_autosave_true_has_one_target.rb +8 -0
- data/test/fixtures/mongo_mapper_circuit_board.rb +6 -0
- data/test/fixtures/mongo_mapper_dashboard.rb +5 -2
- data/test/fixtures/mongo_mapper_has_many_target.rb +7 -0
- data/test/fixtures/mongo_mapper_has_one_target.rb +7 -0
- data/test/fixtures/mongo_mapper_object.rb +14 -0
- data/test/fixtures/mongo_mapper_wheel.rb +2 -0
- data/test/fixtures/mongo_mapper_windows.rb +6 -0
- data/test/fixtures/mongoid_has_many_target.rb +7 -0
- data/test/fixtures/mongoid_has_one_target.rb +7 -0
- data/test/fixtures/mongoid_object.rb +14 -0
- data/test/fixtures/sequel_has_many_target.rb +7 -0
- data/test/fixtures/sequel_has_one_target.rb +7 -0
- data/test/fixtures/sequel_object.rb +14 -0
- data/test/helpers/active_record_test_helper.rb +87 -8
- data/test/helpers/couch_rest_test_helper.rb +7 -0
- data/test/helpers/data_mapper_test_helper.rb +41 -3
- data/test/helpers/sequel_test_helper.rb +65 -9
- data/test/orm_ext/activerecord_test.rb +1 -1
- data/test/orm_ext/datamapper_test.rb +33 -24
- data/test/orm_ext/mongo_mapper_test.rb +6 -6
- data/test/orm_ext/mongoid_test.rb +6 -6
- data/test/orm_ext/sequel_test.rb +1 -1
- data/test/test_helper.rb +18 -9
- metadata +119 -55
@@ -4,7 +4,7 @@ class HasOneTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
context "A class with a has_one association to another class" do
|
6
6
|
setup do
|
7
|
-
|
7
|
+
setup_all_fixtures
|
8
8
|
@climate_control_unit = ActiveRecordClimateControlUnit.create
|
9
9
|
@dashboard = MongoMapperDashboard.create(:active_record_climate_control_unit => @climate_control_unit)
|
10
10
|
end
|
@@ -15,7 +15,7 @@ class HasOneTest < Test::Unit::TestCase
|
|
15
15
|
other_climate_control_unit = ActiveRecordClimateControlUnit.create
|
16
16
|
assert_equal @climate_control_unit, MongoMapperDashboard.find(@dashboard.id).active_record_climate_control_unit
|
17
17
|
ActiveRecordClimateControlUnit.update(@climate_control_unit.id, :mongo_mapper_dashboard_id => nil)
|
18
|
-
ActiveRecordClimateControlUnit.update(other_climate_control_unit.id, :mongo_mapper_dashboard_id => @dashboard
|
18
|
+
ActiveRecordClimateControlUnit.update(other_climate_control_unit.id, :mongo_mapper_dashboard_id => serialize_id(@dashboard))
|
19
19
|
assert_equal other_climate_control_unit, MongoMapperDashboard.find(@dashboard.id).active_record_climate_control_unit
|
20
20
|
|
21
21
|
assert_equal @climate_control_unit, @dashboard.active_record_climate_control_unit
|
@@ -36,6 +36,61 @@ class HasOneTest < Test::Unit::TestCase
|
|
36
36
|
engine = ActiveRecordEngine.create(:active_record_car => car)
|
37
37
|
assert_equal engine, car.active_record_engine
|
38
38
|
end
|
39
|
+
|
40
|
+
should "not be able to modify the associated object if the readonly option is set" do
|
41
|
+
car = ActiveRecordCar.create
|
42
|
+
dashboard = MongoMapperDashboard.create(:active_record_car => car)
|
43
|
+
dashboard = car.mongo_mapper_dashboard
|
44
|
+
dashboard.prop = "value"
|
45
|
+
assert_raises(Tenacity::ReadOnlyError) { dashboard.save }
|
46
|
+
end
|
47
|
+
|
48
|
+
should "save the associated object if autosave is true" do
|
49
|
+
source = ActiveRecordObject.create
|
50
|
+
target = MongoMapperAutosaveTrueHasOneTarget.new(:prop => 'abc')
|
51
|
+
source.mongo_mapper_autosave_true_has_one_target = target
|
52
|
+
source.save
|
53
|
+
assert_equal 'abc', source.mongo_mapper_autosave_true_has_one_target.prop
|
54
|
+
|
55
|
+
source.mongo_mapper_autosave_true_has_one_target.prop = 'xyz'
|
56
|
+
source.save
|
57
|
+
source.reload && source.mongo_mapper_autosave_true_has_one_target(true)
|
58
|
+
assert_equal 'xyz', source.mongo_mapper_autosave_true_has_one_target.prop
|
59
|
+
end
|
60
|
+
|
61
|
+
should "not save the associated object upon assignment if autosave is false" do
|
62
|
+
source = ActiveRecordObject.create
|
63
|
+
target = MongoMapperAutosaveFalseHasOneTarget.new
|
64
|
+
source.mongo_mapper_autosave_false_has_one_target = target
|
65
|
+
|
66
|
+
source.save
|
67
|
+
assert_nil MongoMapperAutosaveFalseHasOneTarget.first(:active_record_object_id => source.id)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "destroy the associated object if autosave is true and object is marked for destruction" do
|
71
|
+
source = ActiveRecordObject.create
|
72
|
+
target = MongoMapperAutosaveTrueHasOneTarget.new
|
73
|
+
source.mongo_mapper_autosave_true_has_one_target = target
|
74
|
+
source.save
|
75
|
+
assert_not_nil source.mongo_mapper_autosave_true_has_one_target(true)
|
76
|
+
|
77
|
+
source.mongo_mapper_autosave_true_has_one_target.mark_for_destruction
|
78
|
+
assert source.mongo_mapper_autosave_true_has_one_target.marked_for_destruction?
|
79
|
+
source.save
|
80
|
+
source.reload
|
81
|
+
assert_nil source.mongo_mapper_autosave_true_has_one_target(true)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "be able to store an object via its polymorphic interface" do
|
85
|
+
circuit_board = MongoMapperCircuitBoard.create
|
86
|
+
alternator = MongoMapperAlternator.create
|
87
|
+
alternator.diagnosable = circuit_board
|
88
|
+
alternator.save
|
89
|
+
|
90
|
+
component = MongoMapperAlternator.find(alternator.id).diagnosable
|
91
|
+
assert_equal circuit_board, component
|
92
|
+
assert_equal 'MongoMapperAlternator', component.diagnosable_type
|
93
|
+
end
|
39
94
|
end
|
40
95
|
|
41
96
|
end
|
@@ -17,26 +17,60 @@ class BelongsToTest < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
should "be able to fetch the id of the associated object" do
|
20
|
-
@target.send("#{@foreign_key_id}=", @source
|
20
|
+
@target.send("#{@foreign_key_id}=", serialize_id(@source))
|
21
21
|
@target.save
|
22
|
-
assert_equal @source
|
22
|
+
assert_equal serialize_id(@source), @target_class._t_find(serialize_id(@target)).send(@foreign_key_id)
|
23
23
|
end
|
24
24
|
|
25
25
|
should "be able to load the associated object" do
|
26
26
|
@target.send("#{@foreign_key}=", @source)
|
27
27
|
@target.save
|
28
|
-
assert_equal @source
|
29
|
-
assert_equal @source, @target_class._t_find(@target
|
28
|
+
assert_equal serialize_id(@source), @target_class._t_find(serialize_id(@target)).send(@foreign_key_id)
|
29
|
+
assert_equal @source, @target_class._t_find(serialize_id(@target)).send(@foreign_key)
|
30
30
|
end
|
31
31
|
|
32
32
|
should "be be able to load the associated object if all we have is the id" do
|
33
|
-
@target.send("#{@foreign_key_id}=", @source
|
33
|
+
@target.send("#{@foreign_key_id}=", serialize_id(@source))
|
34
34
|
@target.save
|
35
|
-
assert_equal @source, @target_class._t_find(@target
|
35
|
+
assert_equal @source, @target_class._t_find(serialize_id(@target)).send(@foreign_key)
|
36
36
|
end
|
37
37
|
|
38
38
|
should "return nil if no association is set" do
|
39
|
-
assert_nil @target_class._t_find(@target
|
39
|
+
assert_nil @target_class._t_find(serialize_id(@target)).send(@foreign_key)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "be able to destroy the associated object when the source object is destroyed" do
|
43
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:destroy)
|
44
|
+
@target.send("#{@foreign_key}=", @source)
|
45
|
+
@target.save
|
46
|
+
@target_class._t_delete([serialize_id(@target)])
|
47
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
48
|
+
assert_nil @target_class._t_find(serialize_id(@target))
|
49
|
+
end
|
50
|
+
|
51
|
+
should "be able to delete the associated object when the source object is destroyed" do
|
52
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:delete)
|
53
|
+
@target.send("#{@foreign_key}=", @source)
|
54
|
+
@target.save
|
55
|
+
@target_class._t_delete([serialize_id(@target)])
|
56
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
57
|
+
assert_nil @target_class._t_find(serialize_id(@target))
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with a polymorphic association" do
|
61
|
+
setup do
|
62
|
+
@foreign_key = "#{source}_has_one_target_testable"
|
63
|
+
@polymorphic_type = "#{source}_has_one_target_testable_type"
|
64
|
+
end
|
65
|
+
|
66
|
+
should "be able to create a polymorphic association" do
|
67
|
+
@target.send("#{@foreign_key}=", @source)
|
68
|
+
@target.save
|
69
|
+
|
70
|
+
reloaded_source = @target_class._t_find(serialize_id(@target)).send(@foreign_key)
|
71
|
+
assert_equal @source, reloaded_source
|
72
|
+
assert_equal @source_class.to_s, @target.send(@polymorphic_type)
|
73
|
+
end
|
40
74
|
end
|
41
75
|
end
|
42
76
|
end
|
@@ -22,8 +22,8 @@ class HasManyTest < Test::Unit::TestCase
|
|
22
22
|
@source.send("#{@foreign_key_id}=", [@target_1.id, @target_2.id, @target_3.id])
|
23
23
|
@source.save
|
24
24
|
[@target_1, @target_2, @target_3].each { |t| t._t_reload }
|
25
|
-
assert_set_equal [@target_1, @target_2, @target_3], @source_class._t_find(@source
|
26
|
-
assert_set_equal [@target_1
|
25
|
+
assert_set_equal [@target_1, @target_2, @target_3], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
26
|
+
assert_set_equal [serialize_id(@target_1), serialize_id(@target_2), serialize_id(@target_3)], @source_class._t_find(serialize_id(@source)).send(@foreign_key_id)
|
27
27
|
end
|
28
28
|
|
29
29
|
context "that works with associated objects" do
|
@@ -34,7 +34,7 @@ class HasManyTest < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
should "be able to set the associated objects" do
|
36
36
|
[@target_1, @target_2, @target_3].each { |t| t._t_reload }
|
37
|
-
assert_set_equal [@target_1, @target_2, @target_3], @source_class._t_find(@source
|
37
|
+
assert_set_equal [@target_1, @target_2, @target_3], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
38
38
|
end
|
39
39
|
|
40
40
|
should "be able to add an associated object using the << operator" do
|
@@ -42,7 +42,7 @@ class HasManyTest < Test::Unit::TestCase
|
|
42
42
|
@source.send(@foreign_key) << target_4
|
43
43
|
@source.save
|
44
44
|
[@target_1, @target_2, @target_3, target_4].each { |t| t._t_reload }
|
45
|
-
assert_set_equal [@target_1, @target_2, @target_3, target_4], @source_class._t_find(@source
|
45
|
+
assert_set_equal [@target_1, @target_2, @target_3, target_4], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
46
46
|
end
|
47
47
|
|
48
48
|
should "be able to add an associated object using the push method" do
|
@@ -51,7 +51,7 @@ class HasManyTest < Test::Unit::TestCase
|
|
51
51
|
@source.send(@foreign_key).push(target_4, target_5)
|
52
52
|
@source.save
|
53
53
|
[@target_1, @target_2, @target_3, target_4, target_5].each { |t| t._t_reload }
|
54
|
-
assert_set_equal [@target_1, @target_2, @target_3, target_4, target_5], @source_class._t_find(@source
|
54
|
+
assert_set_equal [@target_1, @target_2, @target_3, target_4, target_5], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
55
55
|
end
|
56
56
|
|
57
57
|
should "be able to add an associated object using the concat method" do
|
@@ -60,25 +60,74 @@ class HasManyTest < Test::Unit::TestCase
|
|
60
60
|
@source.send(@foreign_key).concat([target_4, target_5])
|
61
61
|
@source.save
|
62
62
|
[@target_1, @target_2, @target_3, target_4, target_5].each { |t| t._t_reload }
|
63
|
-
assert_set_equal [@target_1, @target_2, @target_3, target_4, target_5], @source_class._t_find(@source
|
63
|
+
assert_set_equal [@target_1, @target_2, @target_3, target_4, target_5], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
64
64
|
end
|
65
65
|
|
66
66
|
should "be able to remove an associated object using the delete method" do
|
67
67
|
@source.send(@foreign_key).delete(@target_3)
|
68
68
|
@source.save
|
69
69
|
[@target_1, @target_2].each { |t| t._t_reload }
|
70
|
-
assert_set_equal [@target_1, @target_2], @source_class._t_find(@source
|
70
|
+
assert_set_equal [@target_1, @target_2], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
71
71
|
end
|
72
72
|
|
73
73
|
should "be able to clear all associated objects using the clear method" do
|
74
74
|
@source.send(@foreign_key).clear
|
75
75
|
@source.save
|
76
|
-
assert_set_equal [], @source_class._t_find(@source
|
76
|
+
assert_set_equal [], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
77
77
|
end
|
78
78
|
|
79
79
|
should "return an empty array if the association is not set" do
|
80
|
-
|
81
|
-
assert_set_equal [], @source_class._t_find(
|
80
|
+
s = @source_class.create({})
|
81
|
+
assert_set_equal [], @source_class._t_find(serialize_id(s)).send(@foreign_key)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "be able to destroy the associated object when an object is destroyed" do
|
85
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:destroy, nil)
|
86
|
+
@source.destroy
|
87
|
+
|
88
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
89
|
+
assert_nil @target_class._t_find(serialize_id(@target_1))
|
90
|
+
assert_nil @target_class._t_find(serialize_id(@target_2))
|
91
|
+
assert_nil @target_class._t_find(serialize_id(@target_3))
|
92
|
+
end
|
93
|
+
|
94
|
+
should "be able to delete the associated object when an object is destroyed" do
|
95
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:delete_all)
|
96
|
+
@source.destroy
|
97
|
+
|
98
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
99
|
+
assert_nil @target_class._t_find(serialize_id(@target_1))
|
100
|
+
assert_nil @target_class._t_find(serialize_id(@target_2))
|
101
|
+
assert_nil @target_class._t_find(serialize_id(@target_3))
|
102
|
+
end
|
103
|
+
|
104
|
+
should "be able to nullify the foreign key of the associated object when an object is destroyed" do
|
105
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:nullify)
|
106
|
+
@source.destroy
|
107
|
+
|
108
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
109
|
+
assert_not_nil @target_class._t_find(serialize_id(@target_1))
|
110
|
+
assert_not_nil @target_class._t_find(serialize_id(@target_2))
|
111
|
+
assert_not_nil @target_class._t_find(serialize_id(@target_3))
|
112
|
+
assert_nil @target_class._t_find(serialize_id(@target_1)).send(foreign_key_id_for(target, :belongs_to))
|
113
|
+
assert_nil @target_class._t_find(serialize_id(@target_2)).send(foreign_key_id_for(target, :belongs_to))
|
114
|
+
assert_nil @target_class._t_find(serialize_id(@target_3)).send(foreign_key_id_for(target, :belongs_to))
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "with polymorphic associations" do
|
119
|
+
setup do
|
120
|
+
@foreign_key = "#{target}_has_many_target_testable"
|
121
|
+
@polymorphic_type = "#{target}_has_many_target_testable_type"
|
122
|
+
end
|
123
|
+
|
124
|
+
should "be able to store an object via its polymorphic interface" do
|
125
|
+
@source.send("#{@foreign_key}=", [@target_1, @target_2, @target_3])
|
126
|
+
@source.save
|
127
|
+
|
128
|
+
[@target_1, @target_2, @target_3].each { |t| t._t_reload }
|
129
|
+
assert_set_equal [@target_1, @target_2, @target_3], @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
130
|
+
[@target_1, @target_2, @target_3].each { |t| assert_equal @source_class.to_s, t.send(@polymorphic_type) }
|
82
131
|
end
|
83
132
|
end
|
84
133
|
end
|
@@ -18,11 +18,66 @@ class HasOneTest < Test::Unit::TestCase
|
|
18
18
|
|
19
19
|
should "be able to set and get the associated object" do
|
20
20
|
@source.send("#{@foreign_key}=", @target)
|
21
|
-
assert_equal @target, @source_class._t_find(@source
|
21
|
+
assert_equal @target, @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
22
22
|
end
|
23
23
|
|
24
24
|
should "return nil if no association is set" do
|
25
|
-
assert_nil @source_class._t_find(@source
|
25
|
+
assert_nil @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "be able to invoke the post delete callback" do
|
29
|
+
@source.send("#{@foreign_key}=", @target)
|
30
|
+
@source_class._t_delete([serialize_id(@source)])
|
31
|
+
end
|
32
|
+
|
33
|
+
should "be able to destroy the associated object when an object is destroyed" do
|
34
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:destroy, nil)
|
35
|
+
|
36
|
+
@source.send("#{@foreign_key}=", @target)
|
37
|
+
assert_equal @target, @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
38
|
+
@source.destroy
|
39
|
+
|
40
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
41
|
+
assert_nil @target_class._t_find(serialize_id(@target))
|
42
|
+
end
|
43
|
+
|
44
|
+
should "be able to delete the associated object when an object is destroyed" do
|
45
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:delete)
|
46
|
+
|
47
|
+
@source.send("#{@foreign_key}=", @target)
|
48
|
+
assert_equal @target, @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
49
|
+
@source.destroy
|
50
|
+
|
51
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
52
|
+
assert_nil @target_class._t_find(serialize_id(@target))
|
53
|
+
end
|
54
|
+
|
55
|
+
should "be able to nullify the foreign key of the associated object when an object is destroyed" do
|
56
|
+
Tenacity::Association.any_instance.stubs(:dependent).returns(:nullify)
|
57
|
+
|
58
|
+
@source.send("#{@foreign_key}=", @target)
|
59
|
+
assert_equal @target, @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
60
|
+
@source.destroy
|
61
|
+
|
62
|
+
assert_nil @source_class._t_find(serialize_id(@source))
|
63
|
+
assert_not_nil @target_class._t_find(serialize_id(@target))
|
64
|
+
assert_nil @target_class._t_find(serialize_id(@target)).send(foreign_key_id_for(target, :belongs_to))
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with a polymorphic association" do
|
68
|
+
setup do
|
69
|
+
@foreign_key = "#{target}_has_one_target_testable"
|
70
|
+
@polymorphic_type = "#{target}_has_one_target_testable_type"
|
71
|
+
end
|
72
|
+
|
73
|
+
should "be able to store an object via its polymorphic interface" do
|
74
|
+
@source.send("#{@foreign_key}=", @target)
|
75
|
+
@source.save
|
76
|
+
|
77
|
+
reloaded_target = @source_class._t_find(serialize_id(@source)).send(@foreign_key)
|
78
|
+
assert_equal @target, reloaded_target
|
79
|
+
assert_equal @source_class.to_s, reloaded_target.send(@polymorphic_type)
|
80
|
+
end
|
26
81
|
end
|
27
82
|
end
|
28
83
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
class ActiveRecordCar < ActiveRecord::Base
|
2
2
|
include Tenacity
|
3
3
|
|
4
|
-
t_has_many :mongo_mapper_wheels
|
5
|
-
|
4
|
+
t_has_many :mongo_mapper_wheels, :dependent => :destroy, :readonly => true, :limit => 5
|
5
|
+
t_has_many :mongo_mapper_windows, :limit => 5, :offset => 3
|
6
|
+
t_has_one :mongo_mapper_dashboard, :dependent => :delete, :readonly => true
|
6
7
|
|
7
8
|
t_has_one :couch_rest_windshield, :foreign_key => :car_id
|
8
|
-
t_has_one :active_record_engine, :foreign_key => 'car_id'
|
9
|
-
t_has_many :couch_rest_doors, :foreign_key => 'automobile_id'
|
9
|
+
t_has_one :active_record_engine, :foreign_key => 'car_id', :dependent => :nullify
|
10
|
+
t_has_many :couch_rest_doors, :foreign_key => 'automobile_id', :dependent => :delete_all
|
10
11
|
end
|
@@ -7,4 +7,11 @@ class ActiveRecordHasManyTarget < ActiveRecord::Base
|
|
7
7
|
t_belongs_to :mongo_mapper_object
|
8
8
|
require_mongoid { t_belongs_to :mongoid_object }
|
9
9
|
t_belongs_to :sequel_object
|
10
|
+
|
11
|
+
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
|
12
|
+
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
|
13
|
+
t_belongs_to :data_mapper_has_many_target_testable, :polymorphic => true
|
14
|
+
t_belongs_to :mongo_mapper_has_many_target_testable, :polymorphic => true
|
15
|
+
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
|
16
|
+
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
|
10
17
|
end
|
@@ -7,4 +7,11 @@ class ActiveRecordHasOneTarget < ActiveRecord::Base
|
|
7
7
|
t_belongs_to :mongo_mapper_object
|
8
8
|
require_mongoid { t_belongs_to :mongoid_object }
|
9
9
|
t_belongs_to :sequel_object
|
10
|
+
|
11
|
+
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
|
12
|
+
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
|
13
|
+
t_belongs_to :data_mapper_has_one_target_testable, :polymorphic => true
|
14
|
+
t_belongs_to :mongo_mapper_has_one_target_testable, :polymorphic => true
|
15
|
+
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
|
16
|
+
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
|
10
17
|
end
|
@@ -8,10 +8,29 @@ class ActiveRecordObject < ActiveRecord::Base
|
|
8
8
|
require_mongoid { t_has_one :mongoid_has_one_target }
|
9
9
|
t_has_one :sequel_has_one_target
|
10
10
|
|
11
|
+
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
|
12
|
+
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
|
13
|
+
t_has_one :data_mapper_has_one_target, :as => :data_mapper_has_one_target_testable
|
14
|
+
t_has_one :mongo_mapper_has_one_target, :as => :mongo_mapper_has_one_target_testable
|
15
|
+
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
|
16
|
+
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
|
17
|
+
|
11
18
|
t_has_many :active_record_has_many_targets
|
12
19
|
t_has_many :couch_rest_has_many_targets
|
13
20
|
t_has_many :data_mapper_has_many_targets
|
14
21
|
t_has_many :mongo_mapper_has_many_targets
|
15
22
|
require_mongoid { t_has_many :mongoid_has_many_targets }
|
16
23
|
t_has_many :sequel_has_many_targets
|
24
|
+
|
25
|
+
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
|
26
|
+
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
|
27
|
+
t_has_many :data_mapper_has_many_targets, :as => :data_mapper_has_many_target_testable
|
28
|
+
t_has_many :mongo_mapper_has_many_targets, :as => :mongo_mapper_has_many_target_testable
|
29
|
+
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
|
30
|
+
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
|
31
|
+
|
32
|
+
t_has_one :mongo_mapper_autosave_true_has_one_target, :autosave => true
|
33
|
+
t_has_one :mongo_mapper_autosave_false_has_one_target, :autosave => false
|
34
|
+
t_has_many :mongo_mapper_autosave_true_has_many_targets, :autosave => true
|
35
|
+
t_has_many :mongo_mapper_autosave_false_has_many_targets, :autosave => false
|
17
36
|
end
|
@@ -8,5 +8,12 @@ class CouchRestHasManyTarget < CouchRest::Model::Base
|
|
8
8
|
t_belongs_to :mongo_mapper_object
|
9
9
|
require_mongoid { t_belongs_to :mongoid_object }
|
10
10
|
t_belongs_to :sequel_object
|
11
|
+
|
12
|
+
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
|
13
|
+
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
|
14
|
+
t_belongs_to :data_mapper_has_many_target_testable, :polymorphic => true
|
15
|
+
t_belongs_to :mongo_mapper_has_many_target_testable, :polymorphic => true
|
16
|
+
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
|
17
|
+
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
|
11
18
|
end
|
12
19
|
|
@@ -8,5 +8,12 @@ class CouchRestHasOneTarget < CouchRest::Model::Base
|
|
8
8
|
t_belongs_to :mongo_mapper_object
|
9
9
|
require_mongoid { t_belongs_to :mongoid_object }
|
10
10
|
t_belongs_to :sequel_object
|
11
|
+
|
12
|
+
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
|
13
|
+
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
|
14
|
+
t_belongs_to :data_mapper_has_one_target_testable, :polymorphic => true
|
15
|
+
t_belongs_to :mongo_mapper_has_one_target_testable, :polymorphic => true
|
16
|
+
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
|
17
|
+
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
|
11
18
|
end
|
12
19
|
|