Skip to content

Commit

Permalink
Merge pull request #546 from jonkgrimes/non-destructive-array-filter
Browse files Browse the repository at this point in the history
Use a non-destructive `map` call when transforming an Array filter
  • Loading branch information
AaronLasseigne authored Oct 22, 2022
2 parents 44b7b63 + 719c435 commit 94850dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_interaction/filters/array_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def process(value, context)
children = []

unless filters.empty?
value.map! do |item|
value = value.map do |item|
result = filters[:'0'].process(item, context)
children.push(result)
result.value
Expand Down
5 changes: 5 additions & 0 deletions spec/active_interaction/filters/array_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def to_ary
it 'returns the transformed value' do
expect(result.value).to eql [:test]
end

it 'does not modify the original value' do
expect(result.value.object_id).to_not eql value.object_id
expect(value).to eql ['test']
end
end

context 'with a nested filter' do
Expand Down

0 comments on commit 94850dc

Please sign in to comment.