jnunemaker-mongomapper 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
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.11.1')
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.4
1
+ 0.3.5
@@ -11,7 +11,6 @@ IRB.conf[:MAIN_CONTEXT] = irb.context
11
11
 
12
12
  irb.context.evaluate("require 'irb/completion'", 0)
13
13
  irb.context.evaluate(%@
14
- include XGen::Mongo::Driver
15
14
  include MongoMapper
16
15
 
17
16
  MongoMapper.database = "mmtest"
@@ -2,10 +2,10 @@ require 'pathname'
2
2
  require 'rubygems'
3
3
 
4
4
  gem 'activesupport'
5
- gem 'mongodb-mongo', '0.11.1'
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 ||= XGen::Mongo::Driver::Mongo.new
57
+ @@connection ||= Mongo::Connection.new
58
58
  end
59
59
 
60
60
  def self.connection=(new_connection)
@@ -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.find_first(criteria)
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.count(FinderOptions.to_mongo_criteria(conditions))
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, XGen::Mongo::Driver::ObjectID.new.to_s)
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') && constants.include?( '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( :'#{key.name}' )
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, XGen::Mongo::Driver::ObjectID.new.to_s
170
+ write_attribute :_id, Mongo::ObjectID.new.to_s
167
171
  end
168
172
  end
169
173
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongomapper}
8
- s.version = "0.3.4"
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-28}
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.11.1"])
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.11.1"])
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.11.1"])
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 => '$natural desc')
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 = XGen::Mongo::Driver::ObjectID.new.to_s
29
+ @id = Mongo::ObjectID.new.to_s
30
30
  @document.collection.insert({
31
31
  :_id => @id,
32
32
  :first_name => 'John',
@@ -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(XGen::Mongo::Driver::Mongo)
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 = XGen::Mongo::Driver::Mongo.new
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(XGen::Mongo::Driver::Collection)
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(XGen::Mongo::Driver::Collection)
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 = XGen::Mongo::Driver::Mongo.new
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(XGen::Mongo::Driver::Mongo)
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(XGen::Mongo::Driver::DB)
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
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-28 00:00:00 -07:00
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.11.1
33
+ version: "0.14"
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: jnunemaker-validatable