diff options
author | Max Lincoln <mlincoln@thoughtworks.com> | 2015-03-31 11:03:29 -0400 |
---|---|---|
committer | dB <dblock@dblock.org> | 2015-03-31 11:03:29 -0400 |
commit | fd07b8076954275a9c65bfc462fc55d38b027e6d (patch) | |
tree | 31248bbb73c5efad8b5e6a49bc0fb3f17d360ad8 /spec/hashie/extensions/coercion_spec.rb | |
parent | 8998021867b0ffc55c99aca9dcf6c8f23fb33d7c (diff) | |
download | hashie-fd07b8076954275a9c65bfc462fc55d38b027e6d.tar.gz |
Another spec for #288.
Diffstat (limited to 'spec/hashie/extensions/coercion_spec.rb')
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb index 1c45a55..b190686 100644 --- a/spec/hashie/extensions/coercion_spec.rb +++ b/spec/hashie/extensions/coercion_spec.rb @@ -47,8 +47,13 @@ describe Hashie::Extensions::Coercion do coerce_key :bar, Integer end + class OtherNestedCoercableHash < BaseCoercableHash + coerce_key :foo, Symbol + end + class RootCoercableHash < BaseCoercableHash coerce_key :nested, NestedCoercableHash + coerce_key :other, OtherNestedCoercableHash coerce_key :nested_list, Array[NestedCoercableHash] coerce_key :nested_hash, Hash[String => NestedCoercableHash] end @@ -62,6 +67,13 @@ describe Hashie::Extensions::Coercion do subject { RootCoercableHash } let(:instance) { subject.new } + it 'does not add coercions to superclass' do + instance[:nested] = { foo: 'bar' } + instance[:other] = { foo: 'bar' } + expect(instance[:nested][:foo]).to be_a String + expect(instance[:other][:foo]).to be_a Symbol + end + it 'coerces nested objects' do instance[:nested] = { foo: 123, bar: '456' } test_nested_object(instance[:nested]) |