diff options
author | Michael Herold <opensource@michaeljherold.com> | 2020-10-23 21:57:10 -0500 |
---|---|---|
committer | Michael Herold <> | 2020-10-23 21:57:10 -0500 |
commit | f152e25912d0b93ff08b8964eb757200ad4b6f32 (patch) | |
tree | d357a27b5b2b8408d87f6d400cb5fe8d52259d8c /spec/hashie/extensions/ignore_undeclared_spec.rb | |
parent | 14e923d899183595abb5ee096c29e1de707fcc04 (diff) | |
download | hashie-f152e25912d0b93ff08b8964eb757200ad4b6f32.tar.gz |
Fix inconsistencies with Dash defaults
The normal behavior of Dash with respect to property defaults differed
from the behavior of a Dash/Trash with IgnoreUndeclared mixed in. This
is because some situations called the defaults and some did not.
This change normalizes the behavior so that all situations where the
defaults should be used to override unset values behave consistently,
as well as all situations where the default should not override a `nil`
value.
Diffstat (limited to 'spec/hashie/extensions/ignore_undeclared_spec.rb')
-rw-r--r-- | spec/hashie/extensions/ignore_undeclared_spec.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/hashie/extensions/ignore_undeclared_spec.rb b/spec/hashie/extensions/ignore_undeclared_spec.rb index 50c4f31..6f2d818 100644 --- a/spec/hashie/extensions/ignore_undeclared_spec.rb +++ b/spec/hashie/extensions/ignore_undeclared_spec.rb @@ -27,6 +27,18 @@ describe Hashie::Extensions::IgnoreUndeclared do hash = subject.new(city: 'Toronto') expect { hash.country = 'Canada' }.to raise_error(NoMethodError) end + + context 'with a default value' do + let(:test) do + Class.new(Hashie::Trash) do + include Hashie::Extensions::IgnoreUndeclared + + property :description, from: :desc, default: '' + end + end + + include_examples 'Dash default handling', :description, :desc + end end context 'combined with DeepMerge' do |