Skip to content

Commit

Permalink
Remove unused code in Dragonfly field
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Jul 14, 2024
1 parent 34c5fec commit afee74e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/rails_admin/config/fields/types/dragonfly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Dragonfly < RailsAdmin::Config::Fields::Types::FileUpload
RailsAdmin::Config::Fields::Types.register(self)

register_instance_option :image? do
false unless value
if abstract_model.model.new.respond_to?("#{name}_name")
mime_type = Mime::Type.lookup_by_extension(bindings[:object].send("#{name}_name").to_s.split('.').last)
mime_type.to_s.match?(/^image/)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
23 changes: 23 additions & 0 deletions spec/rails_admin/config/fields/types/drangonfly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
RSpec.describe RailsAdmin::Config::Fields::Types::Dragonfly do
it_behaves_like 'a generic field type', :string_field, :dragonfly

let(:field) do
RailsAdmin.config('FieldTest').fields.detect do |f|
f.name == :dragonfly_asset
end.with(object: record)
end

describe '#image?' do
let(:file) { File.open(file_path('test.jpg')) }
let(:record) { FactoryBot.create :field_test, dragonfly_asset: file }

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

context 'with non-image' do
let(:file) { File.open(file_path('test.txt')) }

it 'returns false' do
expect(field.image?).to be false
end
end
end

describe 'with a model which does not extend Dragonfly::Model' do
before do
class NonDragonflyTest < Tableless
Expand Down

0 comments on commit afee74e

Please sign in to comment.