diff --git a/lib/rails_admin/config/fields/types/dragonfly.rb b/lib/rails_admin/config/fields/types/dragonfly.rb index 3f4049742e..80f9fe5a4e 100644 --- a/lib/rails_admin/config/fields/types/dragonfly.rb +++ b/lib/rails_admin/config/fields/types/dragonfly.rb @@ -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/) diff --git a/spec/fixtures/test.txt b/spec/fixtures/test.txt new file mode 100644 index 0000000000..30d74d2584 --- /dev/null +++ b/spec/fixtures/test.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/spec/rails_admin/config/fields/types/drangonfly_spec.rb b/spec/rails_admin/config/fields/types/drangonfly_spec.rb index 354d00b923..da8cd3c616 100644 --- a/spec/rails_admin/config/fields/types/drangonfly_spec.rb +++ b/spec/rails_admin/config/fields/types/drangonfly_spec.rb @@ -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