mongo_mapper 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/mongo_mapper.rb +1 -1
- data/lib/mongo_mapper/document.rb +4 -0
- data/lib/mongo_mapper/embedded_document.rb +9 -1
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +4 -4
- data/lib/mongo_mapper/plugins/keys.rb +15 -19
- data/lib/mongo_mapper/plugins/modifiers.rb +4 -0
- data/lib/mongo_mapper/plugins/rails.rb +5 -1
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/query.rb +9 -4
- data/lib/mongo_mapper/support.rb +2 -4
- data/lib/mongo_mapper/version.rb +1 -1
- data/mongo_mapper.gemspec +6 -6
- data/test/active_model_lint_test.rb +2 -0
- data/test/functional/test_document.rb +32 -2
- data/test/functional/test_embedded_document.rb +70 -8
- data/test/functional/test_modifiers.rb +9 -1
- data/test/functional/test_validations.rb +44 -31
- data/test/test_helper.rb +1 -0
- data/test/unit/test_document.rb +0 -6
- data/test/unit/test_embedded_document.rb +1 -7
- data/test/unit/test_query.rb +80 -56
- data/test/unit/test_rails.rb +77 -19
- data/test/unit/test_support.rb +6 -2
- metadata +69 -34
data/test/unit/test_rails.rb
CHANGED
@@ -7,7 +7,7 @@ class TestRails < Test::Unit::TestCase
|
|
7
7
|
key :foo, String
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
context "Class methods" do
|
12
12
|
should "alias has_many to many" do
|
13
13
|
@klass.should respond_to(:has_many)
|
@@ -16,7 +16,7 @@ class TestRails < Test::Unit::TestCase
|
|
16
16
|
should "alias has_one to one" do
|
17
17
|
@klass.should respond_to(:has_one)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
should "have column names" do
|
21
21
|
@klass.column_names.sort.should == ['_id', 'foo']
|
22
22
|
end
|
@@ -25,48 +25,76 @@ class TestRails < Test::Unit::TestCase
|
|
25
25
|
@klass.human_name.should == 'Post'
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
context "Instance methods" do
|
30
30
|
setup do
|
31
31
|
@klass.class_eval do
|
32
32
|
def bar=(value)
|
33
33
|
write_attribute(:foo, value)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def bar_before_typecast
|
37
37
|
read_attribute_before_typecast(:foo)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def bar
|
41
41
|
read_attribute(:foo)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
should "alias new_record? to new?" do
|
47
47
|
@klass.new.should be_new_record
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
should "be able to read key with read_attribute" do
|
51
51
|
@klass.new(:foo => 'Bar').bar.should == 'Bar'
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
should "be able to read key before typecast with read_attribute_before_typecast" do
|
55
55
|
@klass.new(:foo => 21).bar_before_typecast.should == 21
|
56
56
|
@klass.new(:foo => 21).bar.should == '21'
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
should "be able to write key with write_attribute" do
|
60
60
|
@klass.new(:bar => 'Setting Foo').foo.should == 'Setting Foo'
|
61
61
|
end
|
62
|
+
|
63
|
+
context '#to_param' do
|
64
|
+
should "be nil if not persisted" do
|
65
|
+
@klass.new.tap do |doc|
|
66
|
+
doc.to_param.should be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
should "array representation of id if persisted" do
|
71
|
+
@klass.create.tap do |doc|
|
72
|
+
doc.to_param.should == doc.id.to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context '#to_key' do
|
78
|
+
should "be nil if not persisted" do
|
79
|
+
@klass.new.tap do |doc|
|
80
|
+
doc.to_key.should be_nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
should "array representation of id if persisted" do
|
85
|
+
@klass.create.tap do |doc|
|
86
|
+
doc.to_key.should == [doc.id]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
62
90
|
end
|
63
91
|
end
|
64
|
-
|
92
|
+
|
65
93
|
context "EmbeddedDocument" do
|
66
94
|
setup do
|
67
95
|
@klass = EDoc('Post') { key :foo, String }
|
68
96
|
end
|
69
|
-
|
97
|
+
|
70
98
|
context "Class methods" do
|
71
99
|
should "alias has_many to many" do
|
72
100
|
@klass.should respond_to(:has_many)
|
@@ -75,7 +103,7 @@ class TestRails < Test::Unit::TestCase
|
|
75
103
|
should "alias has_one to one" do
|
76
104
|
@klass.should respond_to(:has_one)
|
77
105
|
end
|
78
|
-
|
106
|
+
|
79
107
|
should "have column names" do
|
80
108
|
@klass.column_names.sort.should == ['_id', 'foo']
|
81
109
|
end
|
@@ -84,40 +112,70 @@ class TestRails < Test::Unit::TestCase
|
|
84
112
|
@klass.human_name.should == 'Post'
|
85
113
|
end
|
86
114
|
end
|
87
|
-
|
115
|
+
|
88
116
|
context "Instance methods" do
|
89
117
|
setup do
|
90
118
|
@klass.class_eval do
|
91
119
|
def bar=(value)
|
92
120
|
write_attribute(:foo, value)
|
93
121
|
end
|
94
|
-
|
122
|
+
|
95
123
|
def bar_before_typecast
|
96
124
|
read_attribute_before_typecast(:foo)
|
97
125
|
end
|
98
|
-
|
126
|
+
|
99
127
|
def bar
|
100
128
|
read_attribute(:foo)
|
101
129
|
end
|
102
130
|
end
|
103
131
|
end
|
104
|
-
|
132
|
+
|
105
133
|
should "alias new_record? to new?" do
|
106
134
|
@klass.new.should be_new_record
|
107
135
|
end
|
108
|
-
|
136
|
+
|
109
137
|
should "be able to read key with read_attribute" do
|
110
138
|
@klass.new(:foo => 'Bar').bar.should == 'Bar'
|
111
139
|
end
|
112
|
-
|
140
|
+
|
113
141
|
should "be able to read key before typecast with read_attribute_before_typecast" do
|
114
142
|
@klass.new(:foo => 21).bar_before_typecast.should == 21
|
115
143
|
@klass.new(:foo => 21).bar.should == '21'
|
116
144
|
end
|
117
|
-
|
145
|
+
|
118
146
|
should "be able to write key with write_attribute" do
|
119
147
|
@klass.new(:bar => 'Setting Foo').foo.should == 'Setting Foo'
|
120
148
|
end
|
149
|
+
|
150
|
+
context '#to_param' do
|
151
|
+
should "be nil if not persisted" do
|
152
|
+
@klass.new.tap do |doc|
|
153
|
+
doc.to_param.should be_nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
should "array representation of id if persisted" do
|
158
|
+
@klass.new.tap do |doc|
|
159
|
+
doc.expects(:persisted?).returns(true)
|
160
|
+
doc.to_param.should == doc.id.to_s
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context '#to_key' do
|
166
|
+
should "be nil if not persisted" do
|
167
|
+
@klass.new.tap do |doc|
|
168
|
+
doc.to_key.should be_nil
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
should "array representation of id if persisted" do
|
173
|
+
@klass.new.tap do |doc|
|
174
|
+
doc.expects(:persisted?).returns(true)
|
175
|
+
doc.to_key.should == [doc.id]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
121
179
|
end
|
122
180
|
end
|
123
181
|
end
|
data/test/unit/test_support.rb
CHANGED
@@ -60,6 +60,10 @@ class SupportTest < Test::Unit::TestCase
|
|
60
60
|
Boolean.to_mongo('0').should be_false
|
61
61
|
Boolean.to_mongo(0).should be_false
|
62
62
|
end
|
63
|
+
|
64
|
+
should "be nil for nil" do
|
65
|
+
Boolean.to_mongo(nil).should be_nil
|
66
|
+
end
|
63
67
|
end
|
64
68
|
|
65
69
|
context "Boolean#from_mongo" do
|
@@ -71,8 +75,8 @@ class SupportTest < Test::Unit::TestCase
|
|
71
75
|
Boolean.from_mongo(false).should be_false
|
72
76
|
end
|
73
77
|
|
74
|
-
should "be
|
75
|
-
Boolean.
|
78
|
+
should "be nil for nil" do
|
79
|
+
Boolean.to_mongo(nil).should be_nil
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 7
|
8
|
+
- 2
|
9
|
+
version: 0.7.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- John Nunemaker
|
@@ -9,79 +14,107 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-26 00:00:00 -04:00
|
13
18
|
default_executable: mmconsole
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: activesupport
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
- 4
|
31
|
+
version: 2.3.4
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: mongo
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - "="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 19
|
44
|
+
- 1
|
33
45
|
version: 0.19.1
|
34
|
-
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: jnunemaker-validatable
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - "="
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 8
|
58
|
+
- 3
|
43
59
|
version: 1.8.3
|
44
|
-
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
45
62
|
- !ruby/object:Gem::Dependency
|
46
63
|
name: jnunemaker-matchy
|
47
|
-
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
66
|
requirements:
|
51
67
|
- - "="
|
52
68
|
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
- 4
|
72
|
+
- 0
|
53
73
|
version: 0.4.0
|
54
|
-
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
55
76
|
- !ruby/object:Gem::Dependency
|
56
77
|
name: shoulda
|
57
|
-
|
58
|
-
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
60
80
|
requirements:
|
61
81
|
- - "="
|
62
82
|
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 2
|
85
|
+
- 10
|
86
|
+
- 2
|
63
87
|
version: 2.10.2
|
64
|
-
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id005
|
65
90
|
- !ruby/object:Gem::Dependency
|
66
91
|
name: timecop
|
67
|
-
|
68
|
-
|
69
|
-
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
prerelease: false
|
93
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
70
94
|
requirements:
|
71
95
|
- - "="
|
72
96
|
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
- 3
|
100
|
+
- 1
|
73
101
|
version: 0.3.1
|
74
|
-
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id006
|
75
104
|
- !ruby/object:Gem::Dependency
|
76
105
|
name: mocha
|
77
|
-
|
78
|
-
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
prerelease: false
|
107
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
80
108
|
requirements:
|
81
109
|
- - "="
|
82
110
|
- !ruby/object:Gem::Version
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
- 9
|
114
|
+
- 8
|
83
115
|
version: 0.9.8
|
84
|
-
|
116
|
+
type: :development
|
117
|
+
version_requirements: *id007
|
85
118
|
description:
|
86
119
|
email: nunemaker@gmail.com
|
87
120
|
executables:
|
@@ -203,18 +236,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
236
|
requirements:
|
204
237
|
- - ">="
|
205
238
|
- !ruby/object:Gem::Version
|
239
|
+
segments:
|
240
|
+
- 0
|
206
241
|
version: "0"
|
207
|
-
version:
|
208
242
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
243
|
requirements:
|
210
244
|
- - ">="
|
211
245
|
- !ruby/object:Gem::Version
|
246
|
+
segments:
|
247
|
+
- 0
|
212
248
|
version: "0"
|
213
|
-
version:
|
214
249
|
requirements: []
|
215
250
|
|
216
251
|
rubyforge_project:
|
217
|
-
rubygems_version: 1.3.
|
252
|
+
rubygems_version: 1.3.6
|
218
253
|
signing_key:
|
219
254
|
specification_version: 3
|
220
255
|
summary: A Ruby Object Mapper for Mongo
|