mongo_mapper-unstable 2010.3.8 → 2010.06.23
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/README.rdoc +4 -8
- data/bin/mmconsole +1 -1
- data/examples/keys.rb +37 -0
- data/examples/plugins.rb +41 -0
- data/examples/querying.rb +35 -0
- data/examples/scopes.rb +52 -0
- data/lib/mongo_mapper/connection.rb +83 -0
- data/lib/mongo_mapper/document.rb +11 -329
- data/lib/mongo_mapper/embedded_document.rb +9 -38
- data/lib/mongo_mapper/exceptions.rb +30 -0
- data/lib/mongo_mapper/extensions/array.rb +19 -0
- data/lib/mongo_mapper/extensions/binary.rb +22 -0
- data/lib/mongo_mapper/extensions/boolean.rb +44 -0
- data/lib/mongo_mapper/extensions/date.rb +25 -0
- data/lib/mongo_mapper/extensions/float.rb +14 -0
- data/lib/mongo_mapper/extensions/hash.rb +14 -0
- data/lib/mongo_mapper/extensions/integer.rb +19 -0
- data/lib/mongo_mapper/extensions/kernel.rb +9 -0
- data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
- data/lib/mongo_mapper/extensions/object.rb +27 -0
- data/lib/mongo_mapper/extensions/object_id.rb +30 -0
- data/lib/mongo_mapper/extensions/set.rb +20 -0
- data/lib/mongo_mapper/extensions/string.rb +18 -0
- data/lib/mongo_mapper/extensions/time.rb +29 -0
- data/lib/mongo_mapper/plugins/accessible.rb +44 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +5 -6
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +5 -6
- data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +25 -39
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +36 -46
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +5 -4
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
- data/lib/mongo_mapper/plugins/associations/proxy.rb +16 -8
- data/lib/mongo_mapper/plugins/associations.rb +14 -22
- data/lib/mongo_mapper/plugins/caching.rb +21 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +17 -5
- data/lib/mongo_mapper/plugins/clone.rb +10 -4
- data/lib/mongo_mapper/plugins/descendants.rb +3 -2
- data/lib/mongo_mapper/plugins/dirty.rb +1 -0
- data/lib/mongo_mapper/plugins/document.rb +41 -0
- data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +3 -36
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
- data/lib/mongo_mapper/plugins/embedded_document.rb +49 -0
- data/lib/mongo_mapper/plugins/equality.rb +4 -10
- data/lib/mongo_mapper/plugins/identity_map.rb +29 -23
- data/lib/mongo_mapper/plugins/indexes.rb +12 -0
- data/lib/mongo_mapper/plugins/inspect.rb +1 -0
- data/lib/mongo_mapper/plugins/keys/key.rb +55 -0
- data/lib/mongo_mapper/plugins/keys.rb +85 -110
- data/lib/mongo_mapper/plugins/logger.rb +1 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +41 -16
- data/lib/mongo_mapper/plugins/pagination.rb +5 -15
- data/lib/mongo_mapper/plugins/persistence.rb +69 -0
- data/lib/mongo_mapper/plugins/protected.rb +9 -1
- data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
- data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
- data/lib/mongo_mapper/plugins/querying.rb +176 -0
- data/lib/mongo_mapper/plugins/rails.rb +6 -1
- data/lib/mongo_mapper/plugins/safe.rb +28 -0
- data/lib/mongo_mapper/plugins/sci.rb +32 -0
- data/lib/mongo_mapper/plugins/scopes.rb +21 -0
- data/lib/mongo_mapper/plugins/serialization.rb +5 -4
- data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
- data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +9 -5
- data/lib/mongo_mapper/plugins.rb +1 -20
- data/lib/mongo_mapper/support/descendant_appends.rb +5 -6
- data/lib/mongo_mapper/version.rb +4 -0
- data/lib/mongo_mapper.rb +71 -128
- data/test/{NOTE_ON_TESTING → _NOTE_ON_TESTING} +0 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +5 -5
- data/test/functional/associations/test_belongs_to_proxy.rb +13 -21
- data/test/functional/associations/test_in_array_proxy.rb +7 -9
- data/test/functional/associations/test_many_documents_as_proxy.rb +5 -5
- data/test/functional/associations/test_many_documents_proxy.rb +186 -64
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +22 -22
- data/test/functional/associations/test_many_embedded_proxy.rb +32 -32
- data/test/functional/associations/test_many_polymorphic_proxy.rb +47 -47
- data/test/functional/associations/test_one_embedded_proxy.rb +67 -0
- data/test/functional/associations/test_one_proxy.rb +70 -49
- data/test/functional/test_accessible.rb +168 -0
- data/test/functional/test_associations.rb +11 -11
- data/test/functional/test_binary.rb +5 -5
- data/test/functional/test_caching.rb +76 -0
- data/test/functional/test_callbacks.rb +104 -34
- data/test/functional/test_dirty.rb +16 -16
- data/test/functional/test_document.rb +12 -924
- data/test/functional/test_dynamic_querying.rb +75 -0
- data/test/functional/test_embedded_document.rb +88 -8
- data/test/functional/test_identity_map.rb +41 -43
- data/test/functional/{test_indexing.rb → test_indexes.rb} +3 -5
- data/test/functional/test_logger.rb +1 -1
- data/test/functional/test_modifiers.rb +275 -181
- data/test/functional/test_pagination.rb +13 -15
- data/test/functional/test_protected.rb +25 -11
- data/test/functional/test_querying.rb +873 -0
- data/test/functional/test_safe.rb +76 -0
- data/test/functional/test_sci.rb +230 -0
- data/test/functional/test_scopes.rb +171 -0
- data/test/functional/test_string_id_compatibility.rb +11 -11
- data/test/functional/test_timestamps.rb +0 -2
- data/test/functional/test_userstamps.rb +0 -1
- data/test/functional/test_validations.rb +44 -31
- data/test/models.rb +18 -17
- data/test/{active_model_lint_test.rb → test_active_model_lint.rb} +3 -1
- data/test/test_helper.rb +59 -16
- data/test/unit/associations/test_base.rb +47 -42
- data/test/unit/associations/test_proxy.rb +15 -15
- data/test/unit/serializers/test_json_serializer.rb +29 -29
- data/test/unit/test_clone.rb +69 -0
- data/test/unit/test_descendant_appends.rb +3 -3
- data/test/unit/test_document.rb +49 -67
- data/test/unit/test_dynamic_finder.rb +53 -51
- data/test/unit/test_embedded_document.rb +19 -38
- data/test/unit/{test_support.rb → test_extensions.rb} +136 -122
- data/test/unit/test_key.rb +185 -0
- data/test/unit/test_keys.rb +29 -147
- data/test/unit/test_mongo_mapper.rb +3 -48
- data/test/unit/test_pagination.rb +1 -150
- data/test/unit/test_rails.rb +77 -19
- data/test/unit/test_rails_compatibility.rb +12 -12
- data/test/unit/test_serialization.rb +5 -5
- data/test/unit/test_time_zones.rb +9 -9
- data/test/unit/test_validations.rb +46 -46
- metadata +157 -155
- data/.gitignore +0 -10
- data/Rakefile +0 -55
- data/VERSION +0 -1
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
- data/lib/mongo_mapper/query.rb +0 -130
- data/lib/mongo_mapper/support.rb +0 -215
- data/mongo_mapper.gemspec +0 -196
- data/performance/read_write.rb +0 -52
- data/specs.watchr +0 -51
- data/test/support/custom_matchers.rb +0 -55
- data/test/support/timing.rb +0 -16
- data/test/unit/test_query.rb +0 -340
@@ -3,11 +3,11 @@ require 'test_helper'
|
|
3
3
|
class ModifierTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@page_class = Doc do
|
6
|
-
key :title,
|
7
|
-
key :day_count,
|
8
|
-
key :week_count,
|
6
|
+
key :title, String
|
7
|
+
key :day_count, Integer, :default => 0
|
8
|
+
key :week_count, Integer, :default => 0
|
9
9
|
key :month_count, Integer, :default => 0
|
10
|
-
key :tags,
|
10
|
+
key :tags, Array
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -18,268 +18,343 @@ class ModifierTest < Test::Unit::TestCase
|
|
18
18
|
page.month_count.should == month_count
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
:day_count => 1, :week_count => 2, :month_count => 3
|
28
|
-
})
|
21
|
+
def assert_keys_removed(page, *keys)
|
22
|
+
keys.each do |key|
|
23
|
+
doc = @page_class.collection.find_one({:_id => page.id})
|
24
|
+
doc.keys.should_not include(key)
|
25
|
+
end
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
28
|
+
context "ClassMethods" do
|
29
|
+
context "unset" do
|
30
|
+
setup do
|
31
|
+
@page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
32
|
+
@page2 = @page_class.create(:title => 'Home')
|
33
|
+
end
|
34
|
+
|
35
|
+
should "work with criteria and keys" do
|
36
|
+
@page_class.unset({:title => 'Home'}, :title, :tags)
|
37
|
+
assert_keys_removed @page, :title, :tags
|
38
|
+
assert_keys_removed @page2, :title, :tags
|
39
|
+
end
|
40
|
+
|
41
|
+
should "work with ids and keys" do
|
42
|
+
@page_class.unset(@page.id, @page2.id, :title, :tags)
|
43
|
+
assert_keys_removed @page, :title, :tags
|
44
|
+
assert_keys_removed @page2, :title, :tags
|
45
|
+
end
|
32
46
|
end
|
33
47
|
|
34
|
-
|
35
|
-
|
36
|
-
|
48
|
+
context "increment" do
|
49
|
+
setup do
|
50
|
+
@page = @page_class.create(:title => 'Home')
|
51
|
+
@page2 = @page_class.create(:title => 'Home')
|
52
|
+
end
|
37
53
|
|
38
|
-
|
39
|
-
:day_count => 1, :week_count => 2, :month_count => 3
|
40
|
-
})
|
54
|
+
should "work with criteria and modifier hashes" do
|
55
|
+
@page_class.increment({:title => 'Home'}, :day_count => 1, :week_count => 2, :month_count => 3)
|
41
56
|
|
42
|
-
|
43
|
-
|
44
|
-
|
57
|
+
assert_page_counts @page, 1, 2, 3
|
58
|
+
assert_page_counts @page2, 1, 2, 3
|
59
|
+
end
|
45
60
|
|
46
|
-
|
47
|
-
|
48
|
-
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
61
|
+
should "work with ids and modifier hash" do
|
62
|
+
@page_class.increment(@page.id, @page2.id, :day_count => 1, :week_count => 2, :month_count => 3)
|
49
63
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
assert_page_counts page, 0, 0, 0
|
55
|
-
assert_page_counts page2, 0, 0, 0
|
64
|
+
assert_page_counts @page, 1, 2, 3
|
65
|
+
assert_page_counts @page2, 1, 2, 3
|
66
|
+
end
|
56
67
|
end
|
57
68
|
|
58
|
-
|
59
|
-
|
60
|
-
|
69
|
+
context "decrement" do
|
70
|
+
setup 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
|
+
end
|
61
74
|
|
62
|
-
|
63
|
-
:day_count => 1, :week_count => 2, :month_count => 3
|
64
|
-
})
|
75
|
+
should "work with criteria and modifier hashes" do
|
76
|
+
@page_class.decrement({:title => 'Home'}, :day_count => 1, :week_count => 2, :month_count => 3)
|
65
77
|
|
66
|
-
|
67
|
-
|
68
|
-
|
78
|
+
assert_page_counts @page, 0, 0, 0
|
79
|
+
assert_page_counts @page2, 0, 0, 0
|
80
|
+
end
|
69
81
|
|
70
|
-
|
71
|
-
|
72
|
-
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
82
|
+
should "work with ids and modifier hash" do
|
83
|
+
@page_class.decrement(@page.id, @page2.id, :day_count => 1, :week_count => 2, :month_count => 3)
|
73
84
|
|
74
|
-
|
75
|
-
|
76
|
-
|
85
|
+
assert_page_counts @page, 0, 0, 0
|
86
|
+
assert_page_counts @page2, 0, 0, 0
|
87
|
+
end
|
77
88
|
|
78
|
-
|
79
|
-
|
89
|
+
should "decrement with positive or negative numbers" do
|
90
|
+
@page_class.decrement(@page.id, @page2.id, :day_count => -1, :week_count => 2, :month_count => -3)
|
91
|
+
|
92
|
+
assert_page_counts @page, 0, 0, 0
|
93
|
+
assert_page_counts @page2, 0, 0, 0
|
94
|
+
end
|
80
95
|
end
|
81
96
|
|
82
|
-
|
83
|
-
|
84
|
-
|
97
|
+
context "set" do
|
98
|
+
setup do
|
99
|
+
@page = @page_class.create(:title => 'Home')
|
100
|
+
@page2 = @page_class.create(:title => 'Home')
|
101
|
+
end
|
102
|
+
|
103
|
+
should "work with criteria and modifier hashes" do
|
104
|
+
@page_class.set({:title => 'Home'}, :title => 'Home Revised')
|
105
|
+
|
106
|
+
@page.reload
|
107
|
+
@page.title.should == 'Home Revised'
|
108
|
+
|
109
|
+
@page2.reload
|
110
|
+
@page2.title.should == 'Home Revised'
|
111
|
+
end
|
112
|
+
|
113
|
+
should "work with ids and modifier hash" do
|
114
|
+
@page_class.set(@page.id, @page2.id, :title => 'Home Revised')
|
115
|
+
|
116
|
+
@page.reload
|
117
|
+
@page.title.should == 'Home Revised'
|
118
|
+
|
119
|
+
@page2.reload
|
120
|
+
@page2.title.should == 'Home Revised'
|
121
|
+
end
|
122
|
+
|
123
|
+
should "typecast values before querying" do
|
124
|
+
@page_class.key :tags, Set
|
125
|
+
|
126
|
+
assert_nothing_raised do
|
127
|
+
@page_class.set(@page.id, :tags => ['foo', 'bar'].to_set)
|
128
|
+
@page.reload
|
129
|
+
@page.tags.should == Set.new(['foo', 'bar'])
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
should "not typecast keys that are not defined in document" do
|
134
|
+
assert_raises(BSON::InvalidDocument) do
|
135
|
+
@page_class.set(@page.id, :colors => ['red', 'green'].to_set)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
should "set keys that are not defined in document" do
|
140
|
+
@page_class.set(@page.id, :colors => %w[red green])
|
141
|
+
@page.reload
|
142
|
+
@page[:colors].should == %w[red green]
|
143
|
+
end
|
144
|
+
end
|
85
145
|
|
86
|
-
|
146
|
+
context "push" do
|
147
|
+
setup do
|
148
|
+
@page = @page_class.create(:title => 'Home')
|
149
|
+
@page2 = @page_class.create(:title => 'Home')
|
150
|
+
end
|
87
151
|
|
88
|
-
|
89
|
-
|
152
|
+
should "work with criteria and modifier hashes" do
|
153
|
+
@page_class.push({:title => 'Home'}, :tags => 'foo')
|
90
154
|
|
91
|
-
|
92
|
-
|
93
|
-
end
|
155
|
+
@page.reload
|
156
|
+
@page.tags.should == %w(foo)
|
94
157
|
|
95
|
-
|
96
|
-
|
97
|
-
|
158
|
+
@page2.reload
|
159
|
+
@page.tags.should == %w(foo)
|
160
|
+
end
|
98
161
|
|
99
|
-
|
162
|
+
should "work with ids and modifier hash" do
|
163
|
+
@page_class.push(@page.id, @page2.id, :tags => 'foo')
|
100
164
|
|
101
|
-
|
102
|
-
|
165
|
+
@page.reload
|
166
|
+
@page.tags.should == %w(foo)
|
103
167
|
|
104
|
-
|
105
|
-
|
168
|
+
@page2.reload
|
169
|
+
@page.tags.should == %w(foo)
|
170
|
+
end
|
106
171
|
end
|
107
172
|
|
108
|
-
|
109
|
-
|
110
|
-
|
173
|
+
context "push_all" do
|
174
|
+
setup do
|
175
|
+
@page = @page_class.create(:title => 'Home')
|
176
|
+
@page2 = @page_class.create(:title => 'Home')
|
177
|
+
@tags = %w(foo bar)
|
178
|
+
end
|
111
179
|
|
112
|
-
|
180
|
+
should "work with criteria and modifier hashes" do
|
181
|
+
@page_class.push_all({:title => 'Home'}, :tags => @tags)
|
113
182
|
|
114
|
-
|
115
|
-
|
183
|
+
@page.reload
|
184
|
+
@page.tags.should == @tags
|
116
185
|
|
117
|
-
|
118
|
-
|
119
|
-
|
186
|
+
@page2.reload
|
187
|
+
@page.tags.should == @tags
|
188
|
+
end
|
120
189
|
|
121
|
-
|
122
|
-
|
123
|
-
page2 = @page_class.create(:title => 'Home')
|
190
|
+
should "work with ids and modifier hash" do
|
191
|
+
@page_class.push_all(@page.id, @page2.id, :tags => @tags)
|
124
192
|
|
125
|
-
|
193
|
+
@page.reload
|
194
|
+
@page.tags.should == @tags
|
126
195
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
page2.reload
|
131
|
-
page.tags.should == %w(foo)
|
196
|
+
@page2.reload
|
197
|
+
@page.tags.should == @tags
|
198
|
+
end
|
132
199
|
end
|
133
200
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
201
|
+
context "pull" do
|
202
|
+
setup do
|
203
|
+
@page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
204
|
+
@page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
205
|
+
end
|
138
206
|
|
139
|
-
|
207
|
+
should "work with criteria and modifier hashes" do
|
208
|
+
@page_class.pull({:title => 'Home'}, :tags => 'foo')
|
140
209
|
|
141
|
-
|
142
|
-
|
210
|
+
@page.reload
|
211
|
+
@page.tags.should == %w(bar)
|
143
212
|
|
144
|
-
|
145
|
-
|
146
|
-
|
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)
|
213
|
+
@page2.reload
|
214
|
+
@page.tags.should == %w(bar)
|
215
|
+
end
|
152
216
|
|
153
|
-
|
217
|
+
should "be able to pull with ids and modifier hash" do
|
218
|
+
@page_class.pull(@page.id, @page2.id, :tags => 'foo')
|
154
219
|
|
155
|
-
|
156
|
-
|
220
|
+
@page.reload
|
221
|
+
@page.tags.should == %w(bar)
|
157
222
|
|
158
|
-
|
159
|
-
|
223
|
+
@page2.reload
|
224
|
+
@page.tags.should == %w(bar)
|
225
|
+
end
|
160
226
|
end
|
161
227
|
|
162
|
-
|
163
|
-
|
164
|
-
|
228
|
+
context "pull_all" do
|
229
|
+
setup do
|
230
|
+
@page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
231
|
+
@page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
232
|
+
end
|
165
233
|
|
166
|
-
|
234
|
+
should "work with criteria and modifier hashes" do
|
235
|
+
@page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
|
167
236
|
|
168
|
-
|
169
|
-
|
237
|
+
@page.reload
|
238
|
+
@page.tags.should == %w(baz)
|
170
239
|
|
171
|
-
|
172
|
-
|
173
|
-
|
240
|
+
@page2.reload
|
241
|
+
@page.tags.should == %w(baz)
|
242
|
+
end
|
174
243
|
|
175
|
-
|
176
|
-
|
177
|
-
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
244
|
+
should "work with ids and modifier hash" do
|
245
|
+
@page_class.pull_all(@page.id, @page2.id, :tags => %w(foo bar))
|
178
246
|
|
179
|
-
|
247
|
+
@page.reload
|
248
|
+
@page.tags.should == %w(baz)
|
180
249
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
page2.reload
|
185
|
-
page.tags.should == %w(bar)
|
250
|
+
@page2.reload
|
251
|
+
@page.tags.should == %w(baz)
|
252
|
+
end
|
186
253
|
end
|
187
254
|
|
188
|
-
|
189
|
-
|
190
|
-
|
255
|
+
context "add_to_set" do
|
256
|
+
setup do
|
257
|
+
@page = @page_class.create(:title => 'Home', :tags => 'foo')
|
258
|
+
@page2 = @page_class.create(:title => 'Home')
|
259
|
+
end
|
191
260
|
|
192
|
-
|
261
|
+
should "be able to add to set with criteria and modifier hash" do
|
262
|
+
@page_class.add_to_set({:title => 'Home'}, :tags => 'foo')
|
193
263
|
|
194
|
-
|
195
|
-
|
264
|
+
@page.reload
|
265
|
+
@page.tags.should == %w(foo)
|
196
266
|
|
197
|
-
|
198
|
-
|
199
|
-
|
267
|
+
@page2.reload
|
268
|
+
@page.tags.should == %w(foo)
|
269
|
+
end
|
200
270
|
|
201
|
-
|
202
|
-
|
203
|
-
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
271
|
+
should "be able to add to set with ids and modifier hash" do
|
272
|
+
@page_class.add_to_set(@page.id, @page2.id, :tags => 'foo')
|
204
273
|
|
205
|
-
|
274
|
+
@page.reload
|
275
|
+
@page.tags.should == %w(foo)
|
206
276
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
page2.reload
|
211
|
-
page.tags.should == %w(baz)
|
277
|
+
@page2.reload
|
278
|
+
@page.tags.should == %w(foo)
|
279
|
+
end
|
212
280
|
end
|
213
281
|
|
214
|
-
|
215
|
-
|
216
|
-
|
282
|
+
context "push_uniq" do
|
283
|
+
setup do
|
284
|
+
@page = @page_class.create(:title => 'Home', :tags => 'foo')
|
285
|
+
@page2 = @page_class.create(:title => 'Home')
|
286
|
+
end
|
217
287
|
|
218
|
-
|
288
|
+
should "be able to push uniq with criteria and modifier hash" do
|
289
|
+
@page_class.push_uniq({:title => 'Home'}, :tags => 'foo')
|
219
290
|
|
220
|
-
|
221
|
-
|
291
|
+
@page.reload
|
292
|
+
@page.tags.should == %w(foo)
|
222
293
|
|
223
|
-
|
224
|
-
|
225
|
-
|
294
|
+
@page2.reload
|
295
|
+
@page.tags.should == %w(foo)
|
296
|
+
end
|
226
297
|
|
227
|
-
|
228
|
-
|
229
|
-
page2 = @page_class.create(:title => 'Home')
|
298
|
+
should "be able to push uniq with ids and modifier hash" do
|
299
|
+
@page_class.push_uniq(@page.id, @page2.id, :tags => 'foo')
|
230
300
|
|
231
|
-
|
232
|
-
|
233
|
-
page.reload
|
234
|
-
page.tags.should == %w(foo)
|
301
|
+
@page.reload
|
302
|
+
@page.tags.should == %w(foo)
|
235
303
|
|
236
|
-
|
237
|
-
|
304
|
+
@page2.reload
|
305
|
+
@page.tags.should == %w(foo)
|
306
|
+
end
|
238
307
|
end
|
239
308
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
309
|
+
context "pop" do
|
310
|
+
setup do
|
311
|
+
@page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
312
|
+
end
|
313
|
+
|
314
|
+
should "be able to remove the last element the array" do
|
315
|
+
@page_class.pop(@page.id, :tags => 1)
|
316
|
+
@page.reload
|
317
|
+
@page.tags.should == %w(foo)
|
318
|
+
end
|
319
|
+
|
320
|
+
should "be able to remove the first element of the array" do
|
321
|
+
@page_class.pop(@page.id, :tags => -1)
|
322
|
+
@page.reload
|
323
|
+
@page.tags.should == %w(bar)
|
324
|
+
end
|
245
325
|
end
|
326
|
+
end
|
246
327
|
|
247
|
-
|
248
|
-
|
249
|
-
@page_class.
|
250
|
-
page.
|
251
|
-
page
|
328
|
+
context "InstanceMethods" do
|
329
|
+
should "be able to unset with keys" do
|
330
|
+
page = @page_class.create(:title => 'Foo', :tags => %w(foo))
|
331
|
+
page.unset(:title, :tags)
|
332
|
+
assert_keys_removed page, :title, :tags
|
252
333
|
end
|
253
|
-
end
|
254
334
|
|
255
|
-
context "using instance methods" do
|
256
335
|
should "be able to increment with modifier hashes" do
|
257
336
|
page = @page_class.create
|
258
|
-
|
259
|
-
page.increment({:day_count => 1, :week_count => 2, :month_count => 3})
|
337
|
+
page.increment(:day_count => 1, :week_count => 2, :month_count => 3)
|
260
338
|
|
261
339
|
assert_page_counts page, 1, 2, 3
|
262
340
|
end
|
263
341
|
|
264
342
|
should "be able to decrement with modifier hashes" do
|
265
343
|
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})
|
344
|
+
page.decrement(:day_count => 1, :week_count => 2, :month_count => 3)
|
268
345
|
|
269
346
|
assert_page_counts page, 0, 0, 0
|
270
347
|
end
|
271
348
|
|
272
349
|
should "always decrement when decrement is called whether number is positive or negative" do
|
273
350
|
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})
|
351
|
+
page.decrement(:day_count => -1, :week_count => 2, :month_count => -3)
|
276
352
|
|
277
353
|
assert_page_counts page, 0, 0, 0
|
278
354
|
end
|
279
355
|
|
280
356
|
should "be able to set with modifier hashes" do
|
281
357
|
page = @page_class.create(:title => 'Home')
|
282
|
-
|
283
358
|
page.set(:title => 'Home Revised')
|
284
359
|
|
285
360
|
page.reload
|
@@ -288,7 +363,6 @@ class ModifierTest < Test::Unit::TestCase
|
|
288
363
|
|
289
364
|
should "be able to push with modifier hashes" do
|
290
365
|
page = @page_class.create
|
291
|
-
|
292
366
|
page.push(:tags => 'foo')
|
293
367
|
|
294
368
|
page.reload
|
@@ -296,14 +370,27 @@ class ModifierTest < Test::Unit::TestCase
|
|
296
370
|
end
|
297
371
|
|
298
372
|
should "be able to pull with criteria and modifier hashes" do
|
299
|
-
page
|
300
|
-
|
373
|
+
page = @page_class.create(:tags => %w(foo bar))
|
301
374
|
page.pull(:tags => 'foo')
|
302
375
|
|
303
376
|
page.reload
|
304
377
|
page.tags.should == %w(bar)
|
305
378
|
end
|
306
379
|
|
380
|
+
should "be able to add_to_set with criteria and modifier hash" do
|
381
|
+
page = @page_class.create(:tags => 'foo')
|
382
|
+
page2 = @page_class.create
|
383
|
+
|
384
|
+
page.add_to_set(:tags => 'foo')
|
385
|
+
page.add_to_set(:tags => 'foo')
|
386
|
+
|
387
|
+
page.reload
|
388
|
+
page.tags.should == %w(foo)
|
389
|
+
|
390
|
+
page2.reload
|
391
|
+
page.tags.should == %w(foo)
|
392
|
+
end
|
393
|
+
|
307
394
|
should "be able to push uniq with criteria and modifier hash" do
|
308
395
|
page = @page_class.create(:tags => 'foo')
|
309
396
|
page2 = @page_class.create
|
@@ -317,6 +404,13 @@ class ModifierTest < Test::Unit::TestCase
|
|
317
404
|
page2.reload
|
318
405
|
page.tags.should == %w(foo)
|
319
406
|
end
|
320
|
-
end
|
321
407
|
|
408
|
+
should "be able to pop with modifier hashes" do
|
409
|
+
page = @page_class.create(:tags => %w(foo bar))
|
410
|
+
page.pop(:tags => 1)
|
411
|
+
|
412
|
+
page.reload
|
413
|
+
page.tags.should == %w(foo)
|
414
|
+
end
|
415
|
+
end
|
322
416
|
end
|
@@ -4,30 +4,28 @@ class PaginationTest < Test::Unit::TestCase
|
|
4
4
|
context "Paginating" do
|
5
5
|
setup do
|
6
6
|
@document = Doc do
|
7
|
-
set_collection_name 'users'
|
8
|
-
|
9
7
|
key :first_name, String
|
10
8
|
key :last_name, String
|
11
9
|
key :age, Integer
|
12
|
-
|
10
|
+
|
13
11
|
def self.per_page; 1 end
|
14
12
|
end
|
15
|
-
|
16
|
-
@doc1 = @document.create(
|
17
|
-
@doc2 = @document.create(
|
18
|
-
@doc3 = @document.create(
|
13
|
+
|
14
|
+
@doc1 = @document.create(:first_name => 'John', :last_name => 'Nunemaker', :age => '27')
|
15
|
+
@doc2 = @document.create(:first_name => 'Steve', :last_name => 'Smith', :age => '28')
|
16
|
+
@doc3 = @document.create(:first_name => 'Steph', :last_name => 'Nunemaker', :age => '26')
|
19
17
|
end
|
20
18
|
|
21
19
|
should "return the total pages" do
|
22
20
|
result = @document.paginate(:per_page => 2, :page => 1)
|
23
21
|
result.total_pages.should == 2
|
24
22
|
end
|
25
|
-
|
23
|
+
|
26
24
|
should "return the total pages when defaulting to the document class per_page" do
|
27
25
|
result = @document.paginate(:page => 1)
|
28
26
|
result.total_pages.should == 3
|
29
27
|
end
|
30
|
-
|
28
|
+
|
31
29
|
should "return the total of records" do
|
32
30
|
result = @document.paginate(:per_page => 2, :page => 1)
|
33
31
|
result.total_entries.should == 3
|
@@ -43,7 +41,7 @@ class PaginationTest < Test::Unit::TestCase
|
|
43
41
|
result = @document.paginate({
|
44
42
|
:last_name => 'Nunemaker',
|
45
43
|
:order => "age DESC",
|
46
|
-
:per_page => 2,
|
44
|
+
:per_page => 2,
|
47
45
|
:page => 1,
|
48
46
|
})
|
49
47
|
result.should == [@doc1, @doc3]
|
@@ -58,17 +56,17 @@ class PaginationTest < Test::Unit::TestCase
|
|
58
56
|
result.first.age.should == 27
|
59
57
|
end
|
60
58
|
|
61
|
-
should "withstand rigor" do
|
59
|
+
should "withstand rigor" do
|
62
60
|
result = @document.paginate({
|
63
|
-
:per_page => 1,
|
61
|
+
:per_page => 1,
|
64
62
|
:page => 1,
|
65
|
-
:order => 'age desc',
|
63
|
+
:order => 'age desc',
|
66
64
|
:last_name => 'Nunemaker'
|
67
65
|
})
|
68
66
|
result.should == [@doc1]
|
69
67
|
result.total_entries.should == 2
|
70
68
|
result.total_pages.should == 2
|
71
|
-
|
69
|
+
|
72
70
|
result = @document.paginate({
|
73
71
|
:per_page => 1,
|
74
72
|
:page => 2,
|
@@ -78,7 +76,7 @@ class PaginationTest < Test::Unit::TestCase
|
|
78
76
|
result.should == [@doc3]
|
79
77
|
result.total_entries.should == 2
|
80
78
|
result.total_pages.should == 2
|
81
|
-
|
79
|
+
|
82
80
|
result = @document.paginate({
|
83
81
|
:per_page => 2,
|
84
82
|
:page => 1,
|