Skip to content

Commit

Permalink
test(spec): add test examples for #pretty_value
Browse files Browse the repository at this point in the history
  • Loading branch information
RongRongTeng committed Aug 2, 2020
1 parent 5fa2505 commit a594665
Showing 1 changed file with 25 additions and 1 deletion.
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

0 comments on commit a594665

Please sign in to comment.