summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Bleigh <mbleigh@mbleigh.com>2012-10-26 11:06:02 -0700
committerMichael Bleigh <mbleigh@mbleigh.com>2012-10-26 11:06:02 -0700
commitf7adbf6b6e29bfcd3efbc33695fe0e018d62e66e (patch)
treea01ea9b624b0b89218d01882a229c1f3c1f57068
parent7055ae62352b7104dc2e7f50f1616f1b040b68b6 (diff)
parent2fa400b58956f3ae4c4eaaaa196084ffc659072f (diff)
downloadhashie-f7adbf6b6e29bfcd3efbc33695fe0e018d62e66e.tar.gz
Merge pull request #57 from steved555/master
Don't call super when Mash doesn't have id or type
-rw-r--r--lib/hashie/mash.rb8
-rw-r--r--spec/hashie/mash_spec.rb28
2 files changed, 29 insertions, 7 deletions
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index c2a5a2d..d6700fc 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -70,11 +70,15 @@ module Hashie
class << self; alias [] new; end
def id #:nodoc:
- key?("id") ? self["id"] : super
+ self["id"]
end
def type #:nodoc:
- key?("type") ? self["type"] : super
+ self["type"]
+ end
+
+ def object_id #:nodoc:
+ self["object_id"]
end
alias_method :regular_reader, :[]
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index b4b2b6a..bcef406 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -97,10 +97,28 @@ describe Hashie::Mash do
@mash.author.should be_nil
end
+ it "should not call super if object_id is not a key" do
+ @mash.object_id.should == nil
+ end
+
+ it "should return the value if object_id is a key" do
+ @mash.object_id = "Steve"
+ @mash.object_id.should == "Steve"
+ end
- # it "should call super if type is not a key" do
- # @mash.type.should == Hashie::Mash
- # end
+
+ it "should not call super if id is not a key" do
+ @mash.id.should == nil
+ end
+
+ it "should return the value if id is a key" do
+ @mash.id = "Steve"
+ @mash.id.should == "Steve"
+ end
+
+ it "should not call super if type is not a key" do
+ @mash.type.should == nil
+ end
it "should return the value if type is a key" do
@mash.type = "Steve"
@@ -283,11 +301,11 @@ describe Hashie::Mash do
initial = Hashie::Mash.new(:name => 'randy', :address => {:state => 'TX'})
copy = Hashie::Mash.new(initial)
initial.name.should == copy.name
- initial.object_id.should_not == copy.object_id
+ initial.__id__.should_not == copy.__id__
copy.address.state.should == 'TX'
copy.address.state = 'MI'
initial.address.state.should == 'TX'
- copy.address.object_id.should_not == initial.address.object_id
+ copy.address.__id__.should_not == initial.address.__id__
end
it "should accept a default block" do