mongoid 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid/criteria.rb +1 -1
- data/lib/mongoid/document.rb +5 -0
- data/mongoid.gemspec +2 -2
- data/spec/integration/mongoid/document_spec.rb +19 -2
- data/spec/unit/mongoid/criteria_spec.rb +1 -1
- data/spec/unit/mongoid/document_spec.rb +15 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.9
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -310,7 +310,7 @@ module Mongoid #:nodoc:
|
|
310
310
|
# Returns a new +Criteria+ object.
|
311
311
|
def self.translate(*args)
|
312
312
|
type, params = args[0], args[1] || {}
|
313
|
-
return new(:first).id(type.to_s) if type.is_a?(
|
313
|
+
return new(:first).id(type.to_s) if type.is_a?(Mongo::ObjectID)
|
314
314
|
return new(type).where(params.delete(:conditions)).extras(params)
|
315
315
|
end
|
316
316
|
|
data/lib/mongoid/document.rb
CHANGED
@@ -215,6 +215,11 @@ module Mongoid #:nodoc:
|
|
215
215
|
fields[name].get(@attributes[name])
|
216
216
|
end
|
217
217
|
|
218
|
+
# Reloads the +Document+ attributes from the database.
|
219
|
+
def reload
|
220
|
+
@attributes = HashWithIndifferentAccess.new(collection.find_one(id))
|
221
|
+
end
|
222
|
+
|
218
223
|
# Returns the id of the Document
|
219
224
|
def to_param
|
220
225
|
id.to_s
|
data/mongoid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Durran Jordan"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-31}
|
13
13
|
s.email = %q{durran@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.textile"
|
@@ -52,7 +52,7 @@ describe Mongoid::Document do
|
|
52
52
|
context "finding by id" do
|
53
53
|
|
54
54
|
it "finds the document by the supplied id" do
|
55
|
-
person = Person.find(@person.id
|
55
|
+
person = Person.find(@person.id)
|
56
56
|
person.id.should == @person.id
|
57
57
|
end
|
58
58
|
|
@@ -92,6 +92,23 @@ describe Mongoid::Document do
|
|
92
92
|
|
93
93
|
end
|
94
94
|
|
95
|
+
describe "#reload" do
|
96
|
+
|
97
|
+
before do
|
98
|
+
@person = Person.new(:title => "Sir")
|
99
|
+
@person.save
|
100
|
+
@from_db = Person.find(@person.id)
|
101
|
+
@from_db.age = 35
|
102
|
+
@from_db.save
|
103
|
+
end
|
104
|
+
|
105
|
+
it "reloads the obejct attributes from the db" do
|
106
|
+
@person.reload
|
107
|
+
@person.age.should == 35
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
95
112
|
describe "#save" do
|
96
113
|
|
97
114
|
context "on a has_one association" do
|
@@ -104,7 +121,7 @@ describe Mongoid::Document do
|
|
104
121
|
|
105
122
|
it "saves the parent document" do
|
106
123
|
@name.save
|
107
|
-
person = Person.find(@person.id
|
124
|
+
person = Person.find(@person.id)
|
108
125
|
person.name.first_name.should == @name.first_name
|
109
126
|
end
|
110
127
|
|
@@ -388,7 +388,7 @@ describe Mongoid::Criteria do
|
|
388
388
|
|
389
389
|
it "creates a new select criteria" do
|
390
390
|
id = Mongo::ObjectID.new
|
391
|
-
criteria = Mongoid::Criteria.translate(id
|
391
|
+
criteria = Mongoid::Criteria.translate(id)
|
392
392
|
criteria.selector.should == { :_id => id }
|
393
393
|
end
|
394
394
|
|
@@ -458,6 +458,21 @@ describe Mongoid::Document do
|
|
458
458
|
|
459
459
|
end
|
460
460
|
|
461
|
+
describe "#reload" do
|
462
|
+
|
463
|
+
before do
|
464
|
+
@attributes = { "title" => "Herr" }
|
465
|
+
@person = Person.new(:_id => Mongo::ObjectID.new)
|
466
|
+
@collection.expects(:find_one).with(@person.id).returns(@attributes)
|
467
|
+
end
|
468
|
+
|
469
|
+
it "reloads the object attribtues from the database" do
|
470
|
+
@person.reload
|
471
|
+
@person.attributes.should == @attributes
|
472
|
+
end
|
473
|
+
|
474
|
+
end
|
475
|
+
|
461
476
|
describe "#select" do
|
462
477
|
|
463
478
|
it "returns a new criteria with select conditions added" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-31 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|