tenacity 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/EXTEND.rdoc +10 -3
- data/Gemfile +1 -2
- data/README.rdoc +3 -2
- data/Rakefile +6 -0
- data/history.txt +11 -0
- data/lib/tenacity/associate_proxy.rb +1 -1
- data/lib/tenacity/associates_proxy.rb +4 -4
- data/lib/tenacity/associations/has_many.rb +7 -8
- data/lib/tenacity/associations/has_one.rb +4 -4
- data/lib/tenacity/class_methods.rb +1 -1
- data/lib/tenacity/errors.rb +4 -8
- data/lib/tenacity/instance_methods.rb +2 -2
- data/lib/tenacity/orm_ext/activerecord.rb +5 -1
- data/lib/tenacity/orm_ext/couchrest.rb +4 -0
- data/lib/tenacity/orm_ext/datamapper.rb +5 -1
- data/lib/tenacity/orm_ext/helpers.rb +3 -3
- data/lib/tenacity/orm_ext/mongo_mapper.rb +4 -0
- data/lib/tenacity/orm_ext/mongoid.rb +4 -0
- data/lib/tenacity/orm_ext/ripple.rb +4 -0
- data/lib/tenacity/orm_ext/sequel.rb +5 -1
- data/lib/tenacity/orm_ext/toystore.rb +4 -0
- data/lib/tenacity/version.rb +1 -1
- data/test/associations/belongs_to_test.rb +3 -3
- data/test/associations/has_many_test.rb +6 -6
- data/test/associations/has_one_test.rb +4 -4
- data/test/core/classmethods_test.rb +14 -0
- data/test/fixtures/active_record_object_with_string_id.rb +5 -0
- data/test/fixtures/couch_rest_object.rb +2 -0
- data/test/fixtures/data_mapper_object.rb +1 -0
- data/test/fixtures/data_mapper_object_with_string_id.rb +6 -0
- data/test/fixtures/mongo_mapper_object.rb +4 -0
- data/test/fixtures/mongoid_object.rb +2 -0
- data/test/fixtures/ripple_object.rb +2 -0
- data/test/fixtures/sequel_object_with_string_id.rb +3 -0
- data/test/fixtures/toystore_object.rb +2 -0
- data/test/helpers/active_record_test_helper.rb +4 -0
- data/test/helpers/data_mapper_test_helper.rb +1 -0
- data/test/helpers/sequel_test_helper.rb +5 -0
- data/test/orm_ext/activerecord_test.rb +16 -0
- data/test/orm_ext/datamapper_test.rb +16 -0
- data/test/orm_ext/mongo_mapper_test.rb +11 -0
- data/test/orm_ext/mongoid_test.rb +11 -0
- data/test/orm_ext/ripple_test.rb +147 -134
- data/test/orm_ext/sequel_test.rb +16 -0
- data/test/orm_ext/toystore_test.rb +11 -0
- data/test/test_helper.rb +8 -8
- metadata +46 -152
@@ -9,11 +9,11 @@ class HasOneTest < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
@source_class = class_for_extension(source)
|
11
11
|
@source = @source_class.create({})
|
12
|
-
@target_class = class_for_extension(target, :
|
12
|
+
@target_class = class_for_extension(target, :t_has_one)
|
13
13
|
@target = @target_class.create({})
|
14
14
|
|
15
|
-
@foreign_key = foreign_key_for(target, :
|
16
|
-
@foreign_key_id = foreign_key_id_for(target, :
|
15
|
+
@foreign_key = foreign_key_for(target, :t_has_one)
|
16
|
+
@foreign_key_id = foreign_key_id_for(target, :t_has_one)
|
17
17
|
end
|
18
18
|
|
19
19
|
should "be able to set and get the associated object" do
|
@@ -60,7 +60,7 @@ class HasOneTest < Test::Unit::TestCase
|
|
60
60
|
|
61
61
|
assert_nil @source_class._t_find(serialize_id(@source))
|
62
62
|
assert_not_nil @target_class._t_find(serialize_id(@target))
|
63
|
-
assert_nil @target_class._t_find(serialize_id(@target)).send(foreign_key_id_for(target, :
|
63
|
+
assert_nil @target_class._t_find(serialize_id(@target)).send(foreign_key_id_for(target, :t_belongs_to))
|
64
64
|
end
|
65
65
|
|
66
66
|
context "with a polymorphic association" do
|
@@ -58,5 +58,19 @@ class ClassmethodsTest < Test::Unit::TestCase
|
|
58
58
|
should("respond to destroy_all") { assert @targets.respond_to?(:destroy_all) }
|
59
59
|
end
|
60
60
|
|
61
|
+
context "A class including Tenacity" do
|
62
|
+
should "be able to override the default object id type" do
|
63
|
+
active_record_object = ActiveRecordObjectWithStringId.new
|
64
|
+
active_record_object.id = 'abc999'
|
65
|
+
active_record_object.save!
|
66
|
+
|
67
|
+
mongo_mapper_object = MongoMapperObject.create
|
68
|
+
mongo_mapper_object.active_record_object_with_string_id = active_record_object
|
69
|
+
mongo_mapper_object.save
|
70
|
+
|
71
|
+
assert_equal active_record_object, MongoMapperObject._t_find(mongo_mapper_object.id).active_record_object_with_string_id
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
61
75
|
end
|
62
76
|
|
@@ -2,6 +2,8 @@ class MongoMapperObject
|
|
2
2
|
include MongoMapper::Document
|
3
3
|
include Tenacity
|
4
4
|
|
5
|
+
key :prop, String
|
6
|
+
|
5
7
|
t_has_one :active_record_has_one_target
|
6
8
|
t_has_one :couch_rest_has_one_target
|
7
9
|
t_has_one :data_mapper_has_one_target
|
@@ -37,4 +39,6 @@ class MongoMapperObject
|
|
37
39
|
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
|
38
40
|
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
|
39
41
|
require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
|
42
|
+
|
43
|
+
t_belongs_to :active_record_object_with_string_id
|
40
44
|
end
|
@@ -26,6 +26,10 @@ ActiveRecord::Schema.define :version => 0 do
|
|
26
26
|
t.string :prop
|
27
27
|
end
|
28
28
|
|
29
|
+
create_table :active_record_object_with_string_ids, :force => true, :id => false do |t|
|
30
|
+
t.string :id, :limit => 36, :primary => true
|
31
|
+
end
|
32
|
+
|
29
33
|
create_table :active_record_has_one_targets, :force => true do |t|
|
30
34
|
t.integer :active_record_object_id
|
31
35
|
t.string :couch_rest_object_id
|
@@ -5,6 +5,11 @@ Sequel::Model.raise_on_save_failure = true
|
|
5
5
|
|
6
6
|
DB.create_table :sequel_objects do
|
7
7
|
primary_key :id
|
8
|
+
String :prop
|
9
|
+
end
|
10
|
+
|
11
|
+
DB.create_table :sequel_object_with_string_ids do
|
12
|
+
String :id, :primary_key => true
|
8
13
|
end
|
9
14
|
|
10
15
|
DB.create_table :sequel_has_one_targets do
|
@@ -91,6 +91,22 @@ class ActiveRecordTest < Test::Unit::TestCase
|
|
91
91
|
ActiveRecordObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
92
92
|
assert_equal old_count - 3, ActiveRecordObject.count
|
93
93
|
end
|
94
|
+
|
95
|
+
should "save the object if it is dirty" do
|
96
|
+
object = ActiveRecordObject.create
|
97
|
+
object.prop = "something"
|
98
|
+
assert object._t_save_if_dirty
|
99
|
+
end
|
100
|
+
|
101
|
+
should "not save the object if it is not dirty" do
|
102
|
+
object = ActiveRecordObject.create
|
103
|
+
assert !object._t_save_if_dirty
|
104
|
+
end
|
105
|
+
|
106
|
+
should "be able to successfully determine the id type" do
|
107
|
+
assert_equal Integer, ActiveRecordObject._t_id_type
|
108
|
+
assert_equal String, ActiveRecordObjectWithStringId._t_id_type
|
109
|
+
end
|
94
110
|
end
|
95
111
|
|
96
112
|
private
|
@@ -83,6 +83,22 @@ class DataMapperTest < Test::Unit::TestCase
|
|
83
83
|
assert_equal old_count - 3, DataMapperObject.count
|
84
84
|
end
|
85
85
|
|
86
|
+
should "save the object if it is dirty" do
|
87
|
+
object = DataMapperObject.create
|
88
|
+
object.prop = "something"
|
89
|
+
assert object._t_save_if_dirty
|
90
|
+
end
|
91
|
+
|
92
|
+
should "not save the object if it is not dirty" do
|
93
|
+
object = DataMapperObject.create
|
94
|
+
assert !object._t_save_if_dirty
|
95
|
+
end
|
96
|
+
|
97
|
+
should "be able to successfully determine the id type" do
|
98
|
+
assert_equal Integer, DataMapperObject._t_id_type
|
99
|
+
assert_equal String, DataMapperObjectWithStringId._t_id_type
|
100
|
+
end
|
101
|
+
|
86
102
|
context "that works with t_has_many associations" do
|
87
103
|
setup do
|
88
104
|
@has_many_target_1 = DataMapperHasManyTarget.create
|
@@ -92,6 +92,17 @@ class MongoMapperTest < Test::Unit::TestCase
|
|
92
92
|
MongoMapperObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
93
93
|
assert_equal old_count - 3, MongoMapperObject.count
|
94
94
|
end
|
95
|
+
|
96
|
+
should "save the object if it is dirty" do
|
97
|
+
object = MongoMapperObject.create
|
98
|
+
object.prop = "something"
|
99
|
+
assert object._t_save_if_dirty
|
100
|
+
end
|
101
|
+
|
102
|
+
should "not save the object if it is not dirty" do
|
103
|
+
object = MongoMapperObject.create
|
104
|
+
assert !object._t_save_if_dirty
|
105
|
+
end
|
95
106
|
end
|
96
107
|
|
97
108
|
def association
|
@@ -93,6 +93,17 @@ require_mongoid do
|
|
93
93
|
MongoidObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
94
94
|
assert_equal old_count - 3, MongoidObject.count
|
95
95
|
end
|
96
|
+
|
97
|
+
should "save the object if it is dirty" do
|
98
|
+
object = MongoidObject.create
|
99
|
+
object.prop = "something"
|
100
|
+
assert object._t_save_if_dirty
|
101
|
+
end
|
102
|
+
|
103
|
+
should "not save the object if it is not dirty" do
|
104
|
+
object = MongoidObject.create
|
105
|
+
assert !object._t_save_if_dirty
|
106
|
+
end
|
96
107
|
end
|
97
108
|
|
98
109
|
def association
|
data/test/orm_ext/ripple_test.rb
CHANGED
@@ -1,140 +1,153 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
object
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
3
|
+
if ENV['LONG'] == 'true'
|
4
|
+
require_ripple do
|
5
|
+
class RippleTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "The Ripple extension" do
|
8
|
+
setup do
|
9
|
+
setup_ripple_fixtures
|
10
|
+
end
|
11
|
+
|
12
|
+
should "be able to find the object in the database" do
|
13
|
+
object = RippleObject.create
|
14
|
+
assert_equal object, RippleObject._t_find(object.id)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "return nil if the specified id could not be found in the database" do
|
18
|
+
assert_nil RippleObject._t_find('something')
|
19
|
+
end
|
20
|
+
|
21
|
+
should "be able to find multiple objects in the database" do
|
22
|
+
object_1 = RippleObject.create
|
23
|
+
object_2 = RippleObject.create
|
24
|
+
assert_set_equal [object_1, object_2], RippleObject._t_find_bulk([object_1.id, object_2.id, 'bogus_key'])
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return an empty array if none of the specified object ids could be found in the database" do
|
28
|
+
assert_equal [], RippleObject._t_find_bulk(['bogus_key_1', 'bogus_key_2', 'bogus_key_3'])
|
29
|
+
end
|
30
|
+
|
31
|
+
should "be able to find the first associate of an object" do
|
32
|
+
object = RippleObject.create
|
33
|
+
target = RippleHasOneTarget.create(:ripple_object_id => object.id)
|
34
|
+
assert_equal target, RippleHasOneTarget._t_find_first_by_associate(:ripple_object_id, object.id)
|
35
|
+
end
|
36
|
+
|
37
|
+
should "return nil if the first associate of an object could not be found" do
|
38
|
+
assert_nil RippleHasOneTarget._t_find_first_by_associate(:ripple_object_id, 12345)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "be able to find the associates of an object" do
|
42
|
+
object_1 = RippleObject.create
|
43
|
+
object_2 = RippleObject.create
|
44
|
+
target_1 = RippleHasOneTarget.create(:ripple_object => object_1)
|
45
|
+
target_2 = RippleHasOneTarget.create(:ripple_object => object_1)
|
46
|
+
target_3 = RippleHasOneTarget.create(:ripple_object => object_2)
|
47
|
+
assert_set_equal [target_1, target_2], RippleHasOneTarget._t_find_all_by_associate(:ripple_object_id, object_1.id)
|
48
|
+
end
|
49
|
+
|
50
|
+
should "return an empty array if the object has no associates" do
|
51
|
+
assert_equal [], RippleHasOneTarget._t_find_all_by_associate(:ripple_object_id, '1234')
|
52
|
+
end
|
53
|
+
|
54
|
+
should "be able to reload an object from the database" do
|
55
|
+
target = RippleHasOneTarget.create
|
56
|
+
target.ripple_object_id = '101'
|
57
|
+
assert_equal '101', target.ripple_object_id
|
58
|
+
target._t_reload
|
59
|
+
assert_nil target.ripple_object_id
|
60
|
+
end
|
61
|
+
|
62
|
+
should "be able to get the ids of the objects associated with the given object" do
|
63
|
+
target_1 = RippleHasManyTarget.create
|
64
|
+
target_2 = RippleHasManyTarget.create
|
65
|
+
target_3 = RippleHasManyTarget.create
|
66
|
+
object = RippleObject.create
|
67
|
+
object.ripple_has_many_targets = [target_1, target_2, target_3]
|
68
|
+
object.save
|
69
|
+
|
70
|
+
assert_set_equal [target_1.id, target_2.id, target_3.id], RippleHasManyTarget._t_find_all_ids_by_associate("ripple_object_id", object.id)
|
71
|
+
end
|
72
|
+
|
73
|
+
should "return an empty array when trying to fetch associate ids for an object with no associates" do
|
74
|
+
object = RippleObject.create
|
75
|
+
assert_equal [], RippleHasManyTarget._t_find_all_ids_by_associate("ripple_object_id", object.id)
|
76
|
+
end
|
77
|
+
|
78
|
+
should "be able to delete a set of objects, issuing their callbacks" do
|
79
|
+
object_1 = RippleObject.create
|
80
|
+
object_2 = RippleObject.create
|
81
|
+
object_3 = RippleObject.create
|
82
|
+
|
83
|
+
assert RippleObject.bucket.exist?(object_1.id)
|
84
|
+
assert RippleObject.bucket.exist?(object_2.id)
|
85
|
+
assert RippleObject.bucket.exist?(object_3.id)
|
86
|
+
RippleObject._t_delete([object_1.id, object_2.id, object_3.id])
|
87
|
+
assert !RippleObject.bucket.exist?(object_1.id)
|
88
|
+
assert !RippleObject.bucket.exist?(object_2.id)
|
89
|
+
assert !RippleObject.bucket.exist?(object_3.id)
|
90
|
+
end
|
91
|
+
|
92
|
+
should "be able to delete a setup of objects, without issuing their callbacks" do
|
93
|
+
object_1 = RippleObject.create
|
94
|
+
object_2 = RippleObject.create
|
95
|
+
object_3 = RippleObject.create
|
96
|
+
|
97
|
+
assert RippleObject.bucket.exist?(object_1.id)
|
98
|
+
assert RippleObject.bucket.exist?(object_2.id)
|
99
|
+
assert RippleObject.bucket.exist?(object_3.id)
|
100
|
+
RippleObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
101
|
+
assert !RippleObject.bucket.exist?(object_1.id)
|
102
|
+
assert !RippleObject.bucket.exist?(object_2.id)
|
103
|
+
assert !RippleObject.bucket.exist?(object_3.id)
|
104
|
+
end
|
105
|
+
|
106
|
+
should "create associate indexes when source object is saved" do
|
107
|
+
target_1 = RippleHasManyTarget.create
|
108
|
+
target_2 = RippleHasManyTarget.create
|
109
|
+
target_3 = RippleHasManyTarget.create
|
110
|
+
object = RippleObject.create
|
111
|
+
object.ripple_has_many_targets = [target_1, target_2, target_3]
|
112
|
+
object.save
|
113
|
+
|
114
|
+
bucket = ::Ripple.client.bucket('tenacity_test_ripple_has_many_target_ripple_object_id')
|
115
|
+
assert_set_equal [target_1.id, target_2.id, target_3.id], bucket.get(object.id).data
|
116
|
+
end
|
117
|
+
|
118
|
+
should "destroy associate indexes when source object is saved" do
|
119
|
+
target_1 = RippleHasManyTarget.create
|
120
|
+
target_2 = RippleHasManyTarget.create
|
121
|
+
target_3 = RippleHasManyTarget.create
|
122
|
+
object = RippleObject.create
|
123
|
+
object.ripple_has_many_targets = [target_1, target_2, target_3]
|
124
|
+
object.save
|
125
|
+
|
126
|
+
bucket = ::Ripple.client.bucket('tenacity_test_ripple_has_many_target_ripple_object_id')
|
127
|
+
assert_set_equal [target_1.id, target_2.id, target_3.id], bucket.get(object.id).data
|
128
|
+
target_2.destroy
|
129
|
+
assert_set_equal [target_1.id, target_3.id], bucket.get(object.id).data
|
130
|
+
|
131
|
+
target_1.destroy
|
132
|
+
target_3.destroy
|
133
|
+
assert_set_equal [], bucket.get(object.id).data
|
134
|
+
end
|
135
|
+
|
136
|
+
should "save the object if it is dirty" do
|
137
|
+
object = RippleObject.create
|
138
|
+
object.prop = "something"
|
139
|
+
assert object._t_save_if_dirty
|
140
|
+
end
|
141
|
+
|
142
|
+
should "not save the object if it is not dirty" do
|
143
|
+
object = RippleObject.create
|
144
|
+
assert !object._t_save_if_dirty
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def association
|
149
|
+
Tenacity::Association.new(:t_has_many, :ripple_has_many_targets, RippleObject)
|
28
150
|
end
|
29
|
-
|
30
|
-
should "be able to find the first associate of an object" do
|
31
|
-
object = RippleObject.create
|
32
|
-
target = RippleHasOneTarget.create(:ripple_object_id => object.id)
|
33
|
-
assert_equal target, RippleHasOneTarget._t_find_first_by_associate(:ripple_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 RippleHasOneTarget._t_find_first_by_associate(:ripple_object_id, 12345)
|
38
|
-
end
|
39
|
-
|
40
|
-
should "be able to find the associates of an object" do
|
41
|
-
object_1 = RippleObject.create
|
42
|
-
object_2 = RippleObject.create
|
43
|
-
target_1 = RippleHasOneTarget.create(:ripple_object => object_1)
|
44
|
-
target_2 = RippleHasOneTarget.create(:ripple_object => object_1)
|
45
|
-
target_3 = RippleHasOneTarget.create(:ripple_object => object_2)
|
46
|
-
assert_set_equal [target_1, target_2], RippleHasOneTarget._t_find_all_by_associate(:ripple_object_id, object_1.id)
|
47
|
-
end
|
48
|
-
|
49
|
-
should "return an empty array if the object has no associates" do
|
50
|
-
assert_equal [], RippleHasOneTarget._t_find_all_by_associate(:ripple_object_id, '1234')
|
51
|
-
end
|
52
|
-
|
53
|
-
should "be able to reload an object from the database" do
|
54
|
-
target = RippleHasOneTarget.create
|
55
|
-
target.ripple_object_id = '101'
|
56
|
-
assert_equal '101', target.ripple_object_id
|
57
|
-
target._t_reload
|
58
|
-
assert_nil target.ripple_object_id
|
59
|
-
end
|
60
|
-
|
61
|
-
should "be able to get the ids of the objects associated with the given object" do
|
62
|
-
target_1 = RippleHasManyTarget.create
|
63
|
-
target_2 = RippleHasManyTarget.create
|
64
|
-
target_3 = RippleHasManyTarget.create
|
65
|
-
object = RippleObject.create
|
66
|
-
object.ripple_has_many_targets = [target_1, target_2, target_3]
|
67
|
-
object.save
|
68
|
-
|
69
|
-
assert_set_equal [target_1.id, target_2.id, target_3.id], RippleHasManyTarget._t_find_all_ids_by_associate("ripple_object_id", object.id)
|
70
|
-
end
|
71
|
-
|
72
|
-
should "return an empty array when trying to fetch associate ids for an object with no associates" do
|
73
|
-
object = RippleObject.create
|
74
|
-
assert_equal [], RippleHasManyTarget._t_find_all_ids_by_associate("ripple_object_id", object.id)
|
75
|
-
end
|
76
|
-
|
77
|
-
should "be able to delete a set of objects, issuing their callbacks" do
|
78
|
-
object_1 = RippleObject.create
|
79
|
-
object_2 = RippleObject.create
|
80
|
-
object_3 = RippleObject.create
|
81
|
-
|
82
|
-
assert RippleObject.bucket.exist?(object_1.id)
|
83
|
-
assert RippleObject.bucket.exist?(object_2.id)
|
84
|
-
assert RippleObject.bucket.exist?(object_3.id)
|
85
|
-
RippleObject._t_delete([object_1.id, object_2.id, object_3.id])
|
86
|
-
assert !RippleObject.bucket.exist?(object_1.id)
|
87
|
-
assert !RippleObject.bucket.exist?(object_2.id)
|
88
|
-
assert !RippleObject.bucket.exist?(object_3.id)
|
89
|
-
end
|
90
|
-
|
91
|
-
should "be able to delete a setup of objects, without issuing their callbacks" do
|
92
|
-
object_1 = RippleObject.create
|
93
|
-
object_2 = RippleObject.create
|
94
|
-
object_3 = RippleObject.create
|
95
|
-
|
96
|
-
assert RippleObject.bucket.exist?(object_1.id)
|
97
|
-
assert RippleObject.bucket.exist?(object_2.id)
|
98
|
-
assert RippleObject.bucket.exist?(object_3.id)
|
99
|
-
RippleObject._t_delete([object_1.id, object_2.id, object_3.id], false)
|
100
|
-
assert !RippleObject.bucket.exist?(object_1.id)
|
101
|
-
assert !RippleObject.bucket.exist?(object_2.id)
|
102
|
-
assert !RippleObject.bucket.exist?(object_3.id)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "create associate indexes when source object is saved" do
|
106
|
-
target_1 = RippleHasManyTarget.create
|
107
|
-
target_2 = RippleHasManyTarget.create
|
108
|
-
target_3 = RippleHasManyTarget.create
|
109
|
-
object = RippleObject.create
|
110
|
-
object.ripple_has_many_targets = [target_1, target_2, target_3]
|
111
|
-
object.save
|
112
|
-
|
113
|
-
bucket = ::Ripple.client.bucket('tenacity_test_ripple_has_many_target_ripple_object_id')
|
114
|
-
assert_set_equal [target_1.id, target_2.id, target_3.id], bucket.get(object.id).data
|
115
|
-
end
|
116
|
-
|
117
|
-
should "destroy associate indexes when source object is saved" do
|
118
|
-
target_1 = RippleHasManyTarget.create
|
119
|
-
target_2 = RippleHasManyTarget.create
|
120
|
-
target_3 = RippleHasManyTarget.create
|
121
|
-
object = RippleObject.create
|
122
|
-
object.ripple_has_many_targets = [target_1, target_2, target_3]
|
123
|
-
object.save
|
124
|
-
|
125
|
-
bucket = ::Ripple.client.bucket('tenacity_test_ripple_has_many_target_ripple_object_id')
|
126
|
-
assert_set_equal [target_1.id, target_2.id, target_3.id], bucket.get(object.id).data
|
127
|
-
target_2.destroy
|
128
|
-
assert_set_equal [target_1.id, target_3.id], bucket.get(object.id).data
|
129
|
-
|
130
|
-
target_1.destroy
|
131
|
-
target_3.destroy
|
132
|
-
assert_set_equal [], bucket.get(object.id).data
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def association
|
137
|
-
Tenacity::Association.new(:t_has_many, :ripple_has_many_targets, RippleObject)
|
138
151
|
end
|
139
152
|
end
|
140
153
|
end
|