Permalink
Browse files

Merge pull request #57 from steved555/master

Don't call super when Mash doesn't have id or type
  • Loading branch information...
2 parents 7055ae6 + 2fa400b commit f7adbf6b6e29bfcd3efbc33695fe0e018d62e66e @mbleigh mbleigh committed Oct 26, 2012
Showing with 29 additions and 7 deletions.
  1. +6 −2 lib/hashie/mash.rb
  2. +23 −5 spec/hashie/mash_spec.rb
View
8 lib/hashie/mash.rb
@@ -70,11 +70,15 @@ def initialize(source_hash = nil, default = nil, &blk)
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, :[]
View
28 spec/hashie/mash_spec.rb
@@ -97,10 +97,28 @@
@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 @@ class SubMash < Hashie::Mash
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

0 comments on commit f7adbf6

Please sign in to comment.