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.
Files changed (43) hide show
  1. data/README.rdoc +3 -1
  2. data/Rakefile +9 -12
  3. data/lib/mongo_mapper.rb +30 -10
  4. data/lib/mongo_mapper/document.rb +16 -74
  5. data/lib/mongo_mapper/embedded_document.rb +7 -1
  6. data/lib/mongo_mapper/plugins.rb +3 -0
  7. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -12
  8. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +6 -1
  9. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +4 -1
  10. data/lib/mongo_mapper/plugins/callbacks.rb +183 -12
  11. data/lib/mongo_mapper/plugins/keys.rb +17 -5
  12. data/lib/mongo_mapper/plugins/modifiers.rb +87 -0
  13. data/lib/mongo_mapper/plugins/pagination/proxy.rb +7 -3
  14. data/lib/mongo_mapper/plugins/protected.rb +1 -1
  15. data/lib/mongo_mapper/plugins/rails.rb +16 -8
  16. data/lib/mongo_mapper/plugins/serialization.rb +51 -81
  17. data/lib/mongo_mapper/plugins/timestamps.rb +21 -0
  18. data/lib/mongo_mapper/plugins/userstamps.rb +14 -0
  19. data/lib/mongo_mapper/query.rb +1 -1
  20. data/lib/mongo_mapper/version.rb +3 -0
  21. data/mongo_mapper.gemspec +22 -11
  22. data/test/active_model_lint_test.rb +11 -0
  23. data/test/functional/associations/test_in_array_proxy.rb +16 -0
  24. data/test/functional/associations/test_many_documents_proxy.rb +22 -0
  25. data/test/functional/test_callbacks.rb +104 -34
  26. data/test/functional/test_document.rb +70 -149
  27. data/test/functional/test_embedded_document.rb +39 -34
  28. data/test/functional/test_indexing.rb +44 -0
  29. data/test/functional/test_modifiers.rb +297 -227
  30. data/test/functional/test_protected.rb +11 -5
  31. data/test/functional/test_timestamps.rb +64 -0
  32. data/test/functional/test_userstamps.rb +28 -0
  33. data/test/support/timing.rb +1 -1
  34. data/test/unit/serializers/test_json_serializer.rb +30 -17
  35. data/test/unit/test_embedded_document.rb +15 -15
  36. data/test/unit/test_keys.rb +15 -11
  37. data/test/unit/test_mongo_mapper.rb +31 -1
  38. data/test/unit/test_pagination.rb +33 -0
  39. data/test/unit/test_query.rb +6 -0
  40. data/test/unit/test_serialization.rb +3 -3
  41. data/test/unit/test_support.rb +9 -5
  42. metadata +17 -6
  43. data/VERSION +0 -1
@@ -31,7 +31,6 @@ class MongoMapperTest < Test::Unit::TestCase
31
31
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'},
32
32
  'production' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test-prod'}
33
33
  }
34
-
35
34
  MongoMapper.config = config
36
35
  MongoMapper.config.should == config
37
36
  end
@@ -41,7 +40,16 @@ class MongoMapperTest < Test::Unit::TestCase
41
40
  MongoMapper.config = {
42
41
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
43
42
  }
43
+ Mongo::Connection.expects(:new).with('127.0.0.1', 27017, {})
44
+ MongoMapper.expects(:database=).with('test')
45
+ Mongo::DB.any_instance.expects(:authenticate).never
46
+ MongoMapper.connect('development')
47
+ end
44
48
 
49
+ should "work without authentication using uri" do
50
+ MongoMapper.config = {
51
+ 'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
52
+ }
45
53
  Mongo::Connection.expects(:new).with('127.0.0.1', 27017, {})
46
54
  MongoMapper.expects(:database=).with('test')
47
55
  Mongo::DB.any_instance.expects(:authenticate).never
@@ -52,7 +60,15 @@ class MongoMapperTest < Test::Unit::TestCase
52
60
  MongoMapper.config = {
53
61
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
54
62
  }
63
+ connection, logger = mock('connection'), mock('logger')
64
+ Mongo::Connection.expects(:new).with('127.0.0.1', 27017, :logger => logger)
65
+ MongoMapper.connect('development', :logger => logger)
66
+ end
55
67
 
68
+ should "work with options using uri" do
69
+ MongoMapper.config = {
70
+ 'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
71
+ }
56
72
  connection, logger = mock('connection'), mock('logger')
57
73
  Mongo::Connection.expects(:new).with('127.0.0.1', 27017, :logger => logger)
58
74
  MongoMapper.connect('development', :logger => logger)
@@ -62,10 +78,24 @@ class MongoMapperTest < Test::Unit::TestCase
62
78
  MongoMapper.config = {
63
79
  'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'username' => 'john', 'password' => 'secret'}
64
80
  }
81
+ Mongo::DB.any_instance.expects(:authenticate).with('john', 'secret')
82
+ MongoMapper.connect('development')
83
+ end
65
84
 
85
+ should "work with authentication using uri" do
86
+ MongoMapper.config = {
87
+ 'development' => {'uri' => 'mongodb://john:secret@127.0.0.1:27017/test'}
88
+ }
66
89
  Mongo::DB.any_instance.expects(:authenticate).with('john', 'secret')
67
90
  MongoMapper.connect('development')
68
91
  end
92
+
93
+ should "raise error for invalid scheme" do
94
+ MongoMapper.config = {
95
+ 'development' => {'uri' => 'mysql://127.0.0.1:5336/foo'}
96
+ }
97
+ assert_raises(MongoMapper::InvalidScheme) { MongoMapper.connect('development') }
98
+ end
69
99
  end
70
100
 
71
101
  context "setup" do
@@ -12,6 +12,29 @@ class PaginationTest < Test::Unit::TestCase
12
12
  context "Pagination proxy" do
13
13
  include MongoMapper::Plugins::Pagination
14
14
 
15
+ should "respond_to? correctly on proxy readers" do
16
+ proxy = Proxy.new(25, 10, 4)
17
+ proxy.respond_to?(:subject).should be_true
18
+ proxy.respond_to?(:total_entries).should be_true
19
+ proxy.respond_to?(:per_page).should be_true
20
+ proxy.respond_to?(:current_page).should be_true
21
+ proxy.respond_to?(:limit).should be_true
22
+ proxy.respond_to?(:total_pages).should be_true
23
+ proxy.respond_to?(:out_of_bounds?).should be_true
24
+ proxy.respond_to?(:previous_page).should be_true
25
+ proxy.respond_to?(:next_page).should be_true
26
+ proxy.respond_to?(:skip).should be_true
27
+ proxy.respond_to?(:offset).should be_true
28
+
29
+ # make sure it doesnt respond true to everything
30
+ proxy.respond_to?(:blahblahblah).should be_false
31
+ end
32
+
33
+ should "respond_to? correctly on proxy writers" do
34
+ proxy = Proxy.new(25, 10, 4)
35
+ proxy.respond_to?(:subject=).should be_true
36
+ end
37
+
15
38
  should "should have accessors for subject" do
16
39
  subject = [1,2,3,4,5]
17
40
  collection = Proxy.new(25, 2)
@@ -31,6 +54,16 @@ class PaginationTest < Test::Unit::TestCase
31
54
  collection.class.should == Array
32
55
  end
33
56
 
57
+ should "should respond_to? correctly for methods defined on the subject" do
58
+ subject = [1,2,3,4,5]
59
+ def subject.blahblah
60
+ "BLAHBLAH"
61
+ end
62
+ collection = Proxy.new(25, 2, 10)
63
+ collection.subject = subject
64
+ collection.respond_to?(:blahblah).should be_true
65
+ end
66
+
34
67
  should "return correct value for total_entries" do
35
68
  Proxy.new(25, 2, 10).total_entries.should == 25
36
69
  Proxy.new('25', 2, 10).total_entries.should == 25
@@ -38,6 +38,8 @@ class QueryTest < Test::Unit::TestCase
38
38
  end
39
39
 
40
40
  %w{gt lt gte lte ne in nin mod all size where exists}.each do |operator|
41
+ next if operator == 'size' && RUBY_VERSION >= '1.9.1' # 1.9 defines Symbol#size
42
+
41
43
  should "convert #{operator} conditions" do
42
44
  Query.new(Room, :age.send(operator) => 21).criteria.should == {
43
45
  :age => {"$#{operator}" => 21}
@@ -176,6 +178,10 @@ class QueryTest < Test::Unit::TestCase
176
178
  Query.new(Room, :sort => sort, :order => 'foo asc').options[:sort].should == sort
177
179
  end
178
180
 
181
+ should "normalize id to _id" do
182
+ Query.new(Room, :order => :id.asc).options[:sort].should == [['_id', 1]]
183
+ end
184
+
179
185
  should "convert natural in order to proper" do
180
186
  sort = [['$natural', 1]]
181
187
  Query.new(Room, :order => '$natural asc').options[:sort].should == sort
@@ -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.new.send("from_#{format}", serialized)
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.new.send("from_#{format}", serialized)
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.new.send("from_#{format}", serialized)
43
+ unserialized = @document.send("from_#{format}", serialized)
44
44
 
45
45
  assert_nil unserialized.name
46
46
  assert_nil unserialized.age
@@ -78,7 +78,7 @@ class SupportTest < Test::Unit::TestCase
78
78
 
79
79
  context "Date#to_mongo" do
80
80
  should "be time if string" do
81
- date = Date.to_mongo('10/1/2009')
81
+ date = Date.to_mongo('2009-10-01')
82
82
  date.should == Time.utc(2009, 10, 1)
83
83
  date.should == date
84
84
  date.month.should == 10
@@ -276,8 +276,12 @@ class SupportTest < Test::Unit::TestCase
276
276
  end
277
277
 
278
278
  context "Time#to_mongo without Time.zone" do
279
+ setup do
280
+ Time.zone = nil
281
+ end
282
+
279
283
  should "be time to milliseconds if string" do
280
- Time.to_mongo('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123000).utc
284
+ Time.to_mongo('2000-01-01 01:01:01.123456').to_f.should == Time.local(2000, 1, 1, 1, 1, 1, 123000).utc.to_f
281
285
  end
282
286
 
283
287
  should "be time in utc if time" do
@@ -296,13 +300,13 @@ class SupportTest < Test::Unit::TestCase
296
300
  context "Time#to_mongo with Time.zone" do
297
301
  should "be time to milliseconds if time" do
298
302
  Time.zone = 'Hawaii'
299
- Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0, 123456)).should == Time.utc(2009, 8, 16, 0, 0, 0, 123000)
303
+ Time.to_mongo(Time.zone.local(2009, 8, 15, 14, 0, 0, 123456)).to_f.should == Time.utc(2009, 8, 16, 0, 0, 0, 123000).to_f
300
304
  Time.zone = nil
301
305
  end
302
306
 
303
307
  should "be time to milliseconds if string" do
304
308
  Time.zone = 'Hawaii'
305
- Time.to_mongo('2009-08-15 14:00:00.123456').should == Time.utc(2009, 8, 16, 0, 0, 0, 123000)
309
+ Time.to_mongo('2009-08-15 14:00:00.123456').to_f.should == Time.utc(2009, 8, 16, 0, 0, 0, 123000).to_f
306
310
  Time.zone = nil
307
311
  end
308
312
 
@@ -359,4 +363,4 @@ class SupportTest < Test::Unit::TestCase
359
363
  id.original_to_json.should == %Q({"$oid": "#{id}"})
360
364
  end
361
365
  end
362
- end
366
+ end
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.7.0
4
+ version: 0.7.1
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: 2010-02-10 00:00:00 -05:00
12
+ date: 2010-03-09 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.3
33
+ version: 0.19.1
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: jnunemaker-validatable
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - "="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.8.1
43
+ version: 1.8.3
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: jnunemaker-matchy
@@ -96,7 +96,6 @@ files:
96
96
  - LICENSE
97
97
  - README.rdoc
98
98
  - Rakefile
99
- - VERSION
100
99
  - bin/mmconsole
101
100
  - lib/mongo_mapper.rb
102
101
  - lib/mongo_mapper/document.rb
@@ -125,20 +124,25 @@ files:
125
124
  - lib/mongo_mapper/plugins/inspect.rb
126
125
  - lib/mongo_mapper/plugins/keys.rb
127
126
  - lib/mongo_mapper/plugins/logger.rb
127
+ - lib/mongo_mapper/plugins/modifiers.rb
128
128
  - lib/mongo_mapper/plugins/pagination.rb
129
129
  - lib/mongo_mapper/plugins/pagination/proxy.rb
130
130
  - lib/mongo_mapper/plugins/protected.rb
131
131
  - lib/mongo_mapper/plugins/rails.rb
132
132
  - lib/mongo_mapper/plugins/serialization.rb
133
+ - lib/mongo_mapper/plugins/timestamps.rb
134
+ - lib/mongo_mapper/plugins/userstamps.rb
133
135
  - lib/mongo_mapper/plugins/validations.rb
134
136
  - lib/mongo_mapper/query.rb
135
137
  - lib/mongo_mapper/support.rb
136
138
  - lib/mongo_mapper/support/descendant_appends.rb
137
139
  - lib/mongo_mapper/support/find.rb
140
+ - lib/mongo_mapper/version.rb
138
141
  - mongo_mapper.gemspec
139
142
  - performance/read_write.rb
140
143
  - specs.watchr
141
144
  - test/NOTE_ON_TESTING
145
+ - test/active_model_lint_test.rb
142
146
  - test/functional/associations/test_belongs_to_polymorphic_proxy.rb
143
147
  - test/functional/associations/test_belongs_to_proxy.rb
144
148
  - test/functional/associations/test_in_array_proxy.rb
@@ -155,11 +159,14 @@ files:
155
159
  - test/functional/test_document.rb
156
160
  - test/functional/test_embedded_document.rb
157
161
  - test/functional/test_identity_map.rb
162
+ - test/functional/test_indexing.rb
158
163
  - test/functional/test_logger.rb
159
164
  - test/functional/test_modifiers.rb
160
165
  - test/functional/test_pagination.rb
161
166
  - test/functional/test_protected.rb
162
167
  - test/functional/test_string_id_compatibility.rb
168
+ - test/functional/test_timestamps.rb
169
+ - test/functional/test_userstamps.rb
163
170
  - test/functional/test_validations.rb
164
171
  - test/models.rb
165
172
  - test/support/custom_matchers.rb
@@ -210,8 +217,9 @@ rubyforge_project:
210
217
  rubygems_version: 1.3.5
211
218
  signing_key:
212
219
  specification_version: 3
213
- summary: Awesome gem for modeling your domain and storing it in mongo
220
+ summary: A Ruby Object Mapper for Mongo
214
221
  test_files:
222
+ - test/active_model_lint_test.rb
215
223
  - test/functional/associations/test_belongs_to_polymorphic_proxy.rb
216
224
  - test/functional/associations/test_belongs_to_proxy.rb
217
225
  - test/functional/associations/test_in_array_proxy.rb
@@ -228,11 +236,14 @@ test_files:
228
236
  - test/functional/test_document.rb
229
237
  - test/functional/test_embedded_document.rb
230
238
  - test/functional/test_identity_map.rb
239
+ - test/functional/test_indexing.rb
231
240
  - test/functional/test_logger.rb
232
241
  - test/functional/test_modifiers.rb
233
242
  - test/functional/test_pagination.rb
234
243
  - test/functional/test_protected.rb
235
244
  - test/functional/test_string_id_compatibility.rb
245
+ - test/functional/test_timestamps.rb
246
+ - test/functional/test_userstamps.rb
236
247
  - test/functional/test_validations.rb
237
248
  - test/models.rb
238
249
  - test/support/custom_matchers.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.7.0