From ec2e8d35c20fb1493885d99854448a5aa672652e Mon Sep 17 00:00:00 2001 From: Aaron Lasseigne Date: Sat, 3 Jul 2021 15:55:54 -0500 Subject: [PATCH] fix #511 by making sure we set the class when options are passed and `:class` is not one of them --- CHANGELOG.md | 11 ++++++++++- lib/active_interaction/filters/array_filter.rb | 2 +- spec/active_interaction/filters/array_filter_spec.rb | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03933445..3e3e67f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [4.0.4][] (TBD) + +## Fix + +- [#510][] - Hash parameters failed when working outside of Rails. +- [#511][] - Nested filters with options but no `:class` failed to have `:class` automatically added. + # [4.0.3][] (2021-06-24) ## Fix @@ -951,7 +958,8 @@ Example.run - Initial release. - [4.0.2]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.2...v4.0.3 + [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 [4.0.2]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.1...v4.0.2 [4.0.1]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.0...v4.0.1 [4.0.0]: https://github.com/AaronLasseigne/active_interaction/compare/v3.8.3...v4.0.0 @@ -1163,3 +1171,4 @@ Example.run [#505]: https://github.com/AaronLasseigne/active_interaction/issues/505 [#499]: https://github.com/AaronLasseigne/active_interaction/issues/499 [#493]: https://github.com/AaronLasseigne/active_interaction/issues/493 + [#510]: https://github.com/AaronLasseigne/active_interaction/issues/510 diff --git a/lib/active_interaction/filters/array_filter.rb b/lib/active_interaction/filters/array_filter.rb index c6938aa1..6ffaf560 100644 --- a/lib/active_interaction/filters/array_filter.rb +++ b/lib/active_interaction/filters/array_filter.rb @@ -73,7 +73,7 @@ def convert(value) end def add_option_in_place_of_name(klass, options) - if (keys = FILTER_NAME_OR_OPTION[klass.to_s]) && (keys && options.keys).empty? + if (keys = FILTER_NAME_OR_OPTION[klass.to_s]) && (keys & options.keys).empty? options.merge( "#{keys.first}": name.to_s.singularize.camelize.to_sym ) diff --git a/spec/active_interaction/filters/array_filter_spec.rb b/spec/active_interaction/filters/array_filter_spec.rb index 447baf83..2268905c 100644 --- a/spec/active_interaction/filters/array_filter_spec.rb +++ b/spec/active_interaction/filters/array_filter_spec.rb @@ -137,6 +137,18 @@ def to_ary expect(filter.filters[:'0'].options[:methods]).to eql %i[to_s] end end + + context 'with another option set' do + let(:block) { proc { public_send(:object, converter: :new) } } + let(:name) { :objects } + + it 'has a filter with the right options' do + expect(filter.filters[:'0'].options).to have_key(:class) + expect(filter.filters[:'0'].options[:class]).to eql :Object + expect(filter.filters[:'0'].options).to have_key(:converter) + expect(filter.filters[:'0'].options[:converter]).to eql :new + end + end end end