Skip to content

Commit

Permalink
use value instead url in link_to body
Browse files Browse the repository at this point in the history
  • Loading branch information
buncis authored and mshibuya committed Jun 30, 2018
1 parent f90e3a8 commit e3770ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/types/file_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FileUpload < RailsAdmin::Config::Fields::Base
image_html = v.image_tag(thumb_url, class: 'img-thumbnail')
url != thumb_url ? v.link_to(image_html, url, target: '_blank') : image_html
else
v.link_to(nil, url, target: '_blank')
v.link_to(value, url, target: '_blank')
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/rails_admin/config/fields/types/file_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,31 @@
end
end
end

describe '#pretty_value' do
context 'when the field is not image' do
before do
RailsAdmin.config FieldTest do
field :string_field, :file_upload do
def resource_url
'http://example.com/dummy.txt'
end
end
end
end

let :rails_admin_field do
RailsAdmin.config('FieldTest').fields.detect do |f|
f.name == :string_field
end.with(
object: FieldTest.new(string_field: 'dummy.txt'),
view: ApplicationController.new.view_context,
)
end

it 'has non-empty link text' do
expect(rails_admin_field.pretty_value).to eq '<a target="_blank" href="http://example.com/dummy.txt">dummy.txt</a>'
end
end
end
end

0 comments on commit e3770ba

Please sign in to comment.