From c989dddaa2735d25ae0b55cce4b0ae35057dada4 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Tue, 28 Jan 2014 11:43:06 -0600 Subject: [PATCH] Re #114; accept symbols as well as arrays --- lib/active_interaction/base.rb | 4 ++-- spec/active_interaction/base_spec.rb | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/active_interaction/base.rb b/lib/active_interaction/base.rb index 1bd357b8..7324499a 100644 --- a/lib/active_interaction/base.rb +++ b/lib/active_interaction/base.rb @@ -129,8 +129,8 @@ def import_filters(klass, options = {}) except = options[:except] other_filters = klass.filters.dup - other_filters.select! { |k, _| only.include?(k) } if only - other_filters.reject! { |k, _| except.include?(k) } if except + other_filters.select! { |k, _| [*only].include?(k) } if only + other_filters.reject! { |k, _| [*except].include?(k) } if except filters.merge!(other_filters) end diff --git a/spec/active_interaction/base_spec.rb b/spec/active_interaction/base_spec.rb index b61b4b6b..98857334 100644 --- a/spec/active_interaction/base_spec.rb +++ b/spec/active_interaction/base_spec.rb @@ -409,8 +409,8 @@ def filters(klass) it 'imports the filters' do expect(described_class.filters).to eq klass.filters - .select { |k, _| only.nil? ? true : only.include?(k) } - .reject { |k, _| except.nil? ? false : except.include?(k) } + .select { |k, _| only.nil? ? true : [*only].include?(k) } + .reject { |k, _| except.nil? ? false : [*except].include?(k) } end it 'does not modify the source' do @@ -421,15 +421,31 @@ def filters(klass) end context 'with :only' do - include_examples 'import_filters examples' + context 'as an Array' do + include_examples 'import_filters examples' - let(:only) { [:x] } + let(:only) { [:x] } + end + + context 'as an Symbol' do + include_examples 'import_filters examples' + + let(:only) { :x } + end end context 'with :except' do - include_examples 'import_filters examples' + context 'as an Array' do + include_examples 'import_filters examples' - let(:except) { [:x] } + let(:except) { [:x] } + end + + context 'as an Symbol' do + include_examples 'import_filters examples' + + let(:except) { :x } + end end context 'with :only & :except' do