summaryrefslogtreecommitdiff
path: root/spec/hashie/extensions
diff options
context:
space:
mode:
authorMatt White <mattw922@gmail.com>2016-09-16 11:37:49 -0700
committerMatt White <mattw922@gmail.com>2016-09-16 13:29:10 -0700
commitd603f62549657e108bff278c566e99621c071e02 (patch)
tree3aa3ce19a74063cfe7017d1f1c7830be3e32d7df /spec/hashie/extensions
parent6186fe4b7d9392ce9db48ee9c9efbd311fac931a (diff)
downloadhashie-d603f62549657e108bff278c566e99621c071e02.tar.gz
Use existing translations when using IndifferentAccess and
IgnoreUndeclared
Diffstat (limited to 'spec/hashie/extensions')
-rw-r--r--spec/hashie/extensions/indifferent_access_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb
index 294c0b4..a4c2f43 100644
--- a/spec/hashie/extensions/indifferent_access_spec.rb
+++ b/spec/hashie/extensions/indifferent_access_spec.rb
@@ -31,6 +31,13 @@ describe Hashie::Extensions::IndifferentAccess do
property :foo
end
+ class IndifferentHashWithIgnoreUndeclaredAndPropertyTranslation < Hashie::Dash
+ include Hashie::Extensions::IgnoreUndeclared
+ include Hashie::Extensions::Dash::PropertyTranslation
+ include Hashie::Extensions::IndifferentAccess
+ property :foo, from: :bar
+ end
+
describe '#merge' do
it 'indifferently merges in a hash' do
indifferent_hash = Class.new(::Hash) do
@@ -66,6 +73,36 @@ describe Hashie::Extensions::IndifferentAccess do
end
end
+ describe 'when translating properties and ignoring undeclared' do
+ let(:value) { 'baz' }
+
+ subject { IndifferentHashWithIgnoreUndeclaredAndPropertyTranslation.new(params) }
+
+ context 'and the hash keys are strings' do
+ let(:params) { { 'bar' => value } }
+
+ it 'sets the property' do
+ expect(subject[:foo]).to eq value
+ end
+ end
+
+ context 'and the hash keys are symbols' do
+ let(:params) { { bar: 'baz' } }
+
+ it 'sets the property' do
+ expect(subject[:foo]).to eq value
+ end
+ end
+
+ context 'and there are undeclared keys' do
+ let(:params) { { 'bar' => 'baz', 'fail' => false } }
+
+ it 'sets the property' do
+ expect(subject[:foo]).to eq value
+ end
+ end
+ end
+
shared_examples_for 'hash with indifferent access' do
it 'is able to access via string or symbol' do
h = subject.build(abc: 123)