diff --git a/lib/active_storage_validations/attached_validator.rb b/lib/active_storage_validations/attached_validator.rb index ff16d9b3..6080c6d1 100644 --- a/lib/active_storage_validations/attached_validator.rb +++ b/lib/active_storage_validations/attached_validator.rb @@ -11,16 +11,16 @@ class AttachedValidator < ActiveModel::EachValidator # :nodoc: ERROR_TYPES = %i[blank].freeze def check_validity! - %i(allow_nil allow_blank).each do |not_authorized_option| + %i[allow_nil allow_blank].each do |not_authorized_option| if options.include?(not_authorized_option) - raise ArgumentError, "You cannot pass the :#{not_authorized_option} option to this validator" + raise ArgumentError, "You cannot pass the :#{not_authorized_option} option to the #{self.class.name.split('::').last.underscore}" end end end def validate_each(record, attribute, _value) return if record.send(attribute).attached? && - !Array.wrap(record.send(attribute)).all? { |file| file.marked_for_destruction? } + !Array.wrap(record.send(attribute)).all?(&:marked_for_destruction?) errors_options = initialize_error_options(options) add_error(record, attribute, ERROR_TYPES.first, **errors_options) diff --git a/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb b/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb index 8b9a8a39..7730ffd5 100644 --- a/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb +++ b/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DoesNotWorkWithAllowBlankOption extend ActiveSupport::Concern @@ -5,7 +7,12 @@ module DoesNotWorkWithAllowBlankOption subject { validator_test_class::WithAllowBlank.new(params) } describe 'when used with :allow_blank option' do - it { is_expected_to_raise_error(ArgumentError, "You cannot pass the :allow_blank option to this validator") } + it do + is_expected_to_raise_error( + ArgumentError, + "You cannot pass the :allow_blank option to the #{validator_test_class.name.delete('::').underscore}" + ) + end end end end diff --git a/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb b/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb index 82100708..46cb0396 100644 --- a/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb +++ b/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DoesNotWorkWithAllowNilOption extend ActiveSupport::Concern @@ -5,7 +7,12 @@ module DoesNotWorkWithAllowNilOption subject { validator_test_class::WithAllowNil.new(params) } describe 'when used with :allow_nil option' do - it { is_expected_to_raise_error(ArgumentError, "You cannot pass the :allow_nil option to this validator") } + it do + is_expected_to_raise_error( + ArgumentError, + "You cannot pass the :allow_nil option to the #{validator_test_class.name.delete('::').underscore}" + ) + end end end end