summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Lincoln <mlincoln@thoughtworks.com>2015-03-31 11:03:29 -0400
committerdB <dblock@dblock.org>2015-03-31 11:03:29 -0400
commitfd07b8076954275a9c65bfc462fc55d38b027e6d (patch)
tree31248bbb73c5efad8b5e6a49bc0fb3f17d360ad8
parent8998021867b0ffc55c99aca9dcf6c8f23fb33d7c (diff)
downloadhashie-fd07b8076954275a9c65bfc462fc55d38b027e6d.tar.gz
Another spec for #288.
-rw-r--r--spec/hashie/extensions/coercion_spec.rb12
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])