djsun-mongo_mapper 0.5.6.1 → 0.5.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/djsun-mongo_mapper.gemspec +1 -1
- data/lib/mongo_mapper/embedded_document.rb +3 -1
- data/lib/mongo_mapper.rb +3 -0
- data/test/functional/test_document.rb +17 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.6.
|
1
|
+
0.5.6.2
|
data/djsun-mongo_mapper.gemspec
CHANGED
@@ -336,7 +336,9 @@ module MongoMapper
|
|
336
336
|
end
|
337
337
|
|
338
338
|
def read_attribute(name)
|
339
|
-
|
339
|
+
key = _keys[name]
|
340
|
+
raise KeyNotFound, "Could not find key: #{name.inspect}" unless key
|
341
|
+
value = key.get(instance_variable_get("@#{name}"))
|
340
342
|
instance_variable_set "@#{name}", value if !frozen?
|
341
343
|
value
|
342
344
|
end
|
data/lib/mongo_mapper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'activesupport', '>= 2.3'
|
1
3
|
require 'active_support'
|
2
4
|
require 'mongo'
|
3
5
|
require 'validatable'
|
4
6
|
|
5
7
|
module MongoMapper
|
8
|
+
class KeyNotFound < RuntimeError; end
|
6
9
|
DocumentNotFound = Class.new(StandardError)
|
7
10
|
DocumentNotValid = Class.new(StandardError) do
|
8
11
|
def initialize(document)
|
@@ -16,6 +16,23 @@ class DocumentTest < Test::Unit::TestCase
|
|
16
16
|
@document.collection.clear
|
17
17
|
end
|
18
18
|
|
19
|
+
context "Accessing attributes on a document" do
|
20
|
+
setup do
|
21
|
+
@doc = @document.new(:first_name => 'John', :age => '27')
|
22
|
+
end
|
23
|
+
|
24
|
+
should "access existing attributes" do
|
25
|
+
@doc[:first_name].should == 'John'
|
26
|
+
@doc[:age].should == 27
|
27
|
+
end
|
28
|
+
|
29
|
+
should "raise an exception for non-existing attributes" do
|
30
|
+
lambda {
|
31
|
+
@doc[:not_here].should == nil
|
32
|
+
}.should raise_error(MongoMapper::KeyNotFound)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
19
36
|
context "Saving a document with a custom id" do
|
20
37
|
should "clear custom id flag when saved" do
|
21
38
|
doc = @document.new(:id => '1234')
|