summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2014-08-18 12:57:09 +0200
committerDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2014-08-18 12:57:09 +0200
commit1c4fee0aa1c6248d59b2dacda78249e3e9347b01 (patch)
tree61c46b65eba717da841aec4bd11e032cab2c2039 /spec
parentae4cab2a2fd9d37ab5b03f4e11e340cbf4cf1c33 (diff)
parent1971100ca1b185b07d40a2331ed477bd157e5c53 (diff)
downloadhashie-1c4fee0aa1c6248d59b2dacda78249e3e9347b01.tar.gz
Merge pull request #195 from michaelherold/indifferent_access_weirdness
Fix #178 and #180 by injecting in place
Diffstat (limited to 'spec')
-rw-r--r--spec/hashie/extensions/indifferent_access_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb
index 225a236..bd13ff6 100644
--- a/spec/hashie/extensions/indifferent_access_spec.rb
+++ b/spec/hashie/extensions/indifferent_access_spec.rb
@@ -52,6 +52,30 @@ describe Hashie::Extensions::IndifferentAccess do
h = subject.build(:foo => 'bar', 'baz' => 'qux')
expect(h.values_at('foo', :baz)).to eq %w(bar qux)
end
+
+ it 'returns the same instance of the hash that was set' do
+ hash = Hash.new
+ h = subject.build(foo: hash)
+ expect(h.values_at(:foo)[0]).to be(hash)
+ end
+
+ it 'returns the same instance of the array that was set' do
+ array = Array.new
+ h = subject.build(foo: array)
+ expect(h.values_at(:foo)[0]).to be(array)
+ end
+
+ it 'returns the same instance of the string that was set' do
+ str = 'my string'
+ h = subject.build(foo: str)
+ expect(h.values_at(:foo)[0]).to be(str)
+ end
+
+ it 'returns the same instance of the object that was set' do
+ object = Object.new
+ h = subject.build(foo: object)
+ expect(h.values_at(:foo)[0]).to be(object)
+ end
end
describe '#fetch' do
@@ -60,6 +84,30 @@ describe Hashie::Extensions::IndifferentAccess do
expect(h.fetch(:foo)).to eq h.fetch('foo')
expect(h.fetch(:foo)).to eq 'bar'
end
+
+ it 'returns the same instance of the hash that was set' do
+ hash = Hash.new
+ h = subject.build(foo: hash)
+ expect(h.fetch(:foo)).to be(hash)
+ end
+
+ it 'returns the same instance of the array that was set' do
+ array = Array.new
+ h = subject.build(foo: array)
+ expect(h.fetch(:foo)).to be(array)
+ end
+
+ it 'returns the same instance of the string that was set' do
+ str = 'my string'
+ h = subject.build(foo: str)
+ expect(h.fetch(:foo)).to be(str)
+ end
+
+ it 'returns the same instance of the object that was set' do
+ object = Object.new
+ h = subject.build(foo: object)
+ expect(h.fetch(:foo)).to be(object)
+ end
end
describe '#delete' do