tenacity 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/EXTEND.rdoc +11 -1
- data/README.rdoc +4 -1
- data/Rakefile +20 -9
- data/history.txt +21 -0
- data/lib/tenacity.rb +12 -4
- data/lib/tenacity/associates_proxy.rb +67 -0
- data/lib/tenacity/association.rb +19 -6
- data/lib/tenacity/associations/has_many.rb +6 -0
- data/lib/tenacity/class_methods.rb +52 -1
- data/lib/tenacity/instance_methods.rb +7 -3
- data/lib/tenacity/orm_ext/activerecord.rb +30 -13
- data/lib/tenacity/orm_ext/couchrest.rb +140 -0
- data/lib/tenacity/orm_ext/datamapper.rb +139 -0
- data/lib/tenacity/orm_ext/mongo_mapper.rb +88 -80
- data/lib/tenacity/orm_ext/mongoid.rb +108 -0
- data/lib/tenacity/orm_ext/sequel.rb +134 -0
- data/lib/tenacity/version.rb +1 -1
- data/tenacity.gemspec +14 -3
- data/test/association_features/belongs_to_test.rb +42 -0
- data/test/association_features/has_many_test.rb +110 -0
- data/test/association_features/has_one_test.rb +41 -0
- data/test/associations/belongs_to_test.rb +36 -127
- data/test/associations/has_many_test.rb +77 -196
- data/test/associations/has_one_test.rb +22 -84
- data/test/core/classmethods_test.rb +24 -22
- data/test/fixtures/active_record_has_many_target.rb +10 -0
- data/test/fixtures/active_record_has_one_target.rb +10 -0
- data/test/fixtures/{active_record_nuts.rb → active_record_nut.rb} +0 -0
- data/test/fixtures/active_record_object.rb +17 -0
- data/test/fixtures/couch_rest_door.rb +0 -2
- data/test/fixtures/couch_rest_has_many_target.rb +12 -0
- data/test/fixtures/couch_rest_has_one_target.rb +12 -0
- data/test/fixtures/couch_rest_object.rb +19 -0
- data/test/fixtures/couch_rest_windshield.rb +0 -2
- data/test/fixtures/data_mapper_has_many_target.rb +19 -0
- data/test/fixtures/data_mapper_has_one_target.rb +19 -0
- data/test/fixtures/data_mapper_object.rb +20 -0
- data/test/fixtures/mongo_mapper_ash_tray.rb +0 -2
- data/test/fixtures/mongo_mapper_dashboard.rb +0 -2
- data/test/fixtures/mongo_mapper_has_many_target.rb +11 -0
- data/test/fixtures/mongo_mapper_has_one_target.rb +11 -0
- data/test/fixtures/mongo_mapper_object.rb +18 -0
- data/test/fixtures/mongo_mapper_vent.rb +0 -2
- data/test/fixtures/mongo_mapper_wheel.rb +0 -2
- data/test/fixtures/mongoid_has_many_target.rb +13 -0
- data/test/fixtures/mongoid_has_one_target.rb +13 -0
- data/test/fixtures/mongoid_object.rb +20 -0
- data/test/fixtures/sequel_has_many_target.rb +10 -0
- data/test/fixtures/sequel_has_one_target.rb +10 -0
- data/test/fixtures/sequel_object.rb +17 -0
- data/test/helpers/active_record_test_helper.rb +51 -0
- data/test/helpers/data_mapper_test_helper.rb +44 -0
- data/test/helpers/mongoid_test_helper.rb +21 -0
- data/test/helpers/sequel_test_helper.rb +60 -0
- data/test/orm_ext/activerecord_test.rb +55 -35
- data/test/orm_ext/couchrest_test.rb +66 -46
- data/test/orm_ext/datamapper_test.rb +112 -0
- data/test/orm_ext/mongo_mapper_test.rb +64 -44
- data/test/orm_ext/mongoid_test.rb +121 -0
- data/test/orm_ext/sequel_test.rb +113 -0
- data/test/test_helper.rb +87 -11
- metadata +159 -59
- data/lib/tenacity/orm_ext/couchrest/couchrest_extended_document.rb +0 -42
- data/lib/tenacity/orm_ext/couchrest/couchrest_model.rb +0 -44
- data/lib/tenacity/orm_ext/couchrest/tenacity_class_methods.rb +0 -43
- data/lib/tenacity/orm_ext/couchrest/tenacity_instance_methods.rb +0 -21
- data/test/fixtures/couch_rest_radio.rb +0 -10
- data/test/fixtures/mongo_mapper_button.rb +0 -6
@@ -8,92 +8,112 @@ class MongoMapperTest < Test::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
should "be able to find the object in the database" do
|
11
|
-
|
12
|
-
assert_equal
|
11
|
+
object = MongoMapperObject.create
|
12
|
+
assert_equal object, MongoMapperObject._t_find(object.id)
|
13
13
|
end
|
14
14
|
|
15
15
|
should "return nil if the specified id could not be found in the database" do
|
16
|
-
assert_nil
|
16
|
+
assert_nil MongoMapperObject._t_find('4d0e1224b28cdbfb72000042')
|
17
17
|
end
|
18
18
|
|
19
19
|
should "be able to find multiple objects in the database" do
|
20
|
-
|
21
|
-
|
22
|
-
assert_set_equal [
|
20
|
+
object_1 = MongoMapperObject.create
|
21
|
+
object_2 = MongoMapperObject.create
|
22
|
+
assert_set_equal [object_1, object_2], MongoMapperObject._t_find_bulk([object_1.id, object_2.id, '4d0e1224b28cdbfb72000042'])
|
23
23
|
end
|
24
24
|
|
25
25
|
should "return an empty array if none of the specified object ids could be found in the database" do
|
26
|
-
assert_equal [],
|
26
|
+
assert_equal [], MongoMapperObject._t_find_bulk(['4d0e1224b28cdbfb72000042', '4d0e1224b28cdbfb72000043', '4d0e1224b28cdbfb72000044'])
|
27
27
|
end
|
28
28
|
|
29
29
|
should "be able to find the first associate of an object" do
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal
|
30
|
+
object = MongoMapperObject.create
|
31
|
+
target = MongoMapperHasOneTarget.create(:mongo_mapper_object_id => object.id.to_s)
|
32
|
+
assert_equal target, MongoMapperHasOneTarget._t_find_first_by_associate(:mongo_mapper_object_id, object.id)
|
33
33
|
end
|
34
34
|
|
35
35
|
should "return nil if the first associate of an object could not be found" do
|
36
|
-
assert_nil
|
36
|
+
assert_nil MongoMapperHasOneTarget._t_find_first_by_associate(:mongo_mapper_object_id, 12345)
|
37
37
|
end
|
38
38
|
|
39
39
|
should "be able to find the associates of an object" do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert_set_equal [
|
40
|
+
target_1 = MongoMapperHasOneTarget.create(:mongo_mapper_object_id => '101')
|
41
|
+
target_2 = MongoMapperHasOneTarget.create(:mongo_mapper_object_id => '101')
|
42
|
+
target_3 = MongoMapperHasOneTarget.create(:mongo_mapper_object_id => '102')
|
43
|
+
assert_set_equal [target_1, target_2], MongoMapperHasOneTarget._t_find_all_by_associate(:mongo_mapper_object_id, '101')
|
44
44
|
end
|
45
45
|
|
46
46
|
should "return an empty array if the object has no associates" do
|
47
|
-
assert_equal [],
|
47
|
+
assert_equal [], MongoMapperHasOneTarget._t_find_all_by_associate(:mongo_mapper_object_id, '1234')
|
48
48
|
end
|
49
49
|
|
50
50
|
should "be able to reload an object from the database" do
|
51
|
-
|
52
|
-
|
53
|
-
assert_equal 101,
|
54
|
-
|
55
|
-
assert_equal '',
|
51
|
+
target = MongoMapperHasOneTarget.create
|
52
|
+
target.mongo_mapper_object_id = 101
|
53
|
+
assert_equal '101', target.mongo_mapper_object_id
|
54
|
+
target.reload
|
55
|
+
assert_equal '', target.mongo_mapper_object_id
|
56
56
|
end
|
57
57
|
|
58
58
|
should "be able to associate many objects with the given object" do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
assert_set_equal [
|
59
|
+
target_1 = MongoMapperHasManyTarget.create
|
60
|
+
target_2 = MongoMapperHasManyTarget.create
|
61
|
+
target_3 = MongoMapperHasManyTarget.create
|
62
|
+
object = MongoMapperObject.create
|
63
|
+
object._t_associate_many(association, [target_1.id, target_2.id, target_3.id])
|
64
|
+
assert_set_equal [target_1.id.to_s, target_2.id.to_s, target_3.id.to_s], object.t_mongo_mapper_has_many_target_ids
|
65
65
|
end
|
66
66
|
|
67
67
|
should "be able to get the ids of the objects associated with the given object" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
target_1 = MongoMapperHasManyTarget.create
|
69
|
+
target_2 = MongoMapperHasManyTarget.create
|
70
|
+
target_3 = MongoMapperHasManyTarget.create
|
71
|
+
object = MongoMapperObject.create
|
72
72
|
|
73
|
-
|
74
|
-
assert_set_equal [
|
73
|
+
object._t_associate_many(association, [target_1.id, target_2.id, target_3.id])
|
74
|
+
assert_set_equal [target_1.id.to_s, target_2.id.to_s, target_3.id.to_s], object._t_get_associate_ids(association)
|
75
75
|
end
|
76
76
|
|
77
77
|
should "return an empty array when trying to fetch associate ids for an object with no associates" do
|
78
|
-
|
79
|
-
assert_equal [],
|
78
|
+
object = MongoMapperObject.create
|
79
|
+
assert_equal [], object._t_get_associate_ids(association)
|
80
80
|
end
|
81
81
|
|
82
82
|
should "be able to clear the associates of an object" do
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
target_1 = MongoMapperHasManyTarget.create
|
84
|
+
target_2 = MongoMapperHasManyTarget.create
|
85
|
+
target_3 = MongoMapperHasManyTarget.create
|
86
|
+
object = MongoMapperObject.create
|
87
|
+
|
88
|
+
object._t_associate_many(association, [target_1.id, target_2.id, target_3.id])
|
89
|
+
assert_set_equal [target_1.id.to_s, target_2.id.to_s, target_3.id.to_s], object._t_get_associate_ids(association)
|
90
|
+
object._t_clear_associates(association)
|
91
|
+
assert_equal [], object._t_get_associate_ids(association)
|
92
|
+
end
|
93
|
+
|
94
|
+
should "be able to delete a set of objects, issuing their callbacks" do
|
95
|
+
object_1 = MongoMapperObject.create
|
96
|
+
object_2 = MongoMapperObject.create
|
97
|
+
object_3 = MongoMapperObject.create
|
98
|
+
|
99
|
+
old_count = MongoMapperObject.count
|
100
|
+
MongoMapperObject._t_delete([object_1.id, object_2.id, object_3.id])
|
101
|
+
assert_equal old_count - 3, MongoMapperObject.count
|
102
|
+
end
|
103
|
+
|
104
|
+
should "be able to delete a setup of objects, without issuing their callbacks" do
|
105
|
+
object_1 = MongoMapperObject.create
|
106
|
+
object_2 = MongoMapperObject.create
|
107
|
+
object_3 = MongoMapperObject.create
|
87
108
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
assert_equal [], wheel._t_get_associate_ids(association)
|
109
|
+
old_count = MongoMapperObject.count
|
110
|
+
MongoMapperObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
111
|
+
assert_equal old_count - 3, MongoMapperObject.count
|
92
112
|
end
|
93
113
|
end
|
94
114
|
|
95
115
|
def association
|
96
|
-
Tenacity::Association.new(:t_has_many, :
|
116
|
+
Tenacity::Association.new(:t_has_many, :mongo_mapper_has_many_targets, MongoMapperObject)
|
97
117
|
end
|
98
118
|
|
99
119
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require_mongoid do
|
4
|
+
class MongoidTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Mongoid extension" do
|
7
|
+
setup do
|
8
|
+
setup_fixtures
|
9
|
+
end
|
10
|
+
|
11
|
+
should "be able to find the object in the database" do
|
12
|
+
object = MongoidObject.create
|
13
|
+
assert_equal object, MongoidObject._t_find(object.id)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "return nil if the specified id could not be found in the database" do
|
17
|
+
assert_nil MongoidObject._t_find('4d0e1224b28cdbfb72000042')
|
18
|
+
end
|
19
|
+
|
20
|
+
should "be able to find multiple objects in the database" do
|
21
|
+
object_1 = MongoidObject.create
|
22
|
+
object_2 = MongoidObject.create
|
23
|
+
assert_set_equal [object_1, object_2], MongoidObject._t_find_bulk([object_1.id, object_2.id, '4d0e1224b28cdbfb72000042'])
|
24
|
+
end
|
25
|
+
|
26
|
+
should "return an empty array if none of the specified object ids could be found in the database" do
|
27
|
+
assert_equal [], MongoidObject._t_find_bulk(['4d0e1224b28cdbfb72000042', '4d0e1224b28cdbfb72000043', '4d0e1224b28cdbfb72000044'])
|
28
|
+
end
|
29
|
+
|
30
|
+
should "be able to find the first associate of an object" do
|
31
|
+
object = MongoidObject.create
|
32
|
+
target = MongoidHasOneTarget.create(:mongoid_object_id => object.id.to_s)
|
33
|
+
assert_equal target, MongoidHasOneTarget._t_find_first_by_associate(:mongoid_object_id, object.id)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "return nil if the first associate of an object could not be found" do
|
37
|
+
assert_nil MongoidHasOneTarget._t_find_first_by_associate(:mongoid_object_id, 12345)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "be able to find the associates of an object" do
|
41
|
+
target_1 = MongoidHasOneTarget.create(:mongoid_object_id => '101')
|
42
|
+
target_2 = MongoidHasOneTarget.create(:mongoid_object_id => '101')
|
43
|
+
target_3 = MongoidHasOneTarget.create(:mongoid_object_id => '102')
|
44
|
+
assert_set_equal [target_1, target_2], MongoidHasOneTarget._t_find_all_by_associate(:mongoid_object_id, '101')
|
45
|
+
end
|
46
|
+
|
47
|
+
should "return an empty array if the object has no associates" do
|
48
|
+
assert_equal [], MongoidHasOneTarget._t_find_all_by_associate(:mongoid_object_id, '1234')
|
49
|
+
end
|
50
|
+
|
51
|
+
should "be able to reload an object from the database" do
|
52
|
+
target = MongoidHasOneTarget.create
|
53
|
+
target.mongoid_object_id = 101
|
54
|
+
assert_equal '101', target.mongoid_object_id
|
55
|
+
target.reload
|
56
|
+
assert_equal '', target.mongoid_object_id
|
57
|
+
end
|
58
|
+
|
59
|
+
should "be able to associate many objects with the given object" do
|
60
|
+
target_1 = MongoidHasManyTarget.create
|
61
|
+
target_2 = MongoidHasManyTarget.create
|
62
|
+
target_3 = MongoidHasManyTarget.create
|
63
|
+
object = MongoidObject.create
|
64
|
+
object._t_associate_many(association, [target_1.id, target_2.id, target_3.id])
|
65
|
+
assert_set_equal [target_1.id.to_s, target_2.id.to_s, target_3.id.to_s], object.t_mongoid_has_many_target_ids
|
66
|
+
end
|
67
|
+
|
68
|
+
should "be able to get the ids of the objects associated with the given object" do
|
69
|
+
target_1 = MongoidHasManyTarget.create
|
70
|
+
target_2 = MongoidHasManyTarget.create
|
71
|
+
target_3 = MongoidHasManyTarget.create
|
72
|
+
object = MongoidObject.create
|
73
|
+
|
74
|
+
object._t_associate_many(association, [target_1.id, target_2.id, target_3.id])
|
75
|
+
assert_set_equal [target_1.id.to_s, target_2.id.to_s, target_3.id.to_s], object._t_get_associate_ids(association)
|
76
|
+
end
|
77
|
+
|
78
|
+
should "return an empty array when trying to fetch associate ids for an object with no associates" do
|
79
|
+
object = MongoidObject.create
|
80
|
+
assert_equal [], object._t_get_associate_ids(association)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "be able to clear the associates of an object" do
|
84
|
+
target_1 = MongoidHasManyTarget.create
|
85
|
+
target_2 = MongoidHasManyTarget.create
|
86
|
+
target_3 = MongoidHasManyTarget.create
|
87
|
+
object = MongoidObject.create
|
88
|
+
|
89
|
+
object._t_associate_many(association, [target_1.id, target_2.id, target_3.id])
|
90
|
+
assert_set_equal [target_1.id.to_s, target_2.id.to_s, target_3.id.to_s], object._t_get_associate_ids(association)
|
91
|
+
object._t_clear_associates(association)
|
92
|
+
assert_equal [], object._t_get_associate_ids(association)
|
93
|
+
end
|
94
|
+
|
95
|
+
should "be able to delete a set of objects, issuing their callbacks" do
|
96
|
+
object_1 = MongoidObject.create
|
97
|
+
object_2 = MongoidObject.create
|
98
|
+
object_3 = MongoidObject.create
|
99
|
+
|
100
|
+
old_count = MongoidObject.count
|
101
|
+
MongoidObject._t_delete([object_1.id, object_2.id, object_3.id])
|
102
|
+
assert_equal old_count - 3, MongoidObject.count
|
103
|
+
end
|
104
|
+
|
105
|
+
should "be able to delete a setup of objects, without issuing their callbacks" do
|
106
|
+
object_1 = MongoidObject.create
|
107
|
+
object_2 = MongoidObject.create
|
108
|
+
object_3 = MongoidObject.create
|
109
|
+
|
110
|
+
old_count = MongoidObject.count
|
111
|
+
MongoidObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
112
|
+
assert_equal old_count - 3, MongoidObject.count
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def association
|
117
|
+
Tenacity::Association.new(:t_has_many, :mongoid_has_many_targets, MongoidObject)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SequelTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "The Sequel extension" do
|
6
|
+
setup do
|
7
|
+
setup_fixtures
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be able to find the object in the database" do
|
11
|
+
object = SequelObject.create
|
12
|
+
assert_equal object, SequelObject._t_find(object.id)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "return nil if the specified object cannot be found in the database" do
|
16
|
+
assert_nil SequelObject._t_find(989782)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be able to find multiple objects in the database" do
|
20
|
+
object = SequelObject.create
|
21
|
+
object_2 = SequelObject.create
|
22
|
+
assert_set_equal [object, object_2], SequelObject._t_find_bulk([object.id, object_2.id, 989823])
|
23
|
+
end
|
24
|
+
|
25
|
+
should "return an empty array if none of the specified ids could be found in the database" do
|
26
|
+
assert_set_equal [], SequelObject._t_find_bulk([989823, 992111, 989771])
|
27
|
+
end
|
28
|
+
|
29
|
+
should "be able to find the first associate of an object" do
|
30
|
+
object = SequelObject.create
|
31
|
+
has_one_target = SequelHasOneTarget.create(:sequel_object_id => object.id)
|
32
|
+
assert_equal has_one_target, SequelHasOneTarget._t_find_first_by_associate(:sequel_object_id, object.id)
|
33
|
+
end
|
34
|
+
|
35
|
+
should "return nil if unable to find the first associate of an object" do
|
36
|
+
assert_nil SequelHasOneTarget._t_find_first_by_associate(:sequel_object_id, '9999999')
|
37
|
+
end
|
38
|
+
|
39
|
+
should "be able to find all associates of an object" do
|
40
|
+
object = SequelObject.create
|
41
|
+
has_many_target_1 = SequelHasManyTarget.create(:sequel_object_id => object.id)
|
42
|
+
has_many_target_2 = SequelHasManyTarget.create(:sequel_object_id => object.id)
|
43
|
+
has_many_target_3 = SequelHasManyTarget.create(:sequel_object_id => '9999999')
|
44
|
+
assert_set_equal [has_many_target_1, has_many_target_2], SequelHasManyTarget._t_find_all_by_associate(:sequel_object_id, object.id)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "return an empty array able to find the associates of an object" do
|
48
|
+
assert_set_equal [], SequelHasManyTarget._t_find_all_by_associate(:sequel_object_id, '9999999999')
|
49
|
+
end
|
50
|
+
|
51
|
+
should "be able to reload an object from the database" do
|
52
|
+
object = SequelHasOneTarget.create
|
53
|
+
object.mongo_mapper_object_id = 'abc123'
|
54
|
+
assert_equal 'abc123', object.mongo_mapper_object_id
|
55
|
+
object.reload
|
56
|
+
assert_equal '', object.mongo_mapper_object_id
|
57
|
+
end
|
58
|
+
|
59
|
+
should "be able to clear the associates of a given object" do
|
60
|
+
object = SequelObject.create
|
61
|
+
object._t_associate_many(association, ['abc123', 'def456', 'ghi789'])
|
62
|
+
object.save
|
63
|
+
object._t_clear_associates(association)
|
64
|
+
assert_set_equal [], object._t_get_associate_ids(association)
|
65
|
+
end
|
66
|
+
|
67
|
+
should "be able to associate many objects with the given object" do
|
68
|
+
object = SequelObject.create
|
69
|
+
object._t_associate_many(association, ['abc123', 'def456', 'ghi789'])
|
70
|
+
|
71
|
+
rows = DB["select mongo_mapper_has_many_target_id from mongo_mapper_has_many_targets_sequel_objects where sequel_object_id = #{object.id}"].all
|
72
|
+
ids = rows.map { |row| row[:mongo_mapper_has_many_target_id] }
|
73
|
+
assert_set_equal ['abc123', 'def456', 'ghi789'], ids
|
74
|
+
end
|
75
|
+
|
76
|
+
should "be able to get the ids of the objects associated with the given object" do
|
77
|
+
object = SequelObject.create
|
78
|
+
object._t_associate_many(association, ['abc123', 'def456', 'ghi789'])
|
79
|
+
assert_set_equal ['abc123', 'def456', 'ghi789'], object._t_get_associate_ids(association)
|
80
|
+
end
|
81
|
+
|
82
|
+
should "return an empty array if there are no objects associated with the given object ids" do
|
83
|
+
object = SequelObject.create
|
84
|
+
assert_set_equal [], object._t_get_associate_ids(association)
|
85
|
+
end
|
86
|
+
|
87
|
+
should "be able to delete a set of objects, issuing their callbacks" do
|
88
|
+
object_1 = SequelObject.create
|
89
|
+
object_2 = SequelObject.create
|
90
|
+
object_3 = SequelObject.create
|
91
|
+
|
92
|
+
old_count = SequelObject.count
|
93
|
+
SequelObject._t_delete([object_1.id, object_2.id, object_3.id])
|
94
|
+
assert_equal old_count - 3, SequelObject.count
|
95
|
+
end
|
96
|
+
|
97
|
+
should "be able to delete a setup of objects, without issuing their callbacks" do
|
98
|
+
object_1 = SequelObject.create
|
99
|
+
object_2 = SequelObject.create
|
100
|
+
object_3 = SequelObject.create
|
101
|
+
|
102
|
+
old_count = SequelObject.count
|
103
|
+
SequelObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
104
|
+
assert_equal old_count - 3, SequelObject.count
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def association
|
111
|
+
Tenacity::Association.new(:t_has_many, :mongo_mapper_has_many_targets, SequelObject)
|
112
|
+
end
|
113
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -12,8 +12,11 @@ require 'test/unit'
|
|
12
12
|
require 'shoulda'
|
13
13
|
|
14
14
|
require File.join(File.dirname(__FILE__), 'helpers', 'active_record_test_helper')
|
15
|
-
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_mapper_test_helper')
|
16
15
|
require File.join(File.dirname(__FILE__), 'helpers', 'couch_rest_test_helper')
|
16
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'data_mapper_test_helper')
|
17
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_mapper_test_helper')
|
18
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongoid_test_helper')
|
19
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'sequel_test_helper')
|
17
20
|
|
18
21
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
19
22
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
@@ -21,18 +24,38 @@ require 'tenacity'
|
|
21
24
|
|
22
25
|
Dir[File.join(File.dirname(__FILE__), 'fixtures', '*.rb')].each { |file| require file }
|
23
26
|
|
27
|
+
DataMapper.auto_migrate!
|
28
|
+
|
24
29
|
def setup_fixtures
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'fixtures', '*.rb')).each do |filename|
|
31
|
+
begin
|
32
|
+
filename =~ /.*\/(.*)\.rb/
|
33
|
+
clazz = Kernel.const_get($1.camelcase)
|
34
|
+
if clazz.respond_to?(:delete_all)
|
35
|
+
clazz.delete_all
|
36
|
+
elsif clazz.respond_to?(:db)
|
37
|
+
clazz.db["delete from #{clazz.table_name}"].delete
|
38
|
+
elsif clazz.respond_to?(:destroy)
|
39
|
+
clazz.destroy
|
40
|
+
elsif filename =~ /\/couch_rest/
|
41
|
+
# CouchDB fixtures are destroyed with the database
|
42
|
+
else
|
43
|
+
puts "WARN: Don't know how to clear fixtures for #{clazz}"
|
44
|
+
end
|
45
|
+
rescue NameError
|
46
|
+
end
|
47
|
+
end
|
32
48
|
|
33
|
-
|
34
|
-
|
35
|
-
|
49
|
+
join_tables = %w{
|
50
|
+
active_record_cars_mongo_mapper_wheels
|
51
|
+
active_record_cars_couch_rest_doors
|
52
|
+
nuts_and_wheels
|
53
|
+
active_record_has_many_targets_active_record_objects
|
54
|
+
active_record_objects_mongo_mapper_has_many_targets
|
55
|
+
active_record_objects_couch_rest_has_many_targets
|
56
|
+
active_record_objects_mongoid_has_many_targets
|
57
|
+
}
|
58
|
+
join_tables.each { |join_table| ActiveRecordCar.connection.execute("delete from #{join_table}") }
|
36
59
|
end
|
37
60
|
|
38
61
|
def setup_couchdb_fixtures
|
@@ -44,6 +67,59 @@ def setup_all_fixtures
|
|
44
67
|
setup_couchdb_fixtures
|
45
68
|
end
|
46
69
|
|
70
|
+
def setup_fixtures_for(source, target)
|
71
|
+
if source == :couch_rest || target == :couch_rest
|
72
|
+
setup_all_fixtures
|
73
|
+
else
|
74
|
+
setup_fixtures
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def orm_extensions
|
79
|
+
extensions = [:active_record, :couch_rest, :data_mapper, :mongo_mapper, :sequel]
|
80
|
+
require_mongoid { extensions << :mongoid }
|
81
|
+
extensions
|
82
|
+
end
|
83
|
+
|
84
|
+
def for_each_orm_extension_combination
|
85
|
+
orm_extensions.each do |source|
|
86
|
+
orm_extensions.each do |target|
|
87
|
+
yield source, target
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def class_for_extension(extension, type=nil)
|
93
|
+
if type.nil?
|
94
|
+
class_name = extension.to_s.camelcase + "Object"
|
95
|
+
elsif type == :belongs_to || type == :has_one
|
96
|
+
class_name = extension.to_s.camelcase + "HasOneTarget"
|
97
|
+
elsif type == :has_many
|
98
|
+
class_name = extension.to_s.camelcase + "HasManyTarget"
|
99
|
+
end
|
100
|
+
Kernel.const_get(class_name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def foreign_key_for(extension, type)
|
104
|
+
if type == :belongs_to
|
105
|
+
"#{extension}_object"
|
106
|
+
elsif type == :has_one
|
107
|
+
"#{extension}_has_one_target"
|
108
|
+
elsif type == :has_many
|
109
|
+
"#{extension}_has_many_targets"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def foreign_key_id_for(extension, type)
|
114
|
+
if type == :belongs_to
|
115
|
+
"#{extension}_object_id"
|
116
|
+
elsif type == :has_one
|
117
|
+
"#{extension}_has_one_target_id"
|
118
|
+
elsif type == :has_many
|
119
|
+
"#{extension}_has_many_target_ids"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
47
123
|
def assert_set_equal(expecteds, actuals, message = nil)
|
48
124
|
assert_equal expecteds && Set.new(expecteds), actuals && Set.new(actuals), message
|
49
125
|
end
|