Skip to content

Commit

Permalink
Re #114; accept symbols as well as arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Jan 28, 2014
1 parent cfdbfbd commit c989ddd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/active_interaction/base.rb
Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions spec/active_interaction/base_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c989ddd

Please sign in to comment.