mongo_mapper 0.6.8 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -17
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongo_mapper/associations/base.rb +19 -10
- data/lib/mongo_mapper/associations/in_array_proxy.rb +137 -0
- data/lib/mongo_mapper/associations/one_proxy.rb +61 -0
- data/lib/mongo_mapper/associations/proxy.rb +0 -2
- data/lib/mongo_mapper/associations.rb +5 -3
- data/lib/mongo_mapper/callbacks.rb +30 -78
- data/lib/mongo_mapper/dirty.rb +5 -24
- data/lib/mongo_mapper/document.rb +117 -144
- data/lib/mongo_mapper/embedded_document.rb +7 -11
- data/lib/mongo_mapper/finder_options.rb +42 -30
- data/lib/mongo_mapper/mongo_mapper.rb +125 -0
- data/lib/mongo_mapper/pagination.rb +12 -1
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +1 -0
- data/lib/mongo_mapper/serialization.rb +2 -2
- data/lib/mongo_mapper/serializers/json_serializer.rb +2 -46
- data/lib/mongo_mapper/support.rb +5 -2
- data/lib/mongo_mapper/validations.rb +1 -3
- data/lib/mongo_mapper.rb +8 -2
- data/mongo_mapper.gemspec +14 -8
- data/specs.watchr +3 -5
- data/test/functional/associations/test_belongs_to_proxy.rb +43 -0
- data/test/functional/associations/test_in_array_proxy.rb +309 -0
- data/test/functional/associations/test_many_documents_proxy.rb +103 -53
- data/test/functional/associations/test_many_polymorphic_proxy.rb +4 -3
- data/test/functional/associations/test_one_proxy.rb +131 -0
- data/test/functional/test_binary.rb +15 -0
- data/test/functional/test_document.rb +581 -631
- data/test/functional/test_modifiers.rb +242 -0
- data/test/functional/test_validations.rb +0 -17
- data/test/models.rb +1 -1
- data/test/support/timing.rb +1 -1
- data/test/unit/associations/test_base.rb +54 -13
- data/test/unit/test_document.rb +32 -0
- data/test/unit/test_embedded_document.rb +0 -9
- data/test/unit/test_finder_options.rb +36 -7
- data/test/unit/test_pagination.rb +6 -0
- data/test/unit/test_rails_compatibility.rb +4 -1
- data/test/unit/test_support.rb +4 -0
- metadata +12 -6
- data/lib/mongo_mapper/observing.rb +0 -50
- data/test/unit/test_observing.rb +0 -101
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ModifierTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@page_class = Class.new do
|
6
|
+
include MongoMapper::Document
|
7
|
+
|
8
|
+
key :title, String
|
9
|
+
key :day_count, Integer, :default => 0
|
10
|
+
key :week_count, Integer, :default => 0
|
11
|
+
key :month_count, Integer, :default => 0
|
12
|
+
key :tags, Array
|
13
|
+
end
|
14
|
+
|
15
|
+
@page_class.collection.remove
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_page_counts(page, day_count, week_count, month_count)
|
19
|
+
page.reload
|
20
|
+
page.day_count.should == day_count
|
21
|
+
page.week_count.should == week_count
|
22
|
+
page.month_count.should == month_count
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be able to increment with criteria and modifier hashes" do
|
26
|
+
page = @page_class.create(:title => 'Home')
|
27
|
+
page2 = @page_class.create(:title => 'Home')
|
28
|
+
|
29
|
+
@page_class.increment({:title => 'Home'}, {
|
30
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
31
|
+
})
|
32
|
+
|
33
|
+
assert_page_counts page, 1, 2, 3
|
34
|
+
assert_page_counts page2, 1, 2, 3
|
35
|
+
end
|
36
|
+
|
37
|
+
should "be able to increment with ids and modifier hash" do
|
38
|
+
page = @page_class.create(:title => 'Home')
|
39
|
+
page2 = @page_class.create(:title => 'Home')
|
40
|
+
|
41
|
+
@page_class.increment(page.id, page2.id, {
|
42
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
43
|
+
})
|
44
|
+
|
45
|
+
assert_page_counts page, 1, 2, 3
|
46
|
+
assert_page_counts page2, 1, 2, 3
|
47
|
+
end
|
48
|
+
|
49
|
+
should "be able to decrement with criteria and modifier hashes" do
|
50
|
+
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
51
|
+
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
52
|
+
|
53
|
+
@page_class.decrement({:title => 'Home'}, {
|
54
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
55
|
+
})
|
56
|
+
|
57
|
+
assert_page_counts page, 0, 0, 0
|
58
|
+
assert_page_counts page2, 0, 0, 0
|
59
|
+
end
|
60
|
+
|
61
|
+
should "be able to decrement with ids and modifier hash" do
|
62
|
+
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
63
|
+
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
64
|
+
|
65
|
+
@page_class.decrement(page.id, page2.id, {
|
66
|
+
:day_count => 1, :week_count => 2, :month_count => 3
|
67
|
+
})
|
68
|
+
|
69
|
+
assert_page_counts page, 0, 0, 0
|
70
|
+
assert_page_counts page2, 0, 0, 0
|
71
|
+
end
|
72
|
+
|
73
|
+
should "always decrement when decrement is called whether number is positive or negative" do
|
74
|
+
page = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
75
|
+
page2 = @page_class.create(:title => 'Home', :day_count => 1, :week_count => 2, :month_count => 3)
|
76
|
+
|
77
|
+
@page_class.decrement(page.id, page2.id, {
|
78
|
+
:day_count => -1, :week_count => 2, :month_count => -3
|
79
|
+
})
|
80
|
+
|
81
|
+
assert_page_counts page, 0, 0, 0
|
82
|
+
assert_page_counts page2, 0, 0, 0
|
83
|
+
end
|
84
|
+
|
85
|
+
should "be able to set with criteria and modifier hashes" do
|
86
|
+
page = @page_class.create(:title => 'Home')
|
87
|
+
page2 = @page_class.create(:title => 'Home')
|
88
|
+
|
89
|
+
@page_class.set({:title => 'Home'}, :title => 'Home Revised')
|
90
|
+
|
91
|
+
page.reload
|
92
|
+
page.title.should == 'Home Revised'
|
93
|
+
|
94
|
+
page2.reload
|
95
|
+
page2.title.should == 'Home Revised'
|
96
|
+
end
|
97
|
+
|
98
|
+
should "be able to set with ids and modifier hash" do
|
99
|
+
page = @page_class.create(:title => 'Home')
|
100
|
+
page2 = @page_class.create(:title => 'Home')
|
101
|
+
|
102
|
+
@page_class.set(page.id, page2.id, :title => 'Home Revised')
|
103
|
+
|
104
|
+
page.reload
|
105
|
+
page.title.should == 'Home Revised'
|
106
|
+
|
107
|
+
page2.reload
|
108
|
+
page2.title.should == 'Home Revised'
|
109
|
+
end
|
110
|
+
|
111
|
+
should "be able to push with criteria and modifier hashes" do
|
112
|
+
page = @page_class.create(:title => 'Home')
|
113
|
+
page2 = @page_class.create(:title => 'Home')
|
114
|
+
|
115
|
+
@page_class.push({:title => 'Home'}, :tags => 'foo')
|
116
|
+
|
117
|
+
page.reload
|
118
|
+
page.tags.should == %w(foo)
|
119
|
+
|
120
|
+
page2.reload
|
121
|
+
page.tags.should == %w(foo)
|
122
|
+
end
|
123
|
+
|
124
|
+
should "be able to push with ids and modifier hash" do
|
125
|
+
page = @page_class.create(:title => 'Home')
|
126
|
+
page2 = @page_class.create(:title => 'Home')
|
127
|
+
|
128
|
+
@page_class.push(page.id, page2.id, :tags => 'foo')
|
129
|
+
|
130
|
+
page.reload
|
131
|
+
page.tags.should == %w(foo)
|
132
|
+
|
133
|
+
page2.reload
|
134
|
+
page.tags.should == %w(foo)
|
135
|
+
end
|
136
|
+
|
137
|
+
should "be able to push all with criteria and modifier hashes" do
|
138
|
+
page = @page_class.create(:title => 'Home')
|
139
|
+
page2 = @page_class.create(:title => 'Home')
|
140
|
+
tags = %w(foo bar)
|
141
|
+
|
142
|
+
@page_class.push_all({:title => 'Home'}, :tags => tags)
|
143
|
+
|
144
|
+
page.reload
|
145
|
+
page.tags.should == tags
|
146
|
+
|
147
|
+
page2.reload
|
148
|
+
page.tags.should == tags
|
149
|
+
end
|
150
|
+
|
151
|
+
should "be able to push all with ids and modifier hash" do
|
152
|
+
page = @page_class.create(:title => 'Home')
|
153
|
+
page2 = @page_class.create(:title => 'Home')
|
154
|
+
tags = %w(foo bar)
|
155
|
+
|
156
|
+
@page_class.push_all(page.id, page2.id, :tags => tags)
|
157
|
+
|
158
|
+
page.reload
|
159
|
+
page.tags.should == tags
|
160
|
+
|
161
|
+
page2.reload
|
162
|
+
page.tags.should == tags
|
163
|
+
end
|
164
|
+
|
165
|
+
should "be able to pull with criteria and modifier hashes" do
|
166
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
167
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
168
|
+
|
169
|
+
@page_class.pull({:title => 'Home'}, :tags => 'foo')
|
170
|
+
|
171
|
+
page.reload
|
172
|
+
page.tags.should == %w(bar)
|
173
|
+
|
174
|
+
page2.reload
|
175
|
+
page.tags.should == %w(bar)
|
176
|
+
end
|
177
|
+
|
178
|
+
should "be able to pull with ids and modifier hash" do
|
179
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
180
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar))
|
181
|
+
|
182
|
+
@page_class.pull(page.id, page2.id, :tags => 'foo')
|
183
|
+
|
184
|
+
page.reload
|
185
|
+
page.tags.should == %w(bar)
|
186
|
+
|
187
|
+
page2.reload
|
188
|
+
page.tags.should == %w(bar)
|
189
|
+
end
|
190
|
+
|
191
|
+
should "be able to pull all with criteria and modifier hashes" do
|
192
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
193
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
194
|
+
|
195
|
+
@page_class.pull_all({:title => 'Home'}, :tags => %w(foo bar))
|
196
|
+
|
197
|
+
page.reload
|
198
|
+
page.tags.should == %w(baz)
|
199
|
+
|
200
|
+
page2.reload
|
201
|
+
page.tags.should == %w(baz)
|
202
|
+
end
|
203
|
+
|
204
|
+
should "be able to pull all with ids and modifier hash" do
|
205
|
+
page = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
206
|
+
page2 = @page_class.create(:title => 'Home', :tags => %w(foo bar baz))
|
207
|
+
|
208
|
+
@page_class.pull_all(page.id, page2.id, :tags => %w(foo bar))
|
209
|
+
|
210
|
+
page.reload
|
211
|
+
page.tags.should == %w(baz)
|
212
|
+
|
213
|
+
page2.reload
|
214
|
+
page.tags.should == %w(baz)
|
215
|
+
end
|
216
|
+
|
217
|
+
should "be able to push uniq with criteria and modifier hash" do
|
218
|
+
page = @page_class.create(:title => 'Home', :tags => 'foo')
|
219
|
+
page2 = @page_class.create(:title => 'Home')
|
220
|
+
|
221
|
+
@page_class.push_uniq({:title => 'Home'}, :tags => 'foo')
|
222
|
+
|
223
|
+
page.reload
|
224
|
+
page.tags.should == %w(foo)
|
225
|
+
|
226
|
+
page2.reload
|
227
|
+
page.tags.should == %w(foo)
|
228
|
+
end
|
229
|
+
|
230
|
+
should "be able to push uniq with ids and modifier hash" do
|
231
|
+
page = @page_class.create(:title => 'Home', :tags => 'foo')
|
232
|
+
page2 = @page_class.create(:title => 'Home')
|
233
|
+
|
234
|
+
@page_class.push_uniq(page.id, page2.id, :tags => 'foo')
|
235
|
+
|
236
|
+
page.reload
|
237
|
+
page.tags.should == %w(foo)
|
238
|
+
|
239
|
+
page2.reload
|
240
|
+
page.tags.should == %w(foo)
|
241
|
+
end
|
242
|
+
end
|
@@ -25,23 +25,6 @@ class ValidationsTest < Test::Unit::TestCase
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context "Skipping validations when saving" do
|
29
|
-
setup do
|
30
|
-
@document = Class.new do
|
31
|
-
include MongoMapper::Document
|
32
|
-
set_collection_name 'test'
|
33
|
-
key :name, String, :required => true
|
34
|
-
end
|
35
|
-
@document.collection.remove
|
36
|
-
end
|
37
|
-
|
38
|
-
should "insert document" do
|
39
|
-
doc = @document.new
|
40
|
-
doc.save(false)
|
41
|
-
@document.count.should == 1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
28
|
context "Saving a document that is invalid (destructive)" do
|
46
29
|
setup do
|
47
30
|
@document = Class.new do
|
data/test/models.rb
CHANGED
data/test/support/timing.rb
CHANGED
@@ -50,23 +50,17 @@ class AssociationBaseTest < Test::Unit::TestCase
|
|
50
50
|
|
51
51
|
should "be false if not many" do
|
52
52
|
Base.new(:belongs_to, :foo).many?.should be_false
|
53
|
+
Base.new(:one, :foo).many?.should be_false
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
context "
|
57
|
-
should "
|
58
|
-
|
59
|
-
base.finder_options.should == {}
|
57
|
+
context "one?" do
|
58
|
+
should "be true if one" do
|
59
|
+
Base.new(:one, :foo).one?.should be_true
|
60
60
|
end
|
61
61
|
|
62
|
-
should "
|
63
|
-
|
64
|
-
base.finder_options.should == {:order => 'position'}
|
65
|
-
end
|
66
|
-
|
67
|
-
should "correctly parse from options" do
|
68
|
-
base = Base.new(:many, :foos, :order => 'position', :somekey => 'somevalue')
|
69
|
-
base.finder_options.should == {:order => 'position', :somekey => 'somevalue'}
|
62
|
+
should "be false if not one" do
|
63
|
+
Base.new(:many, :foo).one?.should be_false
|
70
64
|
end
|
71
65
|
end
|
72
66
|
|
@@ -90,6 +84,43 @@ class AssociationBaseTest < Test::Unit::TestCase
|
|
90
84
|
end
|
91
85
|
end
|
92
86
|
|
87
|
+
context "as?" do
|
88
|
+
should "be true if one" do
|
89
|
+
Base.new(:one, :foo, :as => :commentable).as?.should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
should "be false if not one" do
|
93
|
+
Base.new(:many, :foo).as?.should be_false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "in_array?" do
|
98
|
+
should "be true if one" do
|
99
|
+
Base.new(:one, :foo, :in => :list_ids).in_array?.should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
should "be false if not one" do
|
103
|
+
Base.new(:many, :foo).in_array?.should be_false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "finder_options" do
|
108
|
+
should "default to empty hash" do
|
109
|
+
base = Base.new(:many, :foos)
|
110
|
+
base.finder_options.should == {}
|
111
|
+
end
|
112
|
+
|
113
|
+
should "work with order" do
|
114
|
+
base = Base.new(:many, :foos, :order => 'position')
|
115
|
+
base.finder_options.should == {:order => 'position'}
|
116
|
+
end
|
117
|
+
|
118
|
+
should "correctly parse from options" do
|
119
|
+
base = Base.new(:many, :foos, :order => 'position', :somekey => 'somevalue')
|
120
|
+
base.finder_options.should == {:order => 'position', :somekey => 'somevalue'}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
93
124
|
context "type_key_name" do
|
94
125
|
should "be _type for many" do
|
95
126
|
Base.new(:many, :foos).type_key_name.should == '_type'
|
@@ -101,7 +132,7 @@ class AssociationBaseTest < Test::Unit::TestCase
|
|
101
132
|
end
|
102
133
|
|
103
134
|
context "foreign_key" do
|
104
|
-
should "default to
|
135
|
+
should "default to assocation name _id for belongs to" do
|
105
136
|
base = Base.new(:belongs_to, :foo)
|
106
137
|
base.foreign_key.should == 'foo_id'
|
107
138
|
end
|
@@ -161,6 +192,16 @@ class AssociationBaseTest < Test::Unit::TestCase
|
|
161
192
|
base = Base.new(:belongs_to, :target, :polymorphic => true)
|
162
193
|
base.proxy_class.should == BelongsToPolymorphicProxy
|
163
194
|
end
|
195
|
+
|
196
|
+
should "be OneProxy for one" do
|
197
|
+
base = Base.new(:one, :target, :polymorphic => true)
|
198
|
+
base.proxy_class.should == OneProxy
|
199
|
+
end
|
200
|
+
|
201
|
+
should "be InArrayProxy for many with :in option" do
|
202
|
+
base = Base.new(:many, :messages, :in => :message_ids)
|
203
|
+
base.proxy_class.should == InArrayProxy
|
204
|
+
end
|
164
205
|
end
|
165
206
|
|
166
207
|
end
|
data/test/unit/test_document.rb
CHANGED
@@ -72,6 +72,38 @@ class DocumentTest < Test::Unit::TestCase
|
|
72
72
|
@document.collection.should be_instance_of(Mongo::Collection)
|
73
73
|
@document.collection.name.should == 'foobar'
|
74
74
|
end
|
75
|
+
|
76
|
+
should 'allow extensions to Document to be appended' do
|
77
|
+
module Extension; def test_this_extension; end end
|
78
|
+
MongoMapper::Document.append_extensions(Extension)
|
79
|
+
article = Class.new { include MongoMapper::Document }
|
80
|
+
|
81
|
+
article.should respond_to(:test_this_extension)
|
82
|
+
end
|
83
|
+
|
84
|
+
should 'add appended extensions to classes that include Document before they are added' do
|
85
|
+
module Extension; def test_this_extension; end end
|
86
|
+
article = Class.new { include MongoMapper::Document }
|
87
|
+
MongoMapper::Document.append_extensions(Extension)
|
88
|
+
|
89
|
+
article.should respond_to(:test_this_extension)
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'allow inclusions to Document to be appended' do
|
93
|
+
module Inclusion; def test_this_inclusion; end end
|
94
|
+
MongoMapper::Document.append_inclusions(Inclusion)
|
95
|
+
article = Class.new { include MongoMapper::Document }
|
96
|
+
|
97
|
+
article.new.should respond_to(:test_this_inclusion)
|
98
|
+
end
|
99
|
+
|
100
|
+
should 'add appended inclusions to classes that include Document before they are added' do
|
101
|
+
module Inclusion; def test_this_inclusion; end end
|
102
|
+
article = Class.new { include MongoMapper::Document }
|
103
|
+
MongoMapper::Document.append_inclusions(Inclusion)
|
104
|
+
|
105
|
+
article.new.should respond_to(:test_this_inclusion)
|
106
|
+
end
|
75
107
|
end # Document class
|
76
108
|
|
77
109
|
context "Documents that inherit from other documents" do
|
@@ -580,15 +580,6 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
580
580
|
doc.instance_variable_get("@foo").should == []
|
581
581
|
end
|
582
582
|
|
583
|
-
should "not set instance variable if frozen" do
|
584
|
-
@document.key :foo, Array
|
585
|
-
doc = @document.new
|
586
|
-
doc.instance_variable_get("@foo").should be_nil
|
587
|
-
doc.freeze
|
588
|
-
doc.foo
|
589
|
-
doc.instance_variable_get("@foo").should be_nil
|
590
|
-
end
|
591
|
-
|
592
583
|
should "be overrideable by modules" do
|
593
584
|
@document = Class.new do
|
594
585
|
include MongoMapper::Document
|
@@ -30,6 +30,13 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
+
should "automatically add _type to query if model is single collection inherited" do
|
34
|
+
FinderOptions.new(Enter, :foo => 'bar').criteria.should == {
|
35
|
+
:foo => 'bar',
|
36
|
+
:_type => 'Enter'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
33
40
|
%w{gt lt gte lte ne in nin mod size where exists}.each do |operator|
|
34
41
|
should "convert #{operator} conditions" do
|
35
42
|
FinderOptions.new(Room, :age.send(operator) => 21).criteria.should == {
|
@@ -38,13 +45,6 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
41
|
-
should "automatically add _type to query if model is single collection inherited" do
|
42
|
-
FinderOptions.new(Enter, :foo => 'bar').criteria.should == {
|
43
|
-
:foo => 'bar',
|
44
|
-
:_type => 'Enter'
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
48
|
should "work with simple criteria" do
|
49
49
|
FinderOptions.new(Room, :foo => 'bar').criteria.should == {
|
50
50
|
:foo => 'bar'
|
@@ -61,6 +61,13 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
61
61
|
FinderOptions.new(Room, :id => id).criteria.should == {:_id => id}
|
62
62
|
end
|
63
63
|
|
64
|
+
should "convert id with symbol operator to _id with modifier" do
|
65
|
+
id = Mongo::ObjectID.new
|
66
|
+
FinderOptions.new(Room, :id.ne => id).criteria.should == {
|
67
|
+
:_id => {'$ne' => id}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
64
71
|
should "make sure that _id's are object ids" do
|
65
72
|
id = Mongo::ObjectID.new
|
66
73
|
FinderOptions.new(Room, :_id => id.to_s).criteria.should == {:_id => id}
|
@@ -81,6 +88,19 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
81
88
|
FinderOptions.new(Message, :room_id => id).criteria.should == {:room_id => id}
|
82
89
|
end
|
83
90
|
|
91
|
+
should "convert times to utc if they aren't already" do
|
92
|
+
time = Time.now.in_time_zone('Indiana (East)')
|
93
|
+
criteria = FinderOptions.new(Room, :created_at => time).criteria
|
94
|
+
criteria[:created_at].utc?.should be_true
|
95
|
+
end
|
96
|
+
|
97
|
+
should "not funk with times already in utc" do
|
98
|
+
time = Time.now.utc
|
99
|
+
criteria = FinderOptions.new(Room, :created_at => time).criteria
|
100
|
+
criteria[:created_at].utc?.should be_true
|
101
|
+
criteria[:created_at].should == time
|
102
|
+
end
|
103
|
+
|
84
104
|
should "use $in for arrays" do
|
85
105
|
FinderOptions.new(Room, :foo => [1,2,3]).criteria.should == {
|
86
106
|
:foo => {'$in' => [1,2,3]}
|
@@ -121,6 +141,15 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
121
141
|
FinderOptions.new(Room, :order => 'foo DESC').options[:sort].should == sort
|
122
142
|
end
|
123
143
|
|
144
|
+
should "convert order operators to mongo sort" do
|
145
|
+
FinderOptions.new(Room, :order => :foo.asc).options[:sort].should == [['foo', 1]]
|
146
|
+
FinderOptions.new(Room, :order => :foo.desc).options[:sort].should == [['foo', -1]]
|
147
|
+
end
|
148
|
+
|
149
|
+
should "convert array of order operators to mongo sort" do
|
150
|
+
FinderOptions.new(Room, :order => [:foo.asc, :bar.desc]).options[:sort].should == [['foo', 1], ['bar', -1]]
|
151
|
+
end
|
152
|
+
|
124
153
|
should "convert field without direction to ascending" do
|
125
154
|
sort = [['foo', 1]]
|
126
155
|
FinderOptions.new(Room, :order => 'foo').options[:sort].should == sort
|
@@ -62,6 +62,12 @@ class PaginationTest < Test::Unit::TestCase
|
|
62
62
|
should "alias offset to skip" do
|
63
63
|
PaginationProxy.new(25, 2, 10).offset.should == 10
|
64
64
|
end
|
65
|
+
|
66
|
+
should "return true for === Array" do
|
67
|
+
collection = PaginationProxy.new(25, 2, 10)
|
68
|
+
collection.subject = [1, 2]
|
69
|
+
collection.should === Array
|
70
|
+
end
|
65
71
|
|
66
72
|
context "previous_page" do
|
67
73
|
should "be nil if current page 1" do
|
@@ -22,7 +22,10 @@ class TestRailsCompatibility < Test::Unit::TestCase
|
|
22
22
|
context "EmbeddedDocument" do
|
23
23
|
should "alias many to has_many" do
|
24
24
|
FirstItem.should respond_to(:has_many)
|
25
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
should "alias one to has_one" do
|
28
|
+
FirstItem.should respond_to(:has_one)
|
26
29
|
end
|
27
30
|
|
28
31
|
should "have column names" do
|
data/test/unit/test_support.rb
CHANGED
@@ -167,6 +167,10 @@ class SupportTest < Test::Unit::TestCase
|
|
167
167
|
ObjectId.to_mongo(nil).should be_nil
|
168
168
|
end
|
169
169
|
|
170
|
+
should "return nil if blank string" do
|
171
|
+
ObjectId.to_mongo('').should be_nil
|
172
|
+
end
|
173
|
+
|
170
174
|
should "return value if object id" do
|
171
175
|
id = Mongo::ObjectID.new
|
172
176
|
ObjectId.to_mongo(id).should be(id)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-01 00:00:00 -05:00
|
13
13
|
default_executable: mmconsole
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.18.
|
33
|
+
version: 0.18.2
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: jnunemaker-validatable
|
@@ -104,11 +104,13 @@ files:
|
|
104
104
|
- lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
|
105
105
|
- lib/mongo_mapper/associations/belongs_to_proxy.rb
|
106
106
|
- lib/mongo_mapper/associations/collection.rb
|
107
|
+
- lib/mongo_mapper/associations/in_array_proxy.rb
|
107
108
|
- lib/mongo_mapper/associations/many_documents_as_proxy.rb
|
108
109
|
- lib/mongo_mapper/associations/many_documents_proxy.rb
|
109
110
|
- lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
|
110
111
|
- lib/mongo_mapper/associations/many_embedded_proxy.rb
|
111
112
|
- lib/mongo_mapper/associations/many_polymorphic_proxy.rb
|
113
|
+
- lib/mongo_mapper/associations/one_proxy.rb
|
112
114
|
- lib/mongo_mapper/associations/proxy.rb
|
113
115
|
- lib/mongo_mapper/callbacks.rb
|
114
116
|
- lib/mongo_mapper/dirty.rb
|
@@ -117,7 +119,7 @@ files:
|
|
117
119
|
- lib/mongo_mapper/embedded_document.rb
|
118
120
|
- lib/mongo_mapper/finder_options.rb
|
119
121
|
- lib/mongo_mapper/key.rb
|
120
|
-
- lib/mongo_mapper/
|
122
|
+
- lib/mongo_mapper/mongo_mapper.rb
|
121
123
|
- lib/mongo_mapper/pagination.rb
|
122
124
|
- lib/mongo_mapper/rails_compatibility/document.rb
|
123
125
|
- lib/mongo_mapper/rails_compatibility/embedded_document.rb
|
@@ -130,11 +132,13 @@ files:
|
|
130
132
|
- test/NOTE_ON_TESTING
|
131
133
|
- test/functional/associations/test_belongs_to_polymorphic_proxy.rb
|
132
134
|
- test/functional/associations/test_belongs_to_proxy.rb
|
135
|
+
- test/functional/associations/test_in_array_proxy.rb
|
133
136
|
- test/functional/associations/test_many_documents_as_proxy.rb
|
134
137
|
- test/functional/associations/test_many_documents_proxy.rb
|
135
138
|
- test/functional/associations/test_many_embedded_polymorphic_proxy.rb
|
136
139
|
- test/functional/associations/test_many_embedded_proxy.rb
|
137
140
|
- test/functional/associations/test_many_polymorphic_proxy.rb
|
141
|
+
- test/functional/associations/test_one_proxy.rb
|
138
142
|
- test/functional/test_associations.rb
|
139
143
|
- test/functional/test_binary.rb
|
140
144
|
- test/functional/test_callbacks.rb
|
@@ -142,6 +146,7 @@ files:
|
|
142
146
|
- test/functional/test_document.rb
|
143
147
|
- test/functional/test_embedded_document.rb
|
144
148
|
- test/functional/test_logger.rb
|
149
|
+
- test/functional/test_modifiers.rb
|
145
150
|
- test/functional/test_pagination.rb
|
146
151
|
- test/functional/test_rails_compatibility.rb
|
147
152
|
- test/functional/test_string_id_compatibility.rb
|
@@ -159,7 +164,6 @@ files:
|
|
159
164
|
- test/unit/test_finder_options.rb
|
160
165
|
- test/unit/test_key.rb
|
161
166
|
- test/unit/test_mongo_mapper.rb
|
162
|
-
- test/unit/test_observing.rb
|
163
167
|
- test/unit/test_pagination.rb
|
164
168
|
- test/unit/test_rails_compatibility.rb
|
165
169
|
- test/unit/test_serializations.rb
|
@@ -197,11 +201,13 @@ summary: Awesome gem for modeling your domain and storing it in mongo
|
|
197
201
|
test_files:
|
198
202
|
- test/functional/associations/test_belongs_to_polymorphic_proxy.rb
|
199
203
|
- test/functional/associations/test_belongs_to_proxy.rb
|
204
|
+
- test/functional/associations/test_in_array_proxy.rb
|
200
205
|
- test/functional/associations/test_many_documents_as_proxy.rb
|
201
206
|
- test/functional/associations/test_many_documents_proxy.rb
|
202
207
|
- test/functional/associations/test_many_embedded_polymorphic_proxy.rb
|
203
208
|
- test/functional/associations/test_many_embedded_proxy.rb
|
204
209
|
- test/functional/associations/test_many_polymorphic_proxy.rb
|
210
|
+
- test/functional/associations/test_one_proxy.rb
|
205
211
|
- test/functional/test_associations.rb
|
206
212
|
- test/functional/test_binary.rb
|
207
213
|
- test/functional/test_callbacks.rb
|
@@ -209,6 +215,7 @@ test_files:
|
|
209
215
|
- test/functional/test_document.rb
|
210
216
|
- test/functional/test_embedded_document.rb
|
211
217
|
- test/functional/test_logger.rb
|
218
|
+
- test/functional/test_modifiers.rb
|
212
219
|
- test/functional/test_pagination.rb
|
213
220
|
- test/functional/test_rails_compatibility.rb
|
214
221
|
- test/functional/test_string_id_compatibility.rb
|
@@ -226,7 +233,6 @@ test_files:
|
|
226
233
|
- test/unit/test_finder_options.rb
|
227
234
|
- test/unit/test_key.rb
|
228
235
|
- test/unit/test_mongo_mapper.rb
|
229
|
-
- test/unit/test_observing.rb
|
230
236
|
- test/unit/test_pagination.rb
|
231
237
|
- test/unit/test_rails_compatibility.rb
|
232
238
|
- test/unit/test_serializations.rb
|