Skip to content

Commit

Permalink
Update ActiveStorage field #image? spec to account for configured types
Browse files Browse the repository at this point in the history
`webp` is not currently a default configured image Mime::Type in Rails, so this includes a check where the application can register a type and RailsAdmin will render it accordingly.

This updates existing coverage as well to test against common image file types.
  • Loading branch information
codealchemy committed Sep 26, 2021
1 parent d9a7db3 commit 7691afd
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions spec/rails_admin/config/fields/types/active_storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
end

describe '#image?' do
context 'when attachment is an image' do
let(:record) { FactoryBot.create :field_test, active_storage_asset: {io: StringIO.new('dummy'), filename: "test.jpg", content_type: "image/jpeg"} }

it 'returns true' do
expect(field.image?).to be_truthy
context 'configured Mime::Types' do
before { Mime::Type.register 'image/webp', :webp }
after { Mime::Type.unregister :webp }

%w[jpg jpeg png gif svg webp].each do |image_type_ext|
context "when attachment is a '#{image_type_ext}' file" do
let(:record) { FactoryBot.create :field_test, active_storage_asset: {io: StringIO.new('dummy'), filename: "test.#{image_type_ext}"} }

it 'returns true' do
expect(field.image?).to be_truthy
end
end
end
end

Expand Down

0 comments on commit 7691afd

Please sign in to comment.