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.
Files changed (143) hide show
  1. data/README.rdoc +4 -8
  2. data/bin/mmconsole +1 -1
  3. data/examples/keys.rb +37 -0
  4. data/examples/plugins.rb +41 -0
  5. data/examples/querying.rb +35 -0
  6. data/examples/scopes.rb +52 -0
  7. data/lib/mongo_mapper/connection.rb +83 -0
  8. data/lib/mongo_mapper/document.rb +11 -329
  9. data/lib/mongo_mapper/embedded_document.rb +9 -38
  10. data/lib/mongo_mapper/exceptions.rb +30 -0
  11. data/lib/mongo_mapper/extensions/array.rb +19 -0
  12. data/lib/mongo_mapper/extensions/binary.rb +22 -0
  13. data/lib/mongo_mapper/extensions/boolean.rb +44 -0
  14. data/lib/mongo_mapper/extensions/date.rb +25 -0
  15. data/lib/mongo_mapper/extensions/float.rb +14 -0
  16. data/lib/mongo_mapper/extensions/hash.rb +14 -0
  17. data/lib/mongo_mapper/extensions/integer.rb +19 -0
  18. data/lib/mongo_mapper/extensions/kernel.rb +9 -0
  19. data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
  20. data/lib/mongo_mapper/extensions/object.rb +27 -0
  21. data/lib/mongo_mapper/extensions/object_id.rb +30 -0
  22. data/lib/mongo_mapper/extensions/set.rb +20 -0
  23. data/lib/mongo_mapper/extensions/string.rb +18 -0
  24. data/lib/mongo_mapper/extensions/time.rb +29 -0
  25. data/lib/mongo_mapper/plugins/accessible.rb +44 -0
  26. data/lib/mongo_mapper/plugins/associations/base.rb +7 -6
  27. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +5 -6
  28. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +5 -6
  29. data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
  30. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +2 -1
  31. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +25 -39
  32. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +4 -4
  33. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +36 -46
  34. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
  35. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +5 -4
  36. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
  37. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
  38. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
  39. data/lib/mongo_mapper/plugins/associations/proxy.rb +16 -8
  40. data/lib/mongo_mapper/plugins/associations.rb +14 -22
  41. data/lib/mongo_mapper/plugins/caching.rb +21 -0
  42. data/lib/mongo_mapper/plugins/callbacks.rb +17 -5
  43. data/lib/mongo_mapper/plugins/clone.rb +10 -4
  44. data/lib/mongo_mapper/plugins/descendants.rb +3 -2
  45. data/lib/mongo_mapper/plugins/dirty.rb +1 -0
  46. data/lib/mongo_mapper/plugins/document.rb +41 -0
  47. data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +3 -36
  48. data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
  49. data/lib/mongo_mapper/plugins/embedded_document.rb +49 -0
  50. data/lib/mongo_mapper/plugins/equality.rb +4 -10
  51. data/lib/mongo_mapper/plugins/identity_map.rb +29 -23
  52. data/lib/mongo_mapper/plugins/indexes.rb +12 -0
  53. data/lib/mongo_mapper/plugins/inspect.rb +1 -0
  54. data/lib/mongo_mapper/plugins/keys/key.rb +55 -0
  55. data/lib/mongo_mapper/plugins/keys.rb +85 -110
  56. data/lib/mongo_mapper/plugins/logger.rb +1 -0
  57. data/lib/mongo_mapper/plugins/modifiers.rb +41 -16
  58. data/lib/mongo_mapper/plugins/pagination.rb +5 -15
  59. data/lib/mongo_mapper/plugins/persistence.rb +69 -0
  60. data/lib/mongo_mapper/plugins/protected.rb +9 -1
  61. data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
  62. data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
  63. data/lib/mongo_mapper/plugins/querying.rb +176 -0
  64. data/lib/mongo_mapper/plugins/rails.rb +6 -1
  65. data/lib/mongo_mapper/plugins/safe.rb +28 -0
  66. data/lib/mongo_mapper/plugins/sci.rb +32 -0
  67. data/lib/mongo_mapper/plugins/scopes.rb +21 -0
  68. data/lib/mongo_mapper/plugins/serialization.rb +5 -4
  69. data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
  70. data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
  71. data/lib/mongo_mapper/plugins/validations.rb +9 -5
  72. data/lib/mongo_mapper/plugins.rb +1 -20
  73. data/lib/mongo_mapper/support/descendant_appends.rb +5 -6
  74. data/lib/mongo_mapper/version.rb +4 -0
  75. data/lib/mongo_mapper.rb +71 -128
  76. data/test/{NOTE_ON_TESTING → _NOTE_ON_TESTING} +0 -0
  77. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +5 -5
  78. data/test/functional/associations/test_belongs_to_proxy.rb +13 -21
  79. data/test/functional/associations/test_in_array_proxy.rb +7 -9
  80. data/test/functional/associations/test_many_documents_as_proxy.rb +5 -5
  81. data/test/functional/associations/test_many_documents_proxy.rb +186 -64
  82. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +22 -22
  83. data/test/functional/associations/test_many_embedded_proxy.rb +32 -32
  84. data/test/functional/associations/test_many_polymorphic_proxy.rb +47 -47
  85. data/test/functional/associations/test_one_embedded_proxy.rb +67 -0
  86. data/test/functional/associations/test_one_proxy.rb +70 -49
  87. data/test/functional/test_accessible.rb +168 -0
  88. data/test/functional/test_associations.rb +11 -11
  89. data/test/functional/test_binary.rb +5 -5
  90. data/test/functional/test_caching.rb +76 -0
  91. data/test/functional/test_callbacks.rb +104 -34
  92. data/test/functional/test_dirty.rb +16 -16
  93. data/test/functional/test_document.rb +12 -924
  94. data/test/functional/test_dynamic_querying.rb +75 -0
  95. data/test/functional/test_embedded_document.rb +88 -8
  96. data/test/functional/test_identity_map.rb +41 -43
  97. data/test/functional/{test_indexing.rb → test_indexes.rb} +3 -5
  98. data/test/functional/test_logger.rb +1 -1
  99. data/test/functional/test_modifiers.rb +275 -181
  100. data/test/functional/test_pagination.rb +13 -15
  101. data/test/functional/test_protected.rb +25 -11
  102. data/test/functional/test_querying.rb +873 -0
  103. data/test/functional/test_safe.rb +76 -0
  104. data/test/functional/test_sci.rb +230 -0
  105. data/test/functional/test_scopes.rb +171 -0
  106. data/test/functional/test_string_id_compatibility.rb +11 -11
  107. data/test/functional/test_timestamps.rb +0 -2
  108. data/test/functional/test_userstamps.rb +0 -1
  109. data/test/functional/test_validations.rb +44 -31
  110. data/test/models.rb +18 -17
  111. data/test/{active_model_lint_test.rb → test_active_model_lint.rb} +3 -1
  112. data/test/test_helper.rb +59 -16
  113. data/test/unit/associations/test_base.rb +47 -42
  114. data/test/unit/associations/test_proxy.rb +15 -15
  115. data/test/unit/serializers/test_json_serializer.rb +29 -29
  116. data/test/unit/test_clone.rb +69 -0
  117. data/test/unit/test_descendant_appends.rb +3 -3
  118. data/test/unit/test_document.rb +49 -67
  119. data/test/unit/test_dynamic_finder.rb +53 -51
  120. data/test/unit/test_embedded_document.rb +19 -38
  121. data/test/unit/{test_support.rb → test_extensions.rb} +136 -122
  122. data/test/unit/test_key.rb +185 -0
  123. data/test/unit/test_keys.rb +29 -147
  124. data/test/unit/test_mongo_mapper.rb +3 -48
  125. data/test/unit/test_pagination.rb +1 -150
  126. data/test/unit/test_rails.rb +77 -19
  127. data/test/unit/test_rails_compatibility.rb +12 -12
  128. data/test/unit/test_serialization.rb +5 -5
  129. data/test/unit/test_time_zones.rb +9 -9
  130. data/test/unit/test_validations.rb +46 -46
  131. metadata +157 -155
  132. data/.gitignore +0 -10
  133. data/Rakefile +0 -55
  134. data/VERSION +0 -1
  135. data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
  136. data/lib/mongo_mapper/query.rb +0 -130
  137. data/lib/mongo_mapper/support.rb +0 -215
  138. data/mongo_mapper.gemspec +0 -196
  139. data/performance/read_write.rb +0 -52
  140. data/specs.watchr +0 -51
  141. data/test/support/custom_matchers.rb +0 -55
  142. data/test/support/timing.rb +0 -16
  143. 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, String
7
- key :day_count, Integer, :default => 0
8
- key :week_count, Integer, :default => 0
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, Array
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
- 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')
25
-
26
- @page_class.increment({:title => 'Home'}, {
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
- assert_page_counts page, 1, 2, 3
31
- assert_page_counts page2, 1, 2, 3
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
- 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')
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
- @page_class.increment(page.id, page2.id, {
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
- assert_page_counts page, 1, 2, 3
43
- assert_page_counts page2, 1, 2, 3
44
- end
57
+ assert_page_counts @page, 1, 2, 3
58
+ assert_page_counts @page2, 1, 2, 3
59
+ end
45
60
 
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)
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
- @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
64
+ assert_page_counts @page, 1, 2, 3
65
+ assert_page_counts @page2, 1, 2, 3
66
+ end
56
67
  end
57
68
 
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)
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
- @page_class.decrement(page.id, page2.id, {
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
- assert_page_counts page, 0, 0, 0
67
- assert_page_counts page2, 0, 0, 0
68
- end
78
+ assert_page_counts @page, 0, 0, 0
79
+ assert_page_counts @page2, 0, 0, 0
80
+ end
69
81
 
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)
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
- @page_class.decrement(page.id, page2.id, {
75
- :day_count => -1, :week_count => 2, :month_count => -3
76
- })
85
+ assert_page_counts @page, 0, 0, 0
86
+ assert_page_counts @page2, 0, 0, 0
87
+ end
77
88
 
78
- assert_page_counts page, 0, 0, 0
79
- assert_page_counts page2, 0, 0, 0
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
- 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')
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
- @page_class.set({:title => 'Home'}, :title => 'Home Revised')
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
- page.reload
89
- page.title.should == 'Home Revised'
152
+ should "work with criteria and modifier hashes" do
153
+ @page_class.push({:title => 'Home'}, :tags => 'foo')
90
154
 
91
- page2.reload
92
- page2.title.should == 'Home Revised'
93
- end
155
+ @page.reload
156
+ @page.tags.should == %w(foo)
94
157
 
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')
158
+ @page2.reload
159
+ @page.tags.should == %w(foo)
160
+ end
98
161
 
99
- @page_class.set(page.id, page2.id, :title => 'Home Revised')
162
+ should "work with ids and modifier hash" do
163
+ @page_class.push(@page.id, @page2.id, :tags => 'foo')
100
164
 
101
- page.reload
102
- page.title.should == 'Home Revised'
165
+ @page.reload
166
+ @page.tags.should == %w(foo)
103
167
 
104
- page2.reload
105
- page2.title.should == 'Home Revised'
168
+ @page2.reload
169
+ @page.tags.should == %w(foo)
170
+ end
106
171
  end
107
172
 
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')
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
- @page_class.push({:title => 'Home'}, :tags => 'foo')
180
+ should "work with criteria and modifier hashes" do
181
+ @page_class.push_all({:title => 'Home'}, :tags => @tags)
113
182
 
114
- page.reload
115
- page.tags.should == %w(foo)
183
+ @page.reload
184
+ @page.tags.should == @tags
116
185
 
117
- page2.reload
118
- page.tags.should == %w(foo)
119
- end
186
+ @page2.reload
187
+ @page.tags.should == @tags
188
+ end
120
189
 
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')
190
+ should "work with ids and modifier hash" do
191
+ @page_class.push_all(@page.id, @page2.id, :tags => @tags)
124
192
 
125
- @page_class.push(page.id, page2.id, :tags => 'foo')
193
+ @page.reload
194
+ @page.tags.should == @tags
126
195
 
127
- page.reload
128
- page.tags.should == %w(foo)
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
- 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)
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
- @page_class.push_all({:title => 'Home'}, :tags => tags)
207
+ should "work with criteria and modifier hashes" do
208
+ @page_class.pull({:title => 'Home'}, :tags => 'foo')
140
209
 
141
- page.reload
142
- page.tags.should == tags
210
+ @page.reload
211
+ @page.tags.should == %w(bar)
143
212
 
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)
213
+ @page2.reload
214
+ @page.tags.should == %w(bar)
215
+ end
152
216
 
153
- @page_class.push_all(page.id, page2.id, :tags => tags)
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
- page.reload
156
- page.tags.should == tags
220
+ @page.reload
221
+ @page.tags.should == %w(bar)
157
222
 
158
- page2.reload
159
- page.tags.should == tags
223
+ @page2.reload
224
+ @page.tags.should == %w(bar)
225
+ end
160
226
  end
161
227
 
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))
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
- @page_class.pull({:title => 'Home'}, :tags => 'foo')
234
+ should "work with criteria and modifier hashes" do
235
+ @page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
167
236
 
168
- page.reload
169
- page.tags.should == %w(bar)
237
+ @page.reload
238
+ @page.tags.should == %w(baz)
170
239
 
171
- page2.reload
172
- page.tags.should == %w(bar)
173
- end
240
+ @page2.reload
241
+ @page.tags.should == %w(baz)
242
+ end
174
243
 
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))
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
- @page_class.pull(page.id, page2.id, :tags => 'foo')
247
+ @page.reload
248
+ @page.tags.should == %w(baz)
180
249
 
181
- page.reload
182
- page.tags.should == %w(bar)
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
- 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))
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
- @page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
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
- page.reload
195
- page.tags.should == %w(baz)
264
+ @page.reload
265
+ @page.tags.should == %w(foo)
196
266
 
197
- page2.reload
198
- page.tags.should == %w(baz)
199
- end
267
+ @page2.reload
268
+ @page.tags.should == %w(foo)
269
+ end
200
270
 
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))
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
- @page_class.pull_all(page.id, page2.id, :tags => %w(foo bar))
274
+ @page.reload
275
+ @page.tags.should == %w(foo)
206
276
 
207
- page.reload
208
- page.tags.should == %w(baz)
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
- 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')
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
- @page_class.push_uniq({:title => 'Home'}, :tags => 'foo')
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
- page.reload
221
- page.tags.should == %w(foo)
291
+ @page.reload
292
+ @page.tags.should == %w(foo)
222
293
 
223
- page2.reload
224
- page.tags.should == %w(foo)
225
- end
294
+ @page2.reload
295
+ @page.tags.should == %w(foo)
296
+ end
226
297
 
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')
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
- @page_class.push_uniq(page.id, page2.id, :tags => 'foo')
232
-
233
- page.reload
234
- page.tags.should == %w(foo)
301
+ @page.reload
302
+ @page.tags.should == %w(foo)
235
303
 
236
- page2.reload
237
- page.tags.should == %w(foo)
304
+ @page2.reload
305
+ @page.tags.should == %w(foo)
306
+ end
238
307
  end
239
308
 
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)
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
- 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)
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 = @page_class.create(:tags => %w(foo bar))
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({:first_name => 'John', :last_name => 'Nunemaker', :age => '27'})
17
- @doc2 = @document.create({:first_name => 'Steve', :last_name => 'Smith', :age => '28'})
18
- @doc3 = @document.create({:first_name => 'Steph', :last_name => 'Nunemaker', :age => '26'})
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,