I have installed this gem to validate and test active storage:
gem 'active_storage_validations'
# Asset Model
class Asset < ApplicationRecord
has_one_attached :portrait
validates(
:portrait,
content_type: ['image/png', 'image/jpeg', 'image/svg+xml'],
dimension: { width: { in: 8..512 }, height: { in: 8..512 } },
size: { less_than: 250.kilobytes }
)
end
# Asset test
require 'rails_helper'
RSpec.describe Asset do
it { is_expected.to validate_dimensions_of(:portrait).width_between(8..512).height_between(8..512) }
end
However, I get this error in my test, but not out of my test:
Asset validations is expected to validate the image dimensions of :portrait
Failure/Error: it { is_expected.to validate_dimensions_of(:portrait).width_between(8..512).height_between(8..512) }
NameError:
uninitialized constant ActiveStorageValidations::Matchers::OpenStruct