Skip to content

Commit

Permalink
fixes #515 by allowing filters nested in arrays to have a default
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronLasseigne committed Oct 14, 2021
1 parent cd2811d commit 5ad3a07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [4.0.6][] (2021-10-13)

## Fix

- [#515][] - Filters nested in arrays should accept default values as indicated in the documentation.

# [4.0.5][] (2021-07-11)

## Fix
Expand Down Expand Up @@ -964,6 +970,7 @@ Example.run

- Initial release.

[4.0.6]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.5...v4.0.6
[4.0.5]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.4...v4.0.5
[4.0.4]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.3...v4.0.4
[4.0.3]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.2...v4.0.3
Expand Down Expand Up @@ -1182,3 +1189,4 @@ Example.run
[#511]: https://github.com/AaronLasseigne/active_interaction/issues/511
[#412]: https://github.com/AaronLasseigne/active_interaction/issues/412
[#480]: https://github.com/AaronLasseigne/active_interaction/issues/480
[#515]: https://github.com/AaronLasseigne/active_interaction/issues/515
6 changes: 2 additions & 4 deletions lib/active_interaction/filters/array_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def method_missing(*, &block)

filters[filters.size.to_s.to_sym] = filter

validate!(filter, names)
validate!(names)
end
end
# rubocop:enable Style/MissingRespondToMissing
Expand All @@ -100,13 +100,11 @@ def method_missing(*, &block)
# @param names [Array<Symbol>]
#
# @raise [InvalidFilterError]
def validate!(filter, names)
def validate!(names)
raise InvalidFilterError, 'multiple filters in array block' if filters.size > 1

raise InvalidFilterError, 'attribute names in array block' unless names.empty?

raise InvalidDefaultError, 'default values in array block' if filter.default?

nil
end
end
Expand Down
8 changes: 0 additions & 8 deletions spec/active_interaction/filters/array_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
end
end

context 'with a nested default' do
let(:block) { proc { array default: nil } }

it 'raises an error' do
expect { filter }.to raise_error ActiveInteraction::InvalidDefaultError
end
end

describe '#cast' do
let(:result) { filter.send(:cast, value, nil) }

Expand Down

0 comments on commit 5ad3a07

Please sign in to comment.