mongodb-mongo_record 0.1.2 → 0.1.3

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.
@@ -16,6 +16,7 @@
16
16
 
17
17
  require 'rubygems'
18
18
  require 'mongo/types/objectid'
19
+ require 'mongo/types/code'
19
20
  require 'mongo/cursor'
20
21
  require 'mongo_record/convert'
21
22
  require 'mongo_record/sql'
@@ -175,7 +176,7 @@ module MongoRecord
175
176
  val != nil && (!val.kind_of?(String) || val != '')
176
177
  })
177
178
  klass_name = options[:class_name] || field_name_to_class_name(name)
178
- @subobjects[name] = Kernel.const_get(klass_name)
179
+ @subobjects[name] = eval(klass_name)
179
180
  end
180
181
  end
181
182
 
@@ -192,7 +193,7 @@ module MongoRecord
192
193
  define_method("#{name}=".to_sym, lambda { |val| instance_variable_set(ivar_name, val) })
193
194
  define_method("#{name}?".to_sym, lambda { !instance_variable_get(ivar_name).empty? })
194
195
  klass_name = options[:class_name] || field_name_to_class_name(name)
195
- @arrays[name] = Kernel.const_get(klass_name)
196
+ @arrays[name] = eval(klass_name)
196
197
  end
197
198
  end
198
199
 
@@ -302,7 +303,7 @@ module MongoRecord
302
303
  begin
303
304
  collection.count(criteria)
304
305
  rescue => ex
305
- if ex.to_s =~ /Error with count command.*ns does not exist/
306
+ if ex.to_s =~ /Error with count command.*ns missing/
306
307
  # Return 0 because we will graciously assume that we are being
307
308
  # called from a subclass that has been initialized properly, and
308
309
  # is therefore mentioned in the schema.
@@ -542,7 +543,7 @@ module MongoRecord
542
543
  # +func+ must be +nil+ or a JavaScript expression or function in a
543
544
  # string.
544
545
  def where_func(func) # :nodoc:
545
- func ? {'$where' => func} : {}
546
+ func ? {'$where' => XGen::Mongo::Driver::Code.new(func)} : {}
546
547
  end
547
548
 
548
549
  def replace_named_bind_variables(str, h) # :nodoc:
@@ -724,8 +725,8 @@ module MongoRecord
724
725
  # +self+ if all is well.
725
726
  def update
726
727
  set_update_times
727
- row = self.class.collection.insert(to_mongo_value)
728
- if row['_id'].to_s != @_id.to_s
728
+ self.class.collection.modify({:_id => @_id}, to_mongo_value)
729
+ if self.class.collection.db.error?
729
730
  return false
730
731
  end
731
732
  self
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mongo_record'
3
- s.version = '0.1.2'
3
+ s.version = '0.1.3'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = 'ActiveRecord-like models for the 10gen Mongo DB'
6
6
  s.description = 'MongoRecord is an ActiveRecord-like framework for the 10gen Mongo database. For more information about Mongo, see http://www.mongodb.org.'
7
-
7
+
8
8
  s.add_dependency('mongodb-mongo', ['>= 0.6.1'])
9
9
 
10
10
  s.require_paths = ['lib']
11
-
11
+
12
12
  s.files = ['examples/tracks.rb', 'lib/mongo_record.rb',
13
13
  'lib/mongo_record/base.rb',
14
14
  'lib/mongo_record/convert.rb',
@@ -19,17 +19,18 @@ Gem::Specification.new do |s|
19
19
  s.test_files = ['tests/address.rb',
20
20
  'tests/course.rb',
21
21
  'tests/student.rb',
22
+ 'tests/class_in_module.rb',
22
23
  'tests/test_log_device.rb',
23
24
  'tests/test_mongo.rb',
24
25
  'tests/test_sql.rb',
25
26
  'tests/track2.rb',
26
27
  'tests/track3.rb']
27
-
28
+
28
29
  s.has_rdoc = true
29
30
  s.rdoc_options = ['--main', 'README.rdoc', '--inline-source']
30
31
  s.extra_rdoc_files = ['README.rdoc']
31
32
 
32
- s.author = 'Jim Menard'
33
- s.email = 'jim@10gen.com'
33
+ s.authors = ['Jim Menard', 'Mike Dirolf']
34
+ s.email = 'mongodb-user@googlegroups.com'
34
35
  s.homepage = 'http://www.mongodb.org'
35
36
  end
@@ -0,0 +1,11 @@
1
+ require 'mongo_record'
2
+
3
+ module MyMod
4
+ class A < MongoRecord::Base
5
+ field :something
6
+ end
7
+ end
8
+
9
+ class B < MongoRecord::Base
10
+ has_many :a, :class_name => "MyMod::A"
11
+ end
data/tests/test_mongo.rb CHANGED
@@ -19,6 +19,7 @@ require 'mongo_record'
19
19
  require File.join(File.dirname(__FILE__), 'course')
20
20
  require File.join(File.dirname(__FILE__), 'address')
21
21
  require File.join(File.dirname(__FILE__), 'student')
22
+ require File.join(File.dirname(__FILE__), 'class_in_module')
22
23
 
23
24
  class Track < MongoRecord::Base
24
25
  collection_name :tracks
@@ -135,12 +136,14 @@ class MongoTest < Test::Unit::TestCase
135
136
  end
136
137
 
137
138
  def test_update
139
+ count = @@tracks.count()
138
140
  t = Track.find_by_track(2)
139
141
  t.track = 99
140
142
  t.save
141
143
  str = @mayor_str.sub(/2/, '99')
142
144
  assert_equal(str, t.to_s)
143
145
  assert_equal(str, Track.find_by_track(99).to_s)
146
+ assert_equal(count, @@tracks.count())
144
147
  end
145
148
 
146
149
  def test_find_all
@@ -399,6 +402,16 @@ class MongoTest < Test::Unit::TestCase
399
402
  assert (score.for_course.name == @score1.for_course.name && score.grade == @score1.grade), "oops: first score is wrong: #{score}"
400
403
  end
401
404
 
405
+ def test_has_many_class_in_module
406
+ a1 = MyMod::A.new(:something => 4)
407
+ a2 = MyMod::A.new(:something => 10)
408
+ b = B.new(:a => [a1, a2])
409
+ assert_not_nil b.a
410
+ assert_equal 2, b.a.length
411
+ assert_equal a1, b.a[0]
412
+ assert_equal a2, b.a[1]
413
+ end
414
+
402
415
  def test_field_query_methods
403
416
  s = Student.new(:name => 'Spongebob Squarepants', :email => 'spongebob@example.com', :scores => [@score1, @score2])
404
417
  assert s.name?
metadata CHANGED
@@ -1,19 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb-mongo_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard
8
+ - Mike Dirolf
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-02-05 00:00:00 -08:00
13
+ date: 2009-04-08 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: mongodb-mongo
18
+ type: :runtime
17
19
  version_requirement:
18
20
  version_requirements: !ruby/object:Gem::Requirement
19
21
  requirements:
@@ -22,7 +24,7 @@ dependencies:
22
24
  version: 0.6.1
23
25
  version:
24
26
  description: MongoRecord is an ActiveRecord-like framework for the 10gen Mongo database. For more information about Mongo, see http://www.mongodb.org.
25
- email: jim@10gen.com
27
+ email: mongodb-user@googlegroups.com
26
28
  executables: []
27
29
 
28
30
  extensions: []
@@ -72,6 +74,7 @@ test_files:
72
74
  - tests/address.rb
73
75
  - tests/course.rb
74
76
  - tests/student.rb
77
+ - tests/class_in_module.rb
75
78
  - tests/test_log_device.rb
76
79
  - tests/test_mongo.rb
77
80
  - tests/test_sql.rb