jnunemaker-mongomapper 0.3.4 → 0.3.5
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/History +4 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/mmconsole +0 -1
- data/lib/mongomapper.rb +3 -3
- data/lib/mongomapper/document.rb +3 -3
- data/lib/mongomapper/embedded_document.rb +7 -3
- data/mongomapper.gemspec +5 -5
- data/test/functional/associations/test_many_documents_as_proxy.rb +2 -2
- data/test/functional/test_document.rb +1 -1
- data/test/unit/test_document.rb +4 -4
- data/test/unit/test_embedded_document.rb +21 -0
- data/test/unit/test_mongomapper.rb +3 -3
- metadata +3 -3
data/History
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
0.3.5 8/29/2009
|
2
|
+
* updated to 0.14 of the ruby driver
|
3
|
+
* _type key gets set automatically at initialize time if defined and blank
|
4
|
+
|
1
5
|
0.3.4 8/28/2009
|
2
6
|
* BACKWORDS COMPATIBILITY BREAK: Timestamps are now optional. To use them add timestamps! to your model.
|
3
7
|
* BACKWORDS COMPATIBILITY BREAK: Associations keys are no longer created automatically when you use belongs_to and many. Too much was hidden from the developer. You now have to declare them like key :creator_id, String and such.
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.rubyforge_project = "mongomapper"
|
13
13
|
|
14
14
|
gem.add_dependency('activesupport')
|
15
|
-
gem.add_dependency('mongodb-mongo', '0.
|
15
|
+
gem.add_dependency('mongodb-mongo', '0.14')
|
16
16
|
gem.add_dependency('jnunemaker-validatable', '1.7.2')
|
17
17
|
|
18
18
|
gem.add_development_dependency('mocha', '0.9.4')
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.5
|
data/bin/mmconsole
CHANGED
data/lib/mongomapper.rb
CHANGED
@@ -2,10 +2,10 @@ require 'pathname'
|
|
2
2
|
require 'rubygems'
|
3
3
|
|
4
4
|
gem 'activesupport'
|
5
|
-
gem 'mongodb-mongo', '0.
|
5
|
+
gem 'mongodb-mongo', '0.14'
|
6
6
|
gem 'jnunemaker-validatable', '1.7.2'
|
7
7
|
|
8
|
-
require 'activesupport'
|
8
|
+
# require 'activesupport'
|
9
9
|
require 'mongo'
|
10
10
|
require 'validatable'
|
11
11
|
|
@@ -54,7 +54,7 @@ module MongoMapper
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.connection
|
57
|
-
@@connection ||=
|
57
|
+
@@connection ||= Mongo::Connection.new
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.connection=(new_connection)
|
data/lib/mongomapper/document.rb
CHANGED
@@ -59,13 +59,13 @@ module MongoMapper
|
|
59
59
|
|
60
60
|
def find_by_id(id)
|
61
61
|
criteria = FinderOptions.to_mongo_criteria(:_id => id)
|
62
|
-
if doc = collection.
|
62
|
+
if doc = collection.find_one(criteria)
|
63
63
|
new(doc)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
def count(conditions={})
|
68
|
-
collection.
|
68
|
+
collection.find(FinderOptions.to_mongo_criteria(conditions)).count
|
69
69
|
end
|
70
70
|
|
71
71
|
def create(*docs)
|
@@ -320,7 +320,7 @@ module MongoMapper
|
|
320
320
|
|
321
321
|
def assign_id
|
322
322
|
if read_attribute(:_id).blank?
|
323
|
-
write_attribute(:_id,
|
323
|
+
write_attribute(:_id, Mongo::ObjectID.new.to_s)
|
324
324
|
end
|
325
325
|
end
|
326
326
|
|
@@ -84,7 +84,7 @@ module MongoMapper
|
|
84
84
|
|
85
85
|
private
|
86
86
|
def accessors_module
|
87
|
-
if const_defined?('MongoMapperKeys')
|
87
|
+
if const_defined?('MongoMapperKeys')
|
88
88
|
const_get 'MongoMapperKeys'
|
89
89
|
else
|
90
90
|
const_set 'MongoMapperKeys', Module.new
|
@@ -94,7 +94,7 @@ module MongoMapper
|
|
94
94
|
def create_accessors_for(key)
|
95
95
|
accessors_module.module_eval <<-end_eval
|
96
96
|
def #{key.name}
|
97
|
-
read_attribute(
|
97
|
+
read_attribute(:'#{key.name}')
|
98
98
|
end
|
99
99
|
|
100
100
|
def #{key.name}_before_typecast
|
@@ -160,10 +160,14 @@ module MongoMapper
|
|
160
160
|
end
|
161
161
|
|
162
162
|
self.attributes = attrs
|
163
|
+
|
164
|
+
if respond_to?(:_type=) && self['_type'].blank?
|
165
|
+
self._type = self.class.name
|
166
|
+
end
|
163
167
|
end
|
164
168
|
|
165
169
|
if self.class.embeddable? && read_attribute(:_id).blank?
|
166
|
-
write_attribute :_id,
|
170
|
+
write_attribute :_id, Mongo::ObjectID.new.to_s
|
167
171
|
end
|
168
172
|
end
|
169
173
|
|
data/mongomapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongomapper}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Nunemaker"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-29}
|
13
13
|
s.default_executable = %q{mmconsole}
|
14
14
|
s.email = %q{nunemaker@gmail.com}
|
15
15
|
s.executables = ["mmconsole"]
|
@@ -124,20 +124,20 @@ Gem::Specification.new do |s|
|
|
124
124
|
|
125
125
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
126
126
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
127
|
-
s.add_runtime_dependency(%q<mongodb-mongo>, ["= 0.
|
127
|
+
s.add_runtime_dependency(%q<mongodb-mongo>, ["= 0.14"])
|
128
128
|
s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.7.2"])
|
129
129
|
s.add_development_dependency(%q<mocha>, ["= 0.9.4"])
|
130
130
|
s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
131
131
|
else
|
132
132
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
133
|
-
s.add_dependency(%q<mongodb-mongo>, ["= 0.
|
133
|
+
s.add_dependency(%q<mongodb-mongo>, ["= 0.14"])
|
134
134
|
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.7.2"])
|
135
135
|
s.add_dependency(%q<mocha>, ["= 0.9.4"])
|
136
136
|
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
137
137
|
end
|
138
138
|
else
|
139
139
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
140
|
-
s.add_dependency(%q<mongodb-mongo>, ["= 0.
|
140
|
+
s.add_dependency(%q<mongodb-mongo>, ["= 0.14"])
|
141
141
|
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.7.2"])
|
142
142
|
s.add_dependency(%q<mocha>, ["= 0.9.4"])
|
143
143
|
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
@@ -141,7 +141,7 @@ class ManyDocumentsAsProxyTest < Test::Unit::TestCase
|
|
141
141
|
end
|
142
142
|
|
143
143
|
should "work with order" do
|
144
|
-
comments = @post.comments.find(:all, :order => '
|
144
|
+
comments = @post.comments.find(:all, :order => 'body desc')
|
145
145
|
comments.should == [@comment2, @comment1]
|
146
146
|
end
|
147
147
|
end
|
@@ -179,7 +179,7 @@ class ManyDocumentsAsProxyTest < Test::Unit::TestCase
|
|
179
179
|
end
|
180
180
|
|
181
181
|
should "work with conditions" do
|
182
|
-
comment = @post.comments.first(:conditions => {:body => 'comment2'})
|
182
|
+
comment = @post.comments.first(:conditions => {:body => 'comment2'}, :order => 'body desc')
|
183
183
|
comment.should == @comment2
|
184
184
|
end
|
185
185
|
end
|
@@ -26,7 +26,7 @@ class DocumentTest < Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
context "Loading a document from the database with keys that are not defined" do
|
28
28
|
setup do
|
29
|
-
@id =
|
29
|
+
@id = Mongo::ObjectID.new.to_s
|
30
30
|
@document.collection.insert({
|
31
31
|
:_id => @id,
|
32
32
|
:first_name => 'John',
|
data/test/unit/test_document.rb
CHANGED
@@ -18,11 +18,11 @@ class DocumentTest < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
should "have a connection" do
|
21
|
-
@document.connection.should be_instance_of(
|
21
|
+
@document.connection.should be_instance_of(Mongo::Connection)
|
22
22
|
end
|
23
23
|
|
24
24
|
should "allow setting different connection without affecting the default" do
|
25
|
-
conn =
|
25
|
+
conn = Mongo::Connection.new
|
26
26
|
@document.connection conn
|
27
27
|
@document.connection.should == conn
|
28
28
|
@document.connection.should_not == MongoMapper.connection
|
@@ -43,13 +43,13 @@ class DocumentTest < Test::Unit::TestCase
|
|
43
43
|
include MongoMapper::Document
|
44
44
|
end
|
45
45
|
|
46
|
-
Item.collection.should be_instance_of(
|
46
|
+
Item.collection.should be_instance_of(Mongo::Collection)
|
47
47
|
Item.collection.name.should == 'items'
|
48
48
|
end
|
49
49
|
|
50
50
|
should "allow setting the collection name" do
|
51
51
|
@document.collection('foobar')
|
52
|
-
@document.collection.should be_instance_of(
|
52
|
+
@document.collection.should be_instance_of(Mongo::Collection)
|
53
53
|
@document.collection.name.should == 'foobar'
|
54
54
|
end
|
55
55
|
end # Document class
|
@@ -282,6 +282,27 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
282
282
|
}.should_not raise_error
|
283
283
|
end
|
284
284
|
end
|
285
|
+
|
286
|
+
context "initialized when _type key present" do
|
287
|
+
setup do
|
288
|
+
::FooBar = Class.new do
|
289
|
+
include MongoMapper::EmbeddedDocument
|
290
|
+
key :_type, String
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
teardown do
|
295
|
+
Object.send(:remove_const, :FooBar)
|
296
|
+
end
|
297
|
+
|
298
|
+
should "set _type to class name" do
|
299
|
+
FooBar.new._type.should == 'FooBar'
|
300
|
+
end
|
301
|
+
|
302
|
+
should "not change _type if already set" do
|
303
|
+
FooBar.new(:_type => 'Foo')._type.should == 'Foo'
|
304
|
+
end
|
305
|
+
end
|
285
306
|
|
286
307
|
context "mass assigning keys" do
|
287
308
|
should "update values for keys provided" do
|
@@ -4,19 +4,19 @@ class Address; end
|
|
4
4
|
|
5
5
|
class MongoMapperTest < Test::Unit::TestCase
|
6
6
|
should "be able to write and read connection" do
|
7
|
-
conn =
|
7
|
+
conn = Mongo::Connection.new
|
8
8
|
MongoMapper.connection = conn
|
9
9
|
MongoMapper.connection.should == conn
|
10
10
|
end
|
11
11
|
|
12
12
|
should "default connection to new mongo ruby driver" do
|
13
13
|
MongoMapper.connection = nil
|
14
|
-
MongoMapper.connection.should be_instance_of(
|
14
|
+
MongoMapper.connection.should be_instance_of(Mongo::Connection)
|
15
15
|
end
|
16
16
|
|
17
17
|
should "be able to write and read default database" do
|
18
18
|
MongoMapper.database = DefaultDatabase
|
19
|
-
MongoMapper.database.should be_instance_of(
|
19
|
+
MongoMapper.database.should be_instance_of(Mongo::DB)
|
20
20
|
MongoMapper.database.name.should == DefaultDatabase
|
21
21
|
end
|
22
22
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jnunemaker-mongomapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
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: 2009-08-
|
12
|
+
date: 2009-08-29 00:00:00 -07: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.
|
33
|
+
version: "0.14"
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: jnunemaker-validatable
|