mongo_mapper-unstable 2010.2.28 → 2010.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/lib/mongo_mapper/document.rb +3 -72
- data/lib/mongo_mapper/plugins/callbacks.rb +14 -3
- data/lib/mongo_mapper/plugins/keys.rb +9 -4
- data/lib/mongo_mapper/plugins/modifiers.rb +87 -0
- 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/plugins.rb +3 -0
- data/lib/mongo_mapper.rb +2 -2
- data/test/active_model_lint_test.rb +11 -0
- data/test/functional/test_document.rb +0 -116
- data/test/functional/test_embedded_document.rb +17 -12
- data/test/functional/test_indexing.rb +44 -0
- data/test/functional/test_modifiers.rb +297 -227
- 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/test_helper.rb +0 -4
- data/test/unit/serializers/test_json_serializer.rb +30 -17
- data/test/unit/test_serialization.rb +3 -3
- metadata +80 -35
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'active_support/version'
|
2
3
|
|
3
4
|
class JsonSerializationTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# Helper function in case things change in the future
|
7
|
+
# - replacing all those to_json calls was a nightmare
|
8
|
+
def convert_to_json object, options = {}
|
9
|
+
ActiveSupport::JSON.encode(object, options)
|
10
|
+
end
|
11
|
+
|
4
12
|
class Tag
|
5
13
|
include MongoMapper::EmbeddedDocument
|
6
14
|
key :name, String
|
@@ -30,11 +38,11 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
30
38
|
|
31
39
|
should "include demodulized root" do
|
32
40
|
Contact.include_root_in_json = true
|
33
|
-
assert_match %r{^\{"contact"
|
41
|
+
assert_match %r{^\{"contact":\s?\{}, convert_to_json(@contact)
|
34
42
|
end
|
35
43
|
|
36
44
|
should "encode all encodable attributes" do
|
37
|
-
json = @contact
|
45
|
+
json = convert_to_json(@contact)
|
38
46
|
|
39
47
|
assert_no_match %r{"_id"}, json
|
40
48
|
assert_match %r{"name":"Konata Izumi"}, json
|
@@ -45,7 +53,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
45
53
|
end
|
46
54
|
|
47
55
|
should "allow attribute filtering with only" do
|
48
|
-
json = @contact
|
56
|
+
json = convert_to_json(@contact, :only => [:name, :age])
|
49
57
|
|
50
58
|
assert_no_match %r{"_id"}, json
|
51
59
|
assert_match %r{"name":"Konata Izumi"}, json
|
@@ -56,7 +64,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
56
64
|
end
|
57
65
|
|
58
66
|
should "allow attribute filtering with except" do
|
59
|
-
json = @contact
|
67
|
+
json = convert_to_json(@contact, :except => [:name, :age])
|
60
68
|
|
61
69
|
assert_no_match %r{"_id"}, json
|
62
70
|
assert_no_match %r{"name"}, json
|
@@ -68,12 +76,12 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
68
76
|
|
69
77
|
context "_id key" do
|
70
78
|
should "not be included by default" do
|
71
|
-
json = @contact
|
79
|
+
json = convert_to_json(@contact)
|
72
80
|
assert_no_match %r{"_id":}, json
|
73
81
|
end
|
74
82
|
|
75
83
|
should "not be included even if :except is used" do
|
76
|
-
json = @contact
|
84
|
+
json = convert_to_json(@contact, :except => :name)
|
77
85
|
assert_no_match %r{"_id":}, json
|
78
86
|
end
|
79
87
|
end
|
@@ -85,12 +93,12 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
85
93
|
end
|
86
94
|
|
87
95
|
should "be included by default" do
|
88
|
-
json = @contact
|
96
|
+
json = convert_to_json(@contact)
|
89
97
|
assert_match %r{"id"}, json
|
90
98
|
end
|
91
99
|
|
92
100
|
should "be included when single method included" do
|
93
|
-
json = @contact
|
101
|
+
json = convert_to_json(@contact, :methods => :label)
|
94
102
|
assert_match %r{"id"}, json
|
95
103
|
assert_match %r{"label":"Has cheezburger"}, json
|
96
104
|
assert_match %r{"name":"Konata Izumi"}, json
|
@@ -98,7 +106,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
98
106
|
end
|
99
107
|
|
100
108
|
should "be included when multiple methods included" do
|
101
|
-
json = @contact
|
109
|
+
json = convert_to_json(@contact, :methods => [:label, :favorite_quote])
|
102
110
|
assert_match %r{"id"}, json
|
103
111
|
assert_match %r{"label":"Has cheezburger"}, json
|
104
112
|
assert_match %r{"favorite_quote":"Constraints are liberating"}, json
|
@@ -106,9 +114,14 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
106
114
|
end
|
107
115
|
|
108
116
|
should "not be included if :only is present" do
|
109
|
-
json = @contact
|
117
|
+
json = convert_to_json(@contact, :only => :name)
|
110
118
|
assert_no_match %r{"id":}, json
|
111
119
|
end
|
120
|
+
|
121
|
+
should "be represented by a string" do
|
122
|
+
json = convert_to_json(@contact)
|
123
|
+
assert_match %r{"id":"}, json
|
124
|
+
end
|
112
125
|
end
|
113
126
|
|
114
127
|
context "including methods" do
|
@@ -118,12 +131,12 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
118
131
|
end
|
119
132
|
|
120
133
|
should "include single method" do
|
121
|
-
json = @contact
|
134
|
+
json = convert_to_json(@contact, :methods => :label)
|
122
135
|
assert_match %r{"label":"Has cheezburger"}, json
|
123
136
|
end
|
124
137
|
|
125
138
|
should "include multiple methods" do
|
126
|
-
json = @contact
|
139
|
+
json = convert_to_json(@contact, :only => :name, :methods => [:label, :favorite_quote])
|
127
140
|
assert_match %r{"label":"Has cheezburger"}, json
|
128
141
|
assert_match %r{"favorite_quote":"Constraints are liberating"}, json
|
129
142
|
assert_match %r{"name":"Konata Izumi"}, json
|
@@ -143,13 +156,13 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
143
156
|
end
|
144
157
|
|
145
158
|
should "allow attribute filtering with only" do
|
146
|
-
json =
|
159
|
+
json =convert_to_json(@contacts, :only => :name)
|
147
160
|
assert_match %r{\{"name":"David"\}}, json
|
148
161
|
assert_match %r{\{"name":"Mary"\}}, json
|
149
162
|
end
|
150
163
|
|
151
164
|
should "allow attribute filtering with except" do
|
152
|
-
json = @contacts
|
165
|
+
json = convert_to_json(@contacts, :except => [:name, :preferences, :awesome, :created_at, :updated_at])
|
153
166
|
assert_match %r{"age":39}, json
|
154
167
|
assert_match %r{"age":14}, json
|
155
168
|
assert_no_match %r{"name":}, json
|
@@ -165,7 +178,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
165
178
|
1 => Contact.new(:name => 'David', :age => 39),
|
166
179
|
2 => Contact.new(:name => 'Mary', :age => 14)
|
167
180
|
}
|
168
|
-
json = contacts
|
181
|
+
json = convert_to_json(contacts, :only => [1, :name])
|
169
182
|
assert_match %r{"1":}, json
|
170
183
|
assert_match %r{\{"name":"David"\}}, json
|
171
184
|
assert_no_match %r{"2":}, json
|
@@ -174,7 +187,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
174
187
|
should "include embedded attributes" do
|
175
188
|
contact = Contact.new(:name => 'John', :age => 27)
|
176
189
|
contact.tags = [Tag.new(:name => 'awesome'), Tag.new(:name => 'ruby')]
|
177
|
-
json = contact
|
190
|
+
json = convert_to_json(contact)
|
178
191
|
assert_match %r{"tags":}, json
|
179
192
|
assert_match %r{"name":"awesome"}, json
|
180
193
|
assert_match %r{"name":"ruby"}, json
|
@@ -183,7 +196,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
183
196
|
should "include dynamic attributes" do
|
184
197
|
contact = Contact.new(:name => 'John', :age => 27, :foo => 'bar')
|
185
198
|
contact['smell'] = 'stinky'
|
186
|
-
json = contact
|
199
|
+
json = convert_to_json(contact)
|
187
200
|
assert_match %r{"smell":"stinky"}, json
|
188
201
|
end
|
189
202
|
end
|
@@ -23,14 +23,14 @@ class SerializationTest < Test::Unit::TestCase
|
|
23
23
|
context format do
|
24
24
|
should "be reversable" do
|
25
25
|
serialized = @instance.send("to_#{format}")
|
26
|
-
unserialized = @document.
|
26
|
+
unserialized = @document.send("from_#{format}", serialized)
|
27
27
|
|
28
28
|
assert_equal @instance, unserialized
|
29
29
|
end
|
30
30
|
|
31
31
|
should "allow attribute only filtering" do
|
32
32
|
serialized = @instance.send("to_#{format}", :only => [ :age, :name ])
|
33
|
-
unserialized = @document.
|
33
|
+
unserialized = @document.send("from_#{format}", serialized)
|
34
34
|
|
35
35
|
assert_equal @instance.name, unserialized.name
|
36
36
|
assert_equal @instance.age, unserialized.age
|
@@ -40,7 +40,7 @@ class SerializationTest < Test::Unit::TestCase
|
|
40
40
|
|
41
41
|
should "allow attribute except filtering" do
|
42
42
|
serialized = @instance.send("to_#{format}", :except => [ :age, :name ])
|
43
|
-
unserialized = @document.
|
43
|
+
unserialized = @document.send("from_#{format}", serialized)
|
44
44
|
|
45
45
|
assert_nil unserialized.name
|
46
46
|
assert_nil unserialized.age
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper-unstable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 2010
|
7
|
+
- 3
|
8
|
+
- 3
|
9
|
+
version: 2010.3.3
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- John Nunemaker
|
@@ -9,79 +14,106 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-03 00:00:00 -05: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
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
23
30
|
version: "2.3"
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: mongo
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
38
|
- - "="
|
32
39
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
- 19
|
43
|
+
- 1
|
44
|
+
version: 0.19.1
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
35
47
|
- !ruby/object:Gem::Dependency
|
36
48
|
name: jnunemaker-validatable
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
51
|
requirements:
|
41
52
|
- - "="
|
42
53
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
54
|
+
segments:
|
55
|
+
- 1
|
56
|
+
- 8
|
57
|
+
- 3
|
58
|
+
version: 1.8.3
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
45
61
|
- !ruby/object:Gem::Dependency
|
46
62
|
name: jnunemaker-matchy
|
47
|
-
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
65
|
requirements:
|
51
66
|
- - "="
|
52
67
|
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
- 4
|
71
|
+
- 0
|
53
72
|
version: 0.4.0
|
54
|
-
|
73
|
+
type: :development
|
74
|
+
version_requirements: *id004
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: shoulda
|
57
|
-
|
58
|
-
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
prerelease: false
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
60
79
|
requirements:
|
61
80
|
- - "="
|
62
81
|
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 2
|
84
|
+
- 10
|
85
|
+
- 2
|
63
86
|
version: 2.10.2
|
64
|
-
|
87
|
+
type: :development
|
88
|
+
version_requirements: *id005
|
65
89
|
- !ruby/object:Gem::Dependency
|
66
90
|
name: timecop
|
67
|
-
|
68
|
-
|
69
|
-
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
prerelease: false
|
92
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
70
93
|
requirements:
|
71
94
|
- - "="
|
72
95
|
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
- 3
|
99
|
+
- 1
|
73
100
|
version: 0.3.1
|
74
|
-
|
101
|
+
type: :development
|
102
|
+
version_requirements: *id006
|
75
103
|
- !ruby/object:Gem::Dependency
|
76
104
|
name: mocha
|
77
|
-
|
78
|
-
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
prerelease: false
|
106
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
80
107
|
requirements:
|
81
108
|
- - "="
|
82
109
|
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 9
|
113
|
+
- 8
|
83
114
|
version: 0.9.8
|
84
|
-
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id007
|
85
117
|
description:
|
86
118
|
email: nunemaker@gmail.com
|
87
119
|
executables:
|
@@ -125,11 +157,14 @@ files:
|
|
125
157
|
- lib/mongo_mapper/plugins/inspect.rb
|
126
158
|
- lib/mongo_mapper/plugins/keys.rb
|
127
159
|
- lib/mongo_mapper/plugins/logger.rb
|
160
|
+
- lib/mongo_mapper/plugins/modifiers.rb
|
128
161
|
- lib/mongo_mapper/plugins/pagination.rb
|
129
162
|
- lib/mongo_mapper/plugins/pagination/proxy.rb
|
130
163
|
- lib/mongo_mapper/plugins/protected.rb
|
131
164
|
- lib/mongo_mapper/plugins/rails.rb
|
132
165
|
- lib/mongo_mapper/plugins/serialization.rb
|
166
|
+
- lib/mongo_mapper/plugins/timestamps.rb
|
167
|
+
- lib/mongo_mapper/plugins/userstamps.rb
|
133
168
|
- lib/mongo_mapper/plugins/validations.rb
|
134
169
|
- lib/mongo_mapper/query.rb
|
135
170
|
- lib/mongo_mapper/support.rb
|
@@ -139,6 +174,7 @@ files:
|
|
139
174
|
- performance/read_write.rb
|
140
175
|
- specs.watchr
|
141
176
|
- test/NOTE_ON_TESTING
|
177
|
+
- test/active_model_lint_test.rb
|
142
178
|
- test/functional/associations/test_belongs_to_polymorphic_proxy.rb
|
143
179
|
- test/functional/associations/test_belongs_to_proxy.rb
|
144
180
|
- test/functional/associations/test_in_array_proxy.rb
|
@@ -155,11 +191,14 @@ files:
|
|
155
191
|
- test/functional/test_document.rb
|
156
192
|
- test/functional/test_embedded_document.rb
|
157
193
|
- test/functional/test_identity_map.rb
|
194
|
+
- test/functional/test_indexing.rb
|
158
195
|
- test/functional/test_logger.rb
|
159
196
|
- test/functional/test_modifiers.rb
|
160
197
|
- test/functional/test_pagination.rb
|
161
198
|
- test/functional/test_protected.rb
|
162
199
|
- test/functional/test_string_id_compatibility.rb
|
200
|
+
- test/functional/test_timestamps.rb
|
201
|
+
- test/functional/test_userstamps.rb
|
163
202
|
- test/functional/test_validations.rb
|
164
203
|
- test/models.rb
|
165
204
|
- test/support/custom_matchers.rb
|
@@ -196,18 +235,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
235
|
requirements:
|
197
236
|
- - ">="
|
198
237
|
- !ruby/object:Gem::Version
|
238
|
+
segments:
|
239
|
+
- 0
|
199
240
|
version: "0"
|
200
|
-
version:
|
201
241
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
242
|
requirements:
|
203
243
|
- - ">="
|
204
244
|
- !ruby/object:Gem::Version
|
245
|
+
segments:
|
246
|
+
- 0
|
205
247
|
version: "0"
|
206
|
-
version:
|
207
248
|
requirements: []
|
208
249
|
|
209
250
|
rubyforge_project:
|
210
|
-
rubygems_version: 1.3.
|
251
|
+
rubygems_version: 1.3.6
|
211
252
|
signing_key:
|
212
253
|
specification_version: 3
|
213
254
|
summary: A Ruby Object Mapper for Mongo
|
@@ -233,10 +274,12 @@ test_files:
|
|
233
274
|
- test/test_helper.rb
|
234
275
|
- test/support/custom_matchers.rb
|
235
276
|
- test/support/timing.rb
|
277
|
+
- test/functional/test_timestamps.rb
|
236
278
|
- test/functional/test_modifiers.rb
|
237
279
|
- test/functional/test_embedded_document.rb
|
238
280
|
- test/functional/test_protected.rb
|
239
281
|
- test/functional/test_string_id_compatibility.rb
|
282
|
+
- test/functional/test_indexing.rb
|
240
283
|
- test/functional/test_associations.rb
|
241
284
|
- test/functional/associations/test_belongs_to_proxy.rb
|
242
285
|
- test/functional/associations/test_in_array_proxy.rb
|
@@ -251,8 +294,10 @@ test_files:
|
|
251
294
|
- test/functional/test_binary.rb
|
252
295
|
- test/functional/test_dirty.rb
|
253
296
|
- test/functional/test_callbacks.rb
|
297
|
+
- test/functional/test_userstamps.rb
|
254
298
|
- test/functional/test_validations.rb
|
255
299
|
- test/functional/test_logger.rb
|
256
300
|
- test/functional/test_document.rb
|
257
301
|
- test/functional/test_pagination.rb
|
258
302
|
- test/models.rb
|
303
|
+
- test/active_model_lint_test.rb
|