mongo_mapper-unstable 2010.2.28 → 2010.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/lib/mongo_mapper/document.rb +3 -72
- data/lib/mongo_mapper/plugins/callbacks.rb +14 -3
- data/lib/mongo_mapper/plugins/keys.rb +9 -4
- data/lib/mongo_mapper/plugins/modifiers.rb +87 -0
- data/lib/mongo_mapper/plugins/rails.rb +16 -8
- data/lib/mongo_mapper/plugins/serialization.rb +51 -81
- data/lib/mongo_mapper/plugins/timestamps.rb +21 -0
- data/lib/mongo_mapper/plugins/userstamps.rb +14 -0
- data/lib/mongo_mapper/plugins.rb +3 -0
- data/lib/mongo_mapper.rb +2 -2
- data/test/active_model_lint_test.rb +11 -0
- data/test/functional/test_document.rb +0 -116
- data/test/functional/test_embedded_document.rb +17 -12
- data/test/functional/test_indexing.rb +44 -0
- data/test/functional/test_modifiers.rb +297 -227
- data/test/functional/test_timestamps.rb +64 -0
- data/test/functional/test_userstamps.rb +28 -0
- data/test/support/timing.rb +1 -1
- data/test/test_helper.rb +0 -4
- data/test/unit/serializers/test_json_serializer.rb +30 -17
- data/test/unit/test_serialization.rb +3 -3
- metadata +80 -35
@@ -10,243 +10,313 @@ class ModifierTest < Test::Unit::TestCase
|
|
10
10
|
key :tags, Array
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def assert_page_counts(page, day_count, week_count, month_count)
|
15
15
|
page.reload
|
16
16
|
page.day_count.should == day_count
|
17
17
|
page.week_count.should == week_count
|
18
18
|
page.month_count.should == month_count
|
19
19
|
end
|
20
|
-
|
21
|
-
should "be able to increment with criteria and modifier hashes" do
|
22
|
-
page = @page_class.create(:title => 'Home')
|
23
|
-
page2 = @page_class.create(:title => 'Home')
|
24
|
-
|
25
|
-
@page_class.increment({:title => 'Home'}, {
|
26
|
-
:day_count => 1, :week_count => 2, :month_count => 3
|
27
|
-
})
|
28
|
-
|
29
|
-
assert_page_counts page, 1, 2, 3
|
30
|
-
assert_page_counts page2, 1, 2, 3
|
31
|
-
end
|
32
|
-
|
33
|
-
should "be able to increment with ids and modifier hash" do
|
34
|
-
page = @page_class.create(:title => 'Home')
|
35
|
-
page2 = @page_class.create(:title => 'Home')
|
36
|
-
|
37
|
-
@page_class.increment(page.id, page2.id, {
|
38
|
-
:day_count => 1, :week_count => 2, :month_count => 3
|
39
|
-
})
|
40
|
-
|
41
|
-
assert_page_counts page, 1, 2, 3
|
42
|
-
assert_page_counts page2, 1, 2, 3
|
43
|
-
end
|
44
|
-
|
45
|
-
should "be able to decrement with criteria and modifier hashes" do
|
46
|
-
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
47
|
-
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
48
|
-
|
49
|
-
@page_class.decrement({:title => 'Home'}, {
|
50
|
-
:day_count => 1, :week_count => 2, :month_count => 3
|
51
|
-
})
|
52
|
-
|
53
|
-
assert_page_counts page, 0, 0, 0
|
54
|
-
assert_page_counts page2, 0, 0, 0
|
55
|
-
end
|
56
|
-
|
57
|
-
should "be able to decrement with ids and modifier hash" do
|
58
|
-
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
59
|
-
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
60
|
-
|
61
|
-
@page_class.decrement(page.id, page2.id, {
|
62
|
-
:day_count => 1, :week_count => 2, :month_count => 3
|
63
|
-
})
|
64
|
-
|
65
|
-
assert_page_counts page, 0, 0, 0
|
66
|
-
assert_page_counts page2, 0, 0, 0
|
67
|
-
end
|
68
|
-
|
69
|
-
should "always decrement when decrement is called whether number is positive or negative" do
|
70
|
-
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
71
|
-
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
72
|
-
|
73
|
-
@page_class.decrement(page.id, page2.id, {
|
74
|
-
:day_count => -1, :week_count => 2, :month_count => -3
|
75
|
-
})
|
76
|
-
|
77
|
-
assert_page_counts page, 0, 0, 0
|
78
|
-
assert_page_counts page2, 0, 0, 0
|
79
|
-
end
|
80
|
-
|
81
|
-
should "be able to set with criteria and modifier hashes" do
|
82
|
-
page = @page_class.create(:title => 'Home')
|
83
|
-
page2 = @page_class.create(:title => 'Home')
|
84
|
-
|
85
|
-
@page_class.set({:title => 'Home'}, :title => 'Home Revised')
|
86
|
-
|
87
|
-
page.reload
|
88
|
-
page.title.should == 'Home Revised'
|
89
|
-
|
90
|
-
page2.reload
|
91
|
-
page2.title.should == 'Home Revised'
|
92
|
-
end
|
93
|
-
|
94
|
-
should "be able to set with ids and modifier hash" do
|
95
|
-
page = @page_class.create(:title => 'Home')
|
96
|
-
page2 = @page_class.create(:title => 'Home')
|
97
|
-
|
98
|
-
@page_class.set(page.id, page2.id, :title => 'Home Revised')
|
99
|
-
|
100
|
-
page.reload
|
101
|
-
page.title.should == 'Home Revised'
|
102
|
-
|
103
|
-
page2.reload
|
104
|
-
page2.title.should == 'Home Revised'
|
105
|
-
end
|
106
|
-
|
107
|
-
should "be able to push with criteria and modifier hashes" do
|
108
|
-
page = @page_class.create(:title => 'Home')
|
109
|
-
page2 = @page_class.create(:title => 'Home')
|
110
|
-
|
111
|
-
@page_class.push({:title => 'Home'}, :tags => 'foo')
|
112
|
-
|
113
|
-
page.reload
|
114
|
-
page.tags.should == %w(foo)
|
115
|
-
|
116
|
-
page2.reload
|
117
|
-
page.tags.should == %w(foo)
|
118
|
-
end
|
119
|
-
|
120
|
-
should "be able to push with ids and modifier hash" do
|
121
|
-
page = @page_class.create(:title => 'Home')
|
122
|
-
page2 = @page_class.create(:title => 'Home')
|
123
|
-
|
124
|
-
@page_class.push(page.id, page2.id, :tags => 'foo')
|
125
|
-
|
126
|
-
page.reload
|
127
|
-
page.tags.should == %w(foo)
|
128
|
-
|
129
|
-
page2.reload
|
130
|
-
page.tags.should == %w(foo)
|
131
|
-
end
|
132
20
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
@page_class.push_all({:title => 'Home'}, :tags => tags)
|
139
|
-
|
140
|
-
page.reload
|
141
|
-
page.tags.should == tags
|
142
|
-
|
143
|
-
page2.reload
|
144
|
-
page.tags.should == tags
|
145
|
-
end
|
146
|
-
|
147
|
-
should "be able to push all with ids and modifier hash" do
|
148
|
-
page = @page_class.create(:title => 'Home')
|
149
|
-
page2 = @page_class.create(:title => 'Home')
|
150
|
-
tags = %w(foo bar)
|
151
|
-
|
152
|
-
@page_class.push_all(page.id, page2.id, :tags => tags)
|
153
|
-
|
154
|
-
page.reload
|
155
|
-
page.tags.should == tags
|
156
|
-
|
157
|
-
page2.reload
|
158
|
-
page.tags.should == tags
|
159
|
-
end
|
160
|
-
|
161
|
-
should "be able to pull with criteria and modifier hashes" do
|
162
|
-
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
163
|
-
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
164
|
-
|
165
|
-
@page_class.pull({:title => 'Home'}, :tags => 'foo')
|
166
|
-
|
167
|
-
page.reload
|
168
|
-
page.tags.should == %w(bar)
|
169
|
-
|
170
|
-
page2.reload
|
171
|
-
page.tags.should == %w(bar)
|
172
|
-
end
|
173
|
-
|
174
|
-
should "be able to pull with ids and modifier hash" do
|
175
|
-
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
176
|
-
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
177
|
-
|
178
|
-
@page_class.pull(page.id, page2.id, :tags => 'foo')
|
179
|
-
|
180
|
-
page.reload
|
181
|
-
page.tags.should == %w(bar)
|
182
|
-
|
183
|
-
page2.reload
|
184
|
-
page.tags.should == %w(bar)
|
185
|
-
end
|
21
|
+
context "using class methods" do
|
22
|
+
should "be able to increment with criteria and modifier hashes" do
|
23
|
+
page = @page_class.create(:title => 'Home')
|
24
|
+
page2 = @page_class.create(:title => 'Home')
|
186
25
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
|
192
|
-
|
193
|
-
page.reload
|
194
|
-
page.tags.should == %w(baz)
|
195
|
-
|
196
|
-
page2.reload
|
197
|
-
page.tags.should == %w(baz)
|
198
|
-
end
|
199
|
-
|
200
|
-
should "be able to pull all with ids and modifier hash" do
|
201
|
-
page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
202
|
-
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
203
|
-
|
204
|
-
@page_class.pull_all(page.id, page2.id, :tags => %w(foo bar))
|
205
|
-
|
206
|
-
page.reload
|
207
|
-
page.tags.should == %w(baz)
|
208
|
-
|
209
|
-
page2.reload
|
210
|
-
page.tags.should == %w(baz)
|
211
|
-
end
|
26
|
+
@page_class.increment({:title => 'Home'}, {
|
27
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
28
|
+
})
|
212
29
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
30
|
+
assert_page_counts page, 1, 2, 3
|
31
|
+
assert_page_counts page2, 1, 2, 3
|
32
|
+
end
|
33
|
+
|
34
|
+
should "be able to increment with ids and modifier hash" do
|
35
|
+
page = @page_class.create(:title => 'Home')
|
36
|
+
page2 = @page_class.create(:title => 'Home')
|
37
|
+
|
38
|
+
@page_class.increment(page.id, page2.id, {
|
39
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
40
|
+
})
|
41
|
+
|
42
|
+
assert_page_counts page, 1, 2, 3
|
43
|
+
assert_page_counts page2, 1, 2, 3
|
44
|
+
end
|
45
|
+
|
46
|
+
should "be able to decrement with criteria and modifier hashes" do
|
47
|
+
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
48
|
+
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
49
|
+
|
50
|
+
@page_class.decrement({:title => 'Home'}, {
|
51
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
52
|
+
})
|
53
|
+
|
54
|
+
assert_page_counts page, 0, 0, 0
|
55
|
+
assert_page_counts page2, 0, 0, 0
|
56
|
+
end
|
57
|
+
|
58
|
+
should "be able to decrement with ids and modifier hash" do
|
59
|
+
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
60
|
+
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
61
|
+
|
62
|
+
@page_class.decrement(page.id, page2.id, {
|
63
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
64
|
+
})
|
65
|
+
|
66
|
+
assert_page_counts page, 0, 0, 0
|
67
|
+
assert_page_counts page2, 0, 0, 0
|
68
|
+
end
|
69
|
+
|
70
|
+
should "always decrement when decrement is called whether number is positive or negative" do
|
71
|
+
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
72
|
+
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
73
|
+
|
74
|
+
@page_class.decrement(page.id, page2.id, {
|
75
|
+
:day_count => -1, :week_count => 2, :month_count => -3
|
76
|
+
})
|
77
|
+
|
78
|
+
assert_page_counts page, 0, 0, 0
|
79
|
+
assert_page_counts page2, 0, 0, 0
|
80
|
+
end
|
81
|
+
|
82
|
+
should "be able to set with criteria and modifier hashes" do
|
83
|
+
page = @page_class.create(:title => 'Home')
|
84
|
+
page2 = @page_class.create(:title => 'Home')
|
85
|
+
|
86
|
+
@page_class.set({:title => 'Home'}, :title => 'Home Revised')
|
87
|
+
|
88
|
+
page.reload
|
89
|
+
page.title.should == 'Home Revised'
|
90
|
+
|
91
|
+
page2.reload
|
92
|
+
page2.title.should == 'Home Revised'
|
93
|
+
end
|
94
|
+
|
95
|
+
should "be able to set with ids and modifier hash" do
|
96
|
+
page = @page_class.create(:title => 'Home')
|
97
|
+
page2 = @page_class.create(:title => 'Home')
|
98
|
+
|
99
|
+
@page_class.set(page.id, page2.id, :title => 'Home Revised')
|
100
|
+
|
101
|
+
page.reload
|
102
|
+
page.title.should == 'Home Revised'
|
103
|
+
|
104
|
+
page2.reload
|
105
|
+
page2.title.should == 'Home Revised'
|
106
|
+
end
|
107
|
+
|
108
|
+
should "be able to push with criteria and modifier hashes" do
|
109
|
+
page = @page_class.create(:title => 'Home')
|
110
|
+
page2 = @page_class.create(:title => 'Home')
|
111
|
+
|
112
|
+
@page_class.push({:title => 'Home'}, :tags => 'foo')
|
113
|
+
|
114
|
+
page.reload
|
115
|
+
page.tags.should == %w(foo)
|
116
|
+
|
117
|
+
page2.reload
|
118
|
+
page.tags.should == %w(foo)
|
119
|
+
end
|
120
|
+
|
121
|
+
should "be able to push with ids and modifier hash" do
|
122
|
+
page = @page_class.create(:title => 'Home')
|
123
|
+
page2 = @page_class.create(:title => 'Home')
|
124
|
+
|
125
|
+
@page_class.push(page.id, page2.id, :tags => 'foo')
|
126
|
+
|
127
|
+
page.reload
|
128
|
+
page.tags.should == %w(foo)
|
129
|
+
|
130
|
+
page2.reload
|
131
|
+
page.tags.should == %w(foo)
|
132
|
+
end
|
133
|
+
|
134
|
+
should "be able to push all with criteria and modifier hashes" do
|
135
|
+
page = @page_class.create(:title => 'Home')
|
136
|
+
page2 = @page_class.create(:title => 'Home')
|
137
|
+
tags = %w(foo bar)
|
138
|
+
|
139
|
+
@page_class.push_all({:title => 'Home'}, :tags => tags)
|
140
|
+
|
141
|
+
page.reload
|
142
|
+
page.tags.should == tags
|
143
|
+
|
144
|
+
page2.reload
|
145
|
+
page.tags.should == tags
|
146
|
+
end
|
147
|
+
|
148
|
+
should "be able to push all with ids and modifier hash" do
|
149
|
+
page = @page_class.create(:title => 'Home')
|
150
|
+
page2 = @page_class.create(:title => 'Home')
|
151
|
+
tags = %w(foo bar)
|
152
|
+
|
153
|
+
@page_class.push_all(page.id, page2.id, :tags => tags)
|
154
|
+
|
155
|
+
page.reload
|
156
|
+
page.tags.should == tags
|
157
|
+
|
158
|
+
page2.reload
|
159
|
+
page.tags.should == tags
|
160
|
+
end
|
161
|
+
|
162
|
+
should "be able to pull with criteria and modifier hashes" do
|
163
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
164
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
165
|
+
|
166
|
+
@page_class.pull({:title => 'Home'}, :tags => 'foo')
|
167
|
+
|
168
|
+
page.reload
|
169
|
+
page.tags.should == %w(bar)
|
170
|
+
|
171
|
+
page2.reload
|
172
|
+
page.tags.should == %w(bar)
|
173
|
+
end
|
174
|
+
|
175
|
+
should "be able to pull with ids and modifier hash" do
|
176
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
177
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
178
|
+
|
179
|
+
@page_class.pull(page.id, page2.id, :tags => 'foo')
|
180
|
+
|
181
|
+
page.reload
|
182
|
+
page.tags.should == %w(bar)
|
183
|
+
|
184
|
+
page2.reload
|
185
|
+
page.tags.should == %w(bar)
|
186
|
+
end
|
187
|
+
|
188
|
+
should "be able to pull all with criteria and modifier hashes" do
|
189
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
190
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
191
|
+
|
192
|
+
@page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
|
193
|
+
|
194
|
+
page.reload
|
195
|
+
page.tags.should == %w(baz)
|
196
|
+
|
197
|
+
page2.reload
|
198
|
+
page.tags.should == %w(baz)
|
199
|
+
end
|
200
|
+
|
201
|
+
should "be able to pull all with ids and modifier hash" do
|
202
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
203
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
204
|
+
|
205
|
+
@page_class.pull_all(page.id, page2.id, :tags => %w(foo bar))
|
206
|
+
|
207
|
+
page.reload
|
208
|
+
page.tags.should == %w(baz)
|
209
|
+
|
210
|
+
page2.reload
|
211
|
+
page.tags.should == %w(baz)
|
212
|
+
end
|
213
|
+
|
214
|
+
should "be able to push uniq with criteria and modifier hash" do
|
215
|
+
page = @page_class.create(:title => 'Home', :tags => 'foo')
|
216
|
+
page2 = @page_class.create(:title => 'Home')
|
217
|
+
|
218
|
+
@page_class.push_uniq({:title => 'Home'}, :tags => 'foo')
|
219
|
+
|
220
|
+
page.reload
|
221
|
+
page.tags.should == %w(foo)
|
222
|
+
|
223
|
+
page2.reload
|
224
|
+
page.tags.should == %w(foo)
|
225
|
+
end
|
226
|
+
|
227
|
+
should "be able to push uniq with ids and modifier hash" do
|
228
|
+
page = @page_class.create(:title => 'Home', :tags => 'foo')
|
229
|
+
page2 = @page_class.create(:title => 'Home')
|
230
|
+
|
231
|
+
@page_class.push_uniq(page.id, page2.id, :tags => 'foo')
|
232
|
+
|
233
|
+
page.reload
|
234
|
+
page.tags.should == %w(foo)
|
235
|
+
|
236
|
+
page2.reload
|
237
|
+
page.tags.should == %w(foo)
|
238
|
+
end
|
239
|
+
|
240
|
+
should "be able to remove the last element the array" do
|
241
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
242
|
+
@page_class.pop(page.id, :tags => 1)
|
243
|
+
page.reload
|
244
|
+
page.tags.should == %w(foo)
|
245
|
+
end
|
246
|
+
|
247
|
+
should "be able to remove the first element of the array" do
|
248
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
249
|
+
@page_class.pop(page.id, :tags => -1)
|
250
|
+
page.reload
|
251
|
+
page.tags.should == %w(bar)
|
252
|
+
end
|
244
253
|
end
|
245
254
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
255
|
+
context "using instance methods" do
|
256
|
+
should "be able to increment with modifier hashes" do
|
257
|
+
page = @page_class.create
|
258
|
+
|
259
|
+
page.increment({:day_count => 1, :week_count => 2, :month_count => 3})
|
260
|
+
|
261
|
+
assert_page_counts page, 1, 2, 3
|
262
|
+
end
|
263
|
+
|
264
|
+
should "be able to decrement with modifier hashes" do
|
265
|
+
page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
|
266
|
+
|
267
|
+
page.decrement({:day_count => 1, :week_count => 2, :month_count => 3})
|
268
|
+
|
269
|
+
assert_page_counts page, 0, 0, 0
|
270
|
+
end
|
271
|
+
|
272
|
+
should "always decrement when decrement is called whether number is positive or negative" do
|
273
|
+
page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
|
274
|
+
|
275
|
+
page.decrement({:day_count => -1, :week_count => 2, :month_count => -3})
|
276
|
+
|
277
|
+
assert_page_counts page, 0, 0, 0
|
278
|
+
end
|
279
|
+
|
280
|
+
should "be able to set with modifier hashes" do
|
281
|
+
page = @page_class.create(:title => 'Home')
|
282
|
+
|
283
|
+
page.set(:title => 'Home Revised')
|
284
|
+
|
285
|
+
page.reload
|
286
|
+
page.title.should == 'Home Revised'
|
287
|
+
end
|
288
|
+
|
289
|
+
should "be able to push with modifier hashes" do
|
290
|
+
page = @page_class.create
|
291
|
+
|
292
|
+
page.push(:tags => 'foo')
|
293
|
+
|
294
|
+
page.reload
|
295
|
+
page.tags.should == %w(foo)
|
296
|
+
end
|
297
|
+
|
298
|
+
should "be able to pull with criteria and modifier hashes" do
|
299
|
+
page = @page_class.create(:tags => %w(foo bar))
|
300
|
+
|
301
|
+
page.pull(:tags => 'foo')
|
302
|
+
|
303
|
+
page.reload
|
304
|
+
page.tags.should == %w(bar)
|
305
|
+
end
|
306
|
+
|
307
|
+
should "be able to push uniq with criteria and modifier hash" do
|
308
|
+
page = @page_class.create(:tags => 'foo')
|
309
|
+
page2 = @page_class.create
|
310
|
+
|
311
|
+
page.push_uniq(:tags => 'foo')
|
312
|
+
page.push_uniq(:tags => 'foo')
|
313
|
+
|
314
|
+
page.reload
|
315
|
+
page.tags.should == %w(foo)
|
316
|
+
|
317
|
+
page2.reload
|
318
|
+
page.tags.should == %w(foo)
|
319
|
+
end
|
251
320
|
end
|
321
|
+
|
252
322
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TimestampsTest < Test::Unit::TestCase
|
4
|
+
context "timestamping" do
|
5
|
+
setup do
|
6
|
+
@klass = Doc do
|
7
|
+
set_collection_name 'users'
|
8
|
+
|
9
|
+
key :first_name, String
|
10
|
+
key :last_name, String
|
11
|
+
key :age, Integer
|
12
|
+
key :date, Date
|
13
|
+
end
|
14
|
+
@klass.timestamps!
|
15
|
+
end
|
16
|
+
|
17
|
+
should "set created_at and updated_at on create" do
|
18
|
+
doc = @klass.new(:first_name => 'John', :age => 27)
|
19
|
+
doc.created_at.should be(nil)
|
20
|
+
doc.updated_at.should be(nil)
|
21
|
+
doc.save
|
22
|
+
doc.created_at.should_not be(nil)
|
23
|
+
doc.updated_at.should_not be(nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "not overwrite created_at if it already exists" do
|
27
|
+
original_created_at = 1.month.ago
|
28
|
+
doc = @klass.new(:first_name => 'John', :age => 27, :created_at => original_created_at)
|
29
|
+
doc.created_at.to_i.should == original_created_at.to_i
|
30
|
+
doc.updated_at.should be_nil
|
31
|
+
doc.save
|
32
|
+
doc.created_at.to_i.should == original_created_at.to_i
|
33
|
+
doc.updated_at.should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
should "set updated_at on field update but leave created_at alone" do
|
37
|
+
doc = @klass.create(:first_name => 'John', :age => 27)
|
38
|
+
old_created_at = doc.created_at
|
39
|
+
old_updated_at = doc.updated_at
|
40
|
+
doc.first_name = 'Johnny'
|
41
|
+
|
42
|
+
Timecop.freeze(Time.now + 5.seconds) do
|
43
|
+
doc.save
|
44
|
+
end
|
45
|
+
|
46
|
+
doc.created_at.should == old_created_at
|
47
|
+
doc.updated_at.should_not == old_updated_at
|
48
|
+
end
|
49
|
+
|
50
|
+
should "set updated_at on document update but leave created_at alone" do
|
51
|
+
doc = @klass.create(:first_name => 'John', :age => 27)
|
52
|
+
old_created_at = doc.created_at
|
53
|
+
old_updated_at = doc.updated_at
|
54
|
+
|
55
|
+
Timecop.freeze(Time.now + 5.seconds) do
|
56
|
+
@klass.update(doc._id, { :first_name => 'Johnny' })
|
57
|
+
end
|
58
|
+
|
59
|
+
doc = doc.reload
|
60
|
+
doc.created_at.should == old_created_at
|
61
|
+
doc.updated_at.should_not == old_updated_at
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UserstampsTest < Test::Unit::TestCase
|
4
|
+
context "userstamping" do
|
5
|
+
setup do
|
6
|
+
@document = Doc do
|
7
|
+
set_collection_name 'users'
|
8
|
+
userstamps!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
should "add creator_id key" do
|
13
|
+
@document.keys.keys.should include('creator_id')
|
14
|
+
end
|
15
|
+
|
16
|
+
should "add updater_id key" do
|
17
|
+
@document.keys.keys.should include('updater_id')
|
18
|
+
end
|
19
|
+
|
20
|
+
should "add belongs_to creator" do
|
21
|
+
@document.associations.keys.should include('creator')
|
22
|
+
end
|
23
|
+
|
24
|
+
should "add belongs_to updater" do
|
25
|
+
@document.associations.keys.should include('updater')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/support/timing.rb
CHANGED