mongo_mapper 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -1
- data/Rakefile +9 -12
- data/lib/mongo_mapper.rb +30 -10
- data/lib/mongo_mapper/document.rb +16 -74
- data/lib/mongo_mapper/embedded_document.rb +7 -1
- data/lib/mongo_mapper/plugins.rb +3 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -12
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +6 -1
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +4 -1
- data/lib/mongo_mapper/plugins/callbacks.rb +183 -12
- data/lib/mongo_mapper/plugins/keys.rb +17 -5
- data/lib/mongo_mapper/plugins/modifiers.rb +87 -0
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +7 -3
- data/lib/mongo_mapper/plugins/protected.rb +1 -1
- 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/query.rb +1 -1
- data/lib/mongo_mapper/version.rb +3 -0
- data/mongo_mapper.gemspec +22 -11
- data/test/active_model_lint_test.rb +11 -0
- data/test/functional/associations/test_in_array_proxy.rb +16 -0
- data/test/functional/associations/test_many_documents_proxy.rb +22 -0
- data/test/functional/test_callbacks.rb +104 -34
- data/test/functional/test_document.rb +70 -149
- data/test/functional/test_embedded_document.rb +39 -34
- data/test/functional/test_indexing.rb +44 -0
- data/test/functional/test_modifiers.rb +297 -227
- data/test/functional/test_protected.rb +11 -5
- 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/unit/serializers/test_json_serializer.rb +30 -17
- data/test/unit/test_embedded_document.rb +15 -15
- data/test/unit/test_keys.rb +15 -11
- data/test/unit/test_mongo_mapper.rb +31 -1
- data/test/unit/test_pagination.rb +33 -0
- data/test/unit/test_query.rb +6 -0
- data/test/unit/test_serialization.rb +3 -3
- data/test/unit/test_support.rb +9 -5
- metadata +17 -6
- data/VERSION +0 -1
@@ -3,51 +3,56 @@ require 'models'
|
|
3
3
|
|
4
4
|
class EmbeddedDocumentTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@klass = Doc do
|
7
|
-
key :
|
8
|
-
key :last_name, String
|
6
|
+
@klass = Doc('Person') do
|
7
|
+
key :name, String
|
9
8
|
end
|
10
|
-
|
11
|
-
@pet_klass = EDoc do
|
9
|
+
|
10
|
+
@pet_klass = EDoc('Pet') do
|
12
11
|
key :name, String
|
13
12
|
end
|
14
|
-
|
13
|
+
|
15
14
|
@klass.many :pets, :class => @pet_klass
|
16
|
-
|
17
|
-
@address_class = EDoc do
|
15
|
+
|
16
|
+
@address_class = EDoc('Address') do
|
18
17
|
key :city, String
|
19
18
|
key :state, String
|
20
19
|
end
|
21
20
|
end
|
22
|
-
|
23
|
-
context "Saving a document with an embedded document" do
|
21
|
+
|
22
|
+
context "Saving a document with a key that is an embedded document" do
|
24
23
|
setup do
|
25
24
|
@klass.key :foo, @address_class
|
26
|
-
|
27
|
-
@address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
28
|
-
@doc = @klass.new(:foo => @address)
|
29
25
|
end
|
30
|
-
|
26
|
+
|
31
27
|
should "embed embedded document" do
|
32
|
-
@
|
33
|
-
@
|
34
|
-
|
28
|
+
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
29
|
+
doc = @klass.create(:foo => address)
|
30
|
+
doc.foo.city.should == 'South Bend'
|
31
|
+
doc.foo.state.should == 'IN'
|
35
32
|
|
36
|
-
doc =
|
33
|
+
doc = doc.reload
|
37
34
|
doc.foo.city.should == 'South Bend'
|
38
35
|
doc.foo.state.should == 'IN'
|
39
36
|
end
|
37
|
+
|
38
|
+
should "assign _parent_document and _root_document" do
|
39
|
+
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
40
|
+
address._parent_document.should be_nil
|
41
|
+
doc = @klass.create(:foo => address)
|
42
|
+
address._parent_document.should be(doc)
|
43
|
+
address._root_document.should be(doc)
|
44
|
+
end
|
40
45
|
end
|
41
|
-
|
46
|
+
|
42
47
|
should "correctly instantiate single collection inherited embedded documents" do
|
43
48
|
document = Doc('Foo') do
|
44
49
|
key :message, Message
|
45
50
|
end
|
46
|
-
|
51
|
+
|
47
52
|
doc1 = document.create(:message => Enter.new)
|
48
53
|
doc1.reload.message.class.should be(Enter)
|
49
54
|
end
|
50
|
-
|
55
|
+
|
51
56
|
context "new?" do
|
52
57
|
setup do
|
53
58
|
@klass.key :foo, @address_class
|
@@ -58,65 +63,65 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
58
63
|
doc = @klass.new(:foo => address)
|
59
64
|
address.new?.should == true
|
60
65
|
end
|
61
|
-
|
66
|
+
|
62
67
|
should "not be new after document is saved" do
|
63
68
|
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
64
69
|
doc = @klass.new(:foo => address)
|
65
70
|
doc.save
|
66
71
|
doc.foo.new?.should == false
|
67
72
|
end
|
68
|
-
|
73
|
+
|
69
74
|
should "not be new when document is read back" do
|
70
75
|
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
71
76
|
doc = @klass.new(:foo => address)
|
72
77
|
doc.save
|
73
|
-
|
78
|
+
|
74
79
|
doc = doc.reload
|
75
80
|
doc.foo.new?.should == false
|
76
81
|
end
|
77
82
|
end
|
78
|
-
|
83
|
+
|
79
84
|
should "be able to save" do
|
80
85
|
person = @klass.create
|
81
|
-
|
86
|
+
|
82
87
|
pet = @pet_klass.new(:name => 'sparky')
|
83
88
|
person.pets << pet
|
84
89
|
pet.should be_new
|
85
90
|
pet.save
|
86
91
|
pet.should_not be_new
|
87
|
-
|
92
|
+
|
88
93
|
person.reload
|
89
94
|
person.pets.first.should == pet
|
90
95
|
end
|
91
|
-
|
96
|
+
|
92
97
|
should "be able to dynamically add new keys and save" do
|
93
98
|
person = @klass.create
|
94
|
-
|
99
|
+
|
95
100
|
pet = @pet_klass.new(:name => 'sparky', :crazy_key => 'crazy')
|
96
101
|
person.pets << pet
|
97
102
|
pet.save
|
98
|
-
|
103
|
+
|
99
104
|
person.reload
|
100
105
|
person.pets.first.crazy_key.should == 'crazy'
|
101
106
|
end
|
102
|
-
|
107
|
+
|
103
108
|
should "be able to update_attributes" do
|
104
109
|
pet = @pet_klass.new(:name => 'sparky')
|
105
110
|
person = @klass.create(:pets => [pet])
|
106
111
|
person.reload
|
107
112
|
pet = person.pets.first
|
108
|
-
|
113
|
+
|
109
114
|
pet.update_attributes(:name => 'koda').should be_true
|
110
115
|
person.reload
|
111
116
|
person.pets.first._id.should == pet._id
|
112
117
|
person.pets.first.name.should == 'koda'
|
113
118
|
end
|
114
|
-
|
119
|
+
|
115
120
|
should "be able to update_attributes!" do
|
116
121
|
person = @klass.create(:pets => [@pet_klass.new(:name => 'sparky')])
|
117
122
|
person.reload
|
118
123
|
pet = person.pets.first
|
119
|
-
|
124
|
+
|
120
125
|
attributes = {:name => 'koda'}
|
121
126
|
pet.expects(:attributes=).with(attributes)
|
122
127
|
pet.expects(:save!)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class IndexingTest < Test::Unit::TestCase
|
4
|
+
context "Indexing" do
|
5
|
+
setup do
|
6
|
+
@document = 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
|
+
drop_indexes(@document)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "allow creating index for a key" do
|
18
|
+
@document.ensure_index :first_name
|
19
|
+
@document.should have_index('first_name_1')
|
20
|
+
end
|
21
|
+
|
22
|
+
should "allow creating unique index for a key" do
|
23
|
+
@document.ensure_index :first_name, :unique => true
|
24
|
+
@document.should have_index('first_name_1')
|
25
|
+
end
|
26
|
+
|
27
|
+
should "allow creating index on multiple keys" do
|
28
|
+
@document.ensure_index [[:first_name, 1], [:last_name, -1]]
|
29
|
+
|
30
|
+
# order is different for different versions of ruby so instead of
|
31
|
+
# just checking have_index('first_name_1_last_name_-1') I'm checking
|
32
|
+
# the values of the indexes to make sure the index creation was successful
|
33
|
+
@document.collection.index_information.detect do |index|
|
34
|
+
keys = index[1]
|
35
|
+
keys.include?(['first_name', 1]) && keys.include?(['last_name', -1])
|
36
|
+
end.should_not be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
should "work with :index shortcut when defining key" do
|
40
|
+
@document.key :father, String, :index => true
|
41
|
+
@document.should have_index('father_1')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -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
|