active_storage_validations icon indicating copy to clipboard operation
active_storage_validations copied to clipboard

[Validations] Validations fail when using dimension: { min: 1080..1080 } syntax

Open Mth0158 opened this issue 1 year ago • 0 comments

Hi,

In the readme, it is mentioned that we can use a short syntax for validating a min width and a min height at the same time, this looks like:

validates :feed_attachment, dimension: { min: 1080..1080 }

However, using this syntax makes the validations fail with RSpec, if I use:

it do
  is_expected.to validate_dimensions_of(:feed_attachment).width_min(1080).height_min(1080)
end

It will throw me an error saying:

     Failure/Error: is_expected.to validate_dimensions_of(:feed_attachment).width_min(1080).height_min(1080)
     
       is expected to validate dimensions of feed_attachment
         width between 1080 and 
         height between 1080 and 

Whereas if I use this syntax:

validates :feed_attachment, dimension: { width: { min: 1080 } }
validates :feed_attachment, dimension: { height: { min: 1080 } }

The previous test passes perfectly.

I could not find in the gem code why it acts this way but this looks like a bug to me, I'll keep the 2 validations for now even if it is 'dirty', keep in mind that it will display 2 error messages when your user fails to respect both width & height.

The 2 way to write these validations works the same in the app.

Mth0158 avatar Jul 22 '22 15:07 Mth0158