jonbell-mongo_mapper 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +33 -0
- data/UPGRADES +7 -0
- data/bin/mmconsole +60 -0
- data/examples/attr_accessible.rb +22 -0
- data/examples/attr_protected.rb +22 -0
- data/examples/cache_key.rb +24 -0
- data/examples/custom_types.rb +24 -0
- data/examples/identity_map.rb +33 -0
- data/examples/identity_map/automatic.rb +8 -0
- data/examples/identity_map/middleware.rb +14 -0
- data/examples/keys.rb +40 -0
- data/examples/modifiers/set.rb +25 -0
- data/examples/plugins.rb +41 -0
- data/examples/querying.rb +35 -0
- data/examples/safe.rb +43 -0
- data/examples/scopes.rb +52 -0
- data/examples/validating/embedded_docs.rb +29 -0
- data/lib/mongo_mapper.rb +79 -0
- data/lib/mongo_mapper/connection.rb +83 -0
- data/lib/mongo_mapper/document.rb +41 -0
- data/lib/mongo_mapper/embedded_document.rb +31 -0
- data/lib/mongo_mapper/exceptions.rb +27 -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.rb +15 -0
- data/lib/mongo_mapper/plugins/accessible.rb +44 -0
- data/lib/mongo_mapper/plugins/associations.rb +97 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +124 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +29 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +24 -0
- data/lib/mongo_mapper/plugins/associations/collection.rb +27 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +40 -0
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +127 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +109 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +24 -0
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -0
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +68 -0
- data/lib/mongo_mapper/plugins/associations/proxy.rb +139 -0
- data/lib/mongo_mapper/plugins/caching.rb +21 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +241 -0
- data/lib/mongo_mapper/plugins/clone.rb +22 -0
- data/lib/mongo_mapper/plugins/descendants.rb +17 -0
- data/lib/mongo_mapper/plugins/dirty.rb +124 -0
- data/lib/mongo_mapper/plugins/document.rb +41 -0
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +44 -0
- data/lib/mongo_mapper/plugins/embedded_document.rb +48 -0
- data/lib/mongo_mapper/plugins/equality.rb +17 -0
- data/lib/mongo_mapper/plugins/identity_map.rb +128 -0
- data/lib/mongo_mapper/plugins/indexes.rb +12 -0
- data/lib/mongo_mapper/plugins/inspect.rb +15 -0
- data/lib/mongo_mapper/plugins/keys.rb +313 -0
- data/lib/mongo_mapper/plugins/keys/key.rb +59 -0
- data/lib/mongo_mapper/plugins/logger.rb +18 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +112 -0
- data/lib/mongo_mapper/plugins/pagination.rb +14 -0
- data/lib/mongo_mapper/plugins/persistence.rb +69 -0
- data/lib/mongo_mapper/plugins/protected.rb +53 -0
- data/lib/mongo_mapper/plugins/querying.rb +176 -0
- 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/rails.rb +58 -0
- 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 +76 -0
- data/lib/mongo_mapper/plugins/timestamps.rb +22 -0
- data/lib/mongo_mapper/plugins/userstamps.rb +15 -0
- data/lib/mongo_mapper/plugins/validations.rb +50 -0
- data/lib/mongo_mapper/support/descendant_appends.rb +45 -0
- data/lib/mongo_mapper/version.rb +4 -0
- data/rails/init.rb +19 -0
- data/test/_NOTE_ON_TESTING +1 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +63 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +93 -0
- data/test/functional/associations/test_in_array_proxy.rb +319 -0
- data/test/functional/associations/test_many_documents_as_proxy.rb +229 -0
- data/test/functional/associations/test_many_documents_proxy.rb +615 -0
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +176 -0
- data/test/functional/associations/test_many_embedded_proxy.rb +256 -0
- data/test/functional/associations/test_many_polymorphic_proxy.rb +302 -0
- data/test/functional/associations/test_one_embedded_proxy.rb +81 -0
- data/test/functional/associations/test_one_proxy.rb +181 -0
- data/test/functional/test_accessible.rb +168 -0
- data/test/functional/test_associations.rb +44 -0
- data/test/functional/test_binary.rb +27 -0
- data/test/functional/test_caching.rb +76 -0
- data/test/functional/test_callbacks.rb +151 -0
- data/test/functional/test_dirty.rb +163 -0
- data/test/functional/test_document.rb +253 -0
- data/test/functional/test_dynamic_querying.rb +75 -0
- data/test/functional/test_embedded_document.rb +210 -0
- data/test/functional/test_identity_map.rb +514 -0
- data/test/functional/test_indexes.rb +42 -0
- data/test/functional/test_logger.rb +20 -0
- data/test/functional/test_modifiers.rb +416 -0
- data/test/functional/test_pagination.rb +91 -0
- data/test/functional/test_protected.rb +175 -0
- 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 +67 -0
- data/test/functional/test_timestamps.rb +62 -0
- data/test/functional/test_userstamps.rb +27 -0
- data/test/functional/test_validations.rb +342 -0
- data/test/models.rb +233 -0
- data/test/test_active_model_lint.rb +13 -0
- data/test/test_helper.rb +100 -0
- data/test/unit/associations/test_base.rb +212 -0
- data/test/unit/associations/test_proxy.rb +105 -0
- data/test/unit/serializers/test_json_serializer.rb +217 -0
- data/test/unit/test_clone.rb +69 -0
- data/test/unit/test_descendant_appends.rb +71 -0
- data/test/unit/test_document.rb +213 -0
- data/test/unit/test_dynamic_finder.rb +125 -0
- data/test/unit/test_embedded_document.rb +644 -0
- data/test/unit/test_extensions.rb +376 -0
- data/test/unit/test_key.rb +185 -0
- data/test/unit/test_keys.rb +89 -0
- data/test/unit/test_mongo_mapper.rb +110 -0
- data/test/unit/test_pagination.rb +11 -0
- data/test/unit/test_plugins.rb +50 -0
- data/test/unit/test_rails.rb +181 -0
- data/test/unit/test_rails_compatibility.rb +52 -0
- data/test/unit/test_serialization.rb +51 -0
- data/test/unit/test_time_zones.rb +39 -0
- data/test/unit/test_validations.rb +564 -0
- metadata +337 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class IndexingTest < Test::Unit::TestCase
|
4
|
+
context "Indexing" do
|
5
|
+
setup do
|
6
|
+
@document = Doc do
|
7
|
+
key :first_name, String
|
8
|
+
key :last_name, String
|
9
|
+
key :age, Integer
|
10
|
+
key :date, Date
|
11
|
+
end
|
12
|
+
end
|
13
|
+
teardown { drop_indexes(@document) }
|
14
|
+
|
15
|
+
should "allow creating index for a key" do
|
16
|
+
@document.ensure_index :first_name
|
17
|
+
@document.should have_index('first_name_1')
|
18
|
+
end
|
19
|
+
|
20
|
+
should "allow creating unique index for a key" do
|
21
|
+
@document.ensure_index :first_name, :unique => true
|
22
|
+
@document.should have_index('first_name_1')
|
23
|
+
end
|
24
|
+
|
25
|
+
should "allow creating index on multiple keys" do
|
26
|
+
@document.ensure_index [[:first_name, 1], [:last_name, -1]]
|
27
|
+
|
28
|
+
# order is different for different versions of ruby so instead of
|
29
|
+
# just checking have_index('first_name_1_last_name_-1') I'm checking
|
30
|
+
# the values of the indexes to make sure the index creation was successful
|
31
|
+
@document.collection.index_information.detect do |index|
|
32
|
+
keys = index[0]
|
33
|
+
keys.include?('first_name_1') && keys.include?('last_name_-1')
|
34
|
+
end.should_not be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
should "work with :index shortcut when defining key" do
|
38
|
+
@document.key :father, String, :index => true
|
39
|
+
@document.should have_index('father_1')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LoggerTest < Test::Unit::TestCase
|
4
|
+
context "with connection that has logger" do
|
5
|
+
setup do
|
6
|
+
@output = StringIO.new
|
7
|
+
@logger = Logger.new(@output)
|
8
|
+
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => @logger)
|
9
|
+
end
|
10
|
+
|
11
|
+
should "be able to get access to that logger" do
|
12
|
+
MongoMapper.logger.should == @logger
|
13
|
+
end
|
14
|
+
|
15
|
+
should "be able to log messages" do
|
16
|
+
MongoMapper.logger.debug 'testing'
|
17
|
+
@output.string.include?('testing').should be_true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,416 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ModifierTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@page_class = Doc do
|
6
|
+
key :title, String
|
7
|
+
key :day_count, Integer, :default => 0
|
8
|
+
key :week_count, Integer, :default => 0
|
9
|
+
key :month_count, Integer, :default => 0
|
10
|
+
key :tags, Array
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_page_counts(page, day_count, week_count, month_count)
|
15
|
+
page.reload
|
16
|
+
page.day_count.should == day_count
|
17
|
+
page.week_count.should == week_count
|
18
|
+
page.month_count.should == month_count
|
19
|
+
end
|
20
|
+
|
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
|
27
|
+
|
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
|
46
|
+
end
|
47
|
+
|
48
|
+
context "increment" do
|
49
|
+
setup do
|
50
|
+
@page = @page_class.create(:title => 'Home')
|
51
|
+
@page2 = @page_class.create(:title => 'Home')
|
52
|
+
end
|
53
|
+
|
54
|
+
should "work with criteria and modifier hashes" do
|
55
|
+
@page_class.increment({:title => 'Home'}, :day_count => 1, :week_count => 2, :month_count => 3)
|
56
|
+
|
57
|
+
assert_page_counts @page, 1, 2, 3
|
58
|
+
assert_page_counts @page2, 1, 2, 3
|
59
|
+
end
|
60
|
+
|
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)
|
63
|
+
|
64
|
+
assert_page_counts @page, 1, 2, 3
|
65
|
+
assert_page_counts @page2, 1, 2, 3
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
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
|
74
|
+
|
75
|
+
should "work with criteria and modifier hashes" do
|
76
|
+
@page_class.decrement({:title => 'Home'}, :day_count => 1, :week_count => 2, :month_count => 3)
|
77
|
+
|
78
|
+
assert_page_counts @page, 0, 0, 0
|
79
|
+
assert_page_counts @page2, 0, 0, 0
|
80
|
+
end
|
81
|
+
|
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)
|
84
|
+
|
85
|
+
assert_page_counts @page, 0, 0, 0
|
86
|
+
assert_page_counts @page2, 0, 0, 0
|
87
|
+
end
|
88
|
+
|
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
|
95
|
+
end
|
96
|
+
|
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
|
145
|
+
|
146
|
+
context "push" do
|
147
|
+
setup do
|
148
|
+
@page = @page_class.create(:title => 'Home')
|
149
|
+
@page2 = @page_class.create(:title => 'Home')
|
150
|
+
end
|
151
|
+
|
152
|
+
should "work with criteria and modifier hashes" do
|
153
|
+
@page_class.push({:title => 'Home'}, :tags => 'foo')
|
154
|
+
|
155
|
+
@page.reload
|
156
|
+
@page.tags.should == %w(foo)
|
157
|
+
|
158
|
+
@page2.reload
|
159
|
+
@page.tags.should == %w(foo)
|
160
|
+
end
|
161
|
+
|
162
|
+
should "work with ids and modifier hash" do
|
163
|
+
@page_class.push(@page.id, @page2.id, :tags => 'foo')
|
164
|
+
|
165
|
+
@page.reload
|
166
|
+
@page.tags.should == %w(foo)
|
167
|
+
|
168
|
+
@page2.reload
|
169
|
+
@page.tags.should == %w(foo)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
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
|
179
|
+
|
180
|
+
should "work with criteria and modifier hashes" do
|
181
|
+
@page_class.push_all({:title => 'Home'}, :tags => @tags)
|
182
|
+
|
183
|
+
@page.reload
|
184
|
+
@page.tags.should == @tags
|
185
|
+
|
186
|
+
@page2.reload
|
187
|
+
@page.tags.should == @tags
|
188
|
+
end
|
189
|
+
|
190
|
+
should "work with ids and modifier hash" do
|
191
|
+
@page_class.push_all(@page.id, @page2.id, :tags => @tags)
|
192
|
+
|
193
|
+
@page.reload
|
194
|
+
@page.tags.should == @tags
|
195
|
+
|
196
|
+
@page2.reload
|
197
|
+
@page.tags.should == @tags
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
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
|
206
|
+
|
207
|
+
should "work with criteria and modifier hashes" do
|
208
|
+
@page_class.pull({:title => 'Home'}, :tags => 'foo')
|
209
|
+
|
210
|
+
@page.reload
|
211
|
+
@page.tags.should == %w(bar)
|
212
|
+
|
213
|
+
@page2.reload
|
214
|
+
@page.tags.should == %w(bar)
|
215
|
+
end
|
216
|
+
|
217
|
+
should "be able to pull with ids and modifier hash" do
|
218
|
+
@page_class.pull(@page.id, @page2.id, :tags => 'foo')
|
219
|
+
|
220
|
+
@page.reload
|
221
|
+
@page.tags.should == %w(bar)
|
222
|
+
|
223
|
+
@page2.reload
|
224
|
+
@page.tags.should == %w(bar)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
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
|
233
|
+
|
234
|
+
should "work with criteria and modifier hashes" do
|
235
|
+
@page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
|
236
|
+
|
237
|
+
@page.reload
|
238
|
+
@page.tags.should == %w(baz)
|
239
|
+
|
240
|
+
@page2.reload
|
241
|
+
@page.tags.should == %w(baz)
|
242
|
+
end
|
243
|
+
|
244
|
+
should "work with ids and modifier hash" do
|
245
|
+
@page_class.pull_all(@page.id, @page2.id, :tags => %w(foo bar))
|
246
|
+
|
247
|
+
@page.reload
|
248
|
+
@page.tags.should == %w(baz)
|
249
|
+
|
250
|
+
@page2.reload
|
251
|
+
@page.tags.should == %w(baz)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
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
|
260
|
+
|
261
|
+
should "be able to add to set with criteria and modifier hash" do
|
262
|
+
@page_class.add_to_set({:title => 'Home'}, :tags => 'foo')
|
263
|
+
|
264
|
+
@page.reload
|
265
|
+
@page.tags.should == %w(foo)
|
266
|
+
|
267
|
+
@page2.reload
|
268
|
+
@page.tags.should == %w(foo)
|
269
|
+
end
|
270
|
+
|
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')
|
273
|
+
|
274
|
+
@page.reload
|
275
|
+
@page.tags.should == %w(foo)
|
276
|
+
|
277
|
+
@page2.reload
|
278
|
+
@page.tags.should == %w(foo)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
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
|
287
|
+
|
288
|
+
should "be able to push uniq with criteria and modifier hash" do
|
289
|
+
@page_class.push_uniq({:title => 'Home'}, :tags => 'foo')
|
290
|
+
|
291
|
+
@page.reload
|
292
|
+
@page.tags.should == %w(foo)
|
293
|
+
|
294
|
+
@page2.reload
|
295
|
+
@page.tags.should == %w(foo)
|
296
|
+
end
|
297
|
+
|
298
|
+
should "be able to push uniq with ids and modifier hash" do
|
299
|
+
@page_class.push_uniq(@page.id, @page2.id, :tags => 'foo')
|
300
|
+
|
301
|
+
@page.reload
|
302
|
+
@page.tags.should == %w(foo)
|
303
|
+
|
304
|
+
@page2.reload
|
305
|
+
@page.tags.should == %w(foo)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
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
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
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
|
333
|
+
end
|
334
|
+
|
335
|
+
should "be able to increment with modifier hashes" do
|
336
|
+
page = @page_class.create
|
337
|
+
page.increment(:day_count => 1, :week_count => 2, :month_count => 3)
|
338
|
+
|
339
|
+
assert_page_counts page, 1, 2, 3
|
340
|
+
end
|
341
|
+
|
342
|
+
should "be able to decrement with modifier hashes" do
|
343
|
+
page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
|
344
|
+
page.decrement(:day_count => 1, :week_count => 2, :month_count => 3)
|
345
|
+
|
346
|
+
assert_page_counts page, 0, 0, 0
|
347
|
+
end
|
348
|
+
|
349
|
+
should "always decrement when decrement is called whether number is positive or negative" do
|
350
|
+
page = @page_class.create(:day_count => 1, :week_count => 2, :month_count => 3)
|
351
|
+
page.decrement(:day_count => -1, :week_count => 2, :month_count => -3)
|
352
|
+
|
353
|
+
assert_page_counts page, 0, 0, 0
|
354
|
+
end
|
355
|
+
|
356
|
+
should "be able to set with modifier hashes" do
|
357
|
+
page = @page_class.create(:title => 'Home')
|
358
|
+
page.set(:title => 'Home Revised')
|
359
|
+
|
360
|
+
page.reload
|
361
|
+
page.title.should == 'Home Revised'
|
362
|
+
end
|
363
|
+
|
364
|
+
should "be able to push with modifier hashes" do
|
365
|
+
page = @page_class.create
|
366
|
+
page.push(:tags => 'foo')
|
367
|
+
|
368
|
+
page.reload
|
369
|
+
page.tags.should == %w(foo)
|
370
|
+
end
|
371
|
+
|
372
|
+
should "be able to pull with criteria and modifier hashes" do
|
373
|
+
page = @page_class.create(:tags => %w(foo bar))
|
374
|
+
page.pull(:tags => 'foo')
|
375
|
+
|
376
|
+
page.reload
|
377
|
+
page.tags.should == %w(bar)
|
378
|
+
end
|
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
|
+
|
394
|
+
should "be able to push uniq with criteria and modifier hash" do
|
395
|
+
page = @page_class.create(:tags => 'foo')
|
396
|
+
page2 = @page_class.create
|
397
|
+
|
398
|
+
page.push_uniq(:tags => 'foo')
|
399
|
+
page.push_uniq(:tags => 'foo')
|
400
|
+
|
401
|
+
page.reload
|
402
|
+
page.tags.should == %w(foo)
|
403
|
+
|
404
|
+
page2.reload
|
405
|
+
page.tags.should == %w(foo)
|
406
|
+
end
|
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
|
416
|
+
end
|