Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rails_admin/config/fields/types/multiple_file_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def initialize(value)
image_html = v.image_tag(thumb_url, class: 'img-thumbnail')
url != thumb_url ? v.link_to(image_html, url, target: '_blank', rel: 'noopener noreferrer') : image_html
else
v.link_to(value, url, target: '_blank', rel: 'noopener noreferrer')
display_value = value.respond_to?(:filename) ? value.filename : value
v.link_to(display_value, url, target: '_blank', rel: 'noopener noreferrer')
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,34 @@
let(:field) do
RailsAdmin.config('FieldTest').fields.detect do |f|
f.name == :active_storage_assets
end.with(object: record)
end.with(
object: record,
view: ApplicationController.new.view_context,
)
end

describe RailsAdmin::Config::Fields::Types::MultipleActiveStorage::ActiveStorageAttachment do
describe '#pretty_value' do
subject { field.pretty_value }

context 'when attachment is not an image' do
let(:record) { FactoryBot.create :field_test, active_storage_assets: [{io: StringIO.new('dummy'), filename: "test.txt", content_type: "text/plain"}] }

it 'uses filename as link text' do
expect(Nokogiri::HTML(subject).text).to eq 'test.txt'
end
end

context 'when the field is an image' do
let(:record) { FactoryBot.create :field_test, active_storage_assets: [{io: StringIO.new('dummy'), filename: "test.jpg", content_type: "image/jpeg"}] }

it 'shows thumbnail image with a link' do
expect(Nokogiri::HTML(subject).css('img').attribute('src').value).to match(%r{rails/active_storage/representations})
expect(Nokogiri::HTML(subject).css('a').attribute('href').value).to match(%r{rails/active_storage/blobs})
end
end
end

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