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 CHANGED
@@ -1 +1 @@
1
- 0.5.6.1
1
+ 0.5.6.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{djsun-mongo_mapper}
8
- s.version = "0.5.6.1"
8
+ s.version = "0.5.6.2"
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"]
@@ -336,7 +336,9 @@ module MongoMapper
336
336
  end
337
337
 
338
338
  def read_attribute(name)
339
- value = _keys[name].get(instance_variable_get("@#{name}"))
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')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djsun-mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6.1
4
+ version: 0.5.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker