diff options
author | Jim Myhrberg <contact@jimeh.me> | 2013-03-02 14:35:19 +0000 |
---|---|---|
committer | Jim Myhrberg <contact@jimeh.me> | 2013-03-02 15:35:56 +0000 |
commit | 94673a64e493ee61ede1310e6564ab293b012001 (patch) | |
tree | 0c547c9da3dbf9a0b2031b2fc7a90cdaae41ae9a /spec/hashie/extensions | |
parent | 0b481778159605e79659cbe51e2781984b07d262 (diff) | |
download | hashie-94673a64e493ee61ede1310e6564ab293b012001.tar.gz |
Add support and tests for #replace to Coercion extension
Diffstat (limited to 'spec/hashie/extensions')
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb index 8dcf6fd..2ad5181 100644 --- a/spec/hashie/extensions/coercion_spec.rb +++ b/spec/hashie/extensions/coercion_spec.rb @@ -58,15 +58,45 @@ describe Hashie::Extensions::Coercion do instance[:foo].should be_coerced end + + context 'when #replace is used' do + before { subject.coerce_key :foo, :bar, Coercable } + + let(:instance) do + subject.new(:foo => "bar"). + replace(:foo => "foz", :bar => "baz", :hi => "bye") + end + + it "should coerce relevant keys" do + instance[:foo].should be_coerced + instance[:bar].should be_coerced + instance[:hi].should_not respond_to(:coerced?) + end + + it "should set correct values" do + instance[:hi].should == "bye" + end + end end describe '.coerce_value' do context 'with :strict => true' do it 'should coerce any value of the exact right class' do subject.coerce_value String, Coercable - + instance[:foo] = "bar" instance[:bar] = "bax" + instance[:hi] = :bye + instance[:foo].should be_coerced + instance[:bar].should be_coerced + instance[:hi].should_not respond_to(:coerced?) + end + + it 'should coerce values from a #replace call' do + subject.coerce_value String, Coercable + + instance[:foo] = :bar + instance.replace(:foo => "bar", :bar => "bax") instance[:foo].should be_coerced instance[:bar].should be_coerced end |