From 970d9bf325c11d5d9478eac3a997fb0c4f88cda5 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Thu, 30 Jul 2015 14:34:34 -0500 Subject: [PATCH 1/2] Fix #296; don't catch InvalidDefaultError --- CHANGELOG.md | 6 ++++++ lib/active_interaction/base.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cc40d84..e0597f54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Fixed + +- [#296][]: Fixed a bug that silently converted invalid lazy default values to + `nil` instead of raising an `InvalidDefaultError`. + # [2.1.0][] (2015-07-30) ## Added @@ -565,5 +570,6 @@ For help upgrading to version 2, please read [the announcement post][]. [#286]: https://github.com/orgsync/active_interaction/issues/286 [#289]: https://github.com/orgsync/active_interaction/issues/289 [#295]: https://github.com/orgsync/active_interaction/issues/295 + [#296]: https://github.com/orgsync/active_interaction/issues/296 [the announcement post]: http://devblog.orgsync.com/2015/05/06/announcing-active-interaction-2/ diff --git a/lib/active_interaction/base.rb b/lib/active_interaction/base.rb index 7b3d2895..a359d291 100644 --- a/lib/active_interaction/base.rb +++ b/lib/active_interaction/base.rb @@ -248,7 +248,7 @@ def populate_filters(inputs) self.class.filters.each do |name, filter| begin public_send("#{name}=", filter.clean(inputs[name])) - rescue Error + rescue InvalidValueError, MissingValueError, NoDefaultError # #type_check will add errors if appropriate. end end From 41f4909f6954c284698496843f063bb7494c8df3 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Thu, 30 Jul 2015 14:53:59 -0500 Subject: [PATCH 2/2] Add some specs for #296 --- spec/support/interactions.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/support/interactions.rb b/spec/support/interactions.rb index 5e198078..ab426c69 100644 --- a/spec/support/interactions.rb +++ b/spec/support/interactions.rb @@ -30,6 +30,19 @@ def execute end end + context 'with an invalid lazy default' do + let(:described_class) do + Class.new(TestInteraction) do + public_send(type, :default, + filter_options.merge(default: -> { Object.new })) + end + end + + it 'raises an error' do + expect { outcome }.to raise_error ActiveInteraction::InvalidDefaultError + end + end + context 'without required inputs' do it 'is invalid' do expect(outcome).to be_invalid