summaryrefslogtreecommitdiff
path: root/spec/hashie/extensions
diff options
context:
space:
mode:
authorMichael Righi <michael@righi.me>2014-04-06 09:28:22 -0400
committerdblock <dblock@dblock.org>2014-04-06 09:29:28 -0400
commit736fd088921f235728acb743f42ef348e3f3f43a (patch)
treeb7446e5d493fea4228cd96766abd04817f13175b /spec/hashie/extensions
parent75e67454e4c30e7edcdc737ac48e38f7abcf4259 (diff)
downloadhashie-736fd088921f235728acb743f42ef348e3f3f43a.tar.gz
Added IgnoreUndeclared, an extension to silently ignore undeclared properties at hash intialization.
Diffstat (limited to 'spec/hashie/extensions')
-rw-r--r--spec/hashie/extensions/ignore_undeclared_spec.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/hashie/extensions/ignore_undeclared_spec.rb b/spec/hashie/extensions/ignore_undeclared_spec.rb
new file mode 100644
index 0000000..b7d7ad5
--- /dev/null
+++ b/spec/hashie/extensions/ignore_undeclared_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe Hashie::Extensions::IgnoreUndeclared do
+ class ForgivingTrash < Hashie::Trash
+ include Hashie::Extensions::IgnoreUndeclared
+ property :city
+ property :state, from: :provence
+ end
+
+ subject { ForgivingTrash }
+
+ it 'should silently ignore undeclared properties on initialization' do
+ expect { subject.new(city: 'Toronto', provence: 'ON', country: 'Canada') }.to_not raise_error
+ end
+
+ it 'should work with translated properties (with symbol keys)' do
+ expect(subject.new(provence: 'Ontario').state).to eq('Ontario')
+ end
+
+ it 'should work with translated properties (with string keys)' do
+ expect(subject.new(provence: 'Ontario').state).to eq('Ontario')
+ end
+end