Testing Dragonfly Field Type Integration in Rails Admin
This test suite validates the Dragonfly field type implementation in Rails Admin, focusing on image handling and model integration. The tests ensure proper functionality of Dragonfly assets within the Rails Admin interface while maintaining compatibility with both image and non-image file types.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
railsadminteam/rails_admin
spec/rails_admin/config/fields/types/drangonfly_spec.rb
# frozen_string_literal: true
require 'spec_helper'
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
column :asset_uid, :varchar
end
end
it 'does not break' do
expect { RailsAdmin.config(NonDragonflyTest).fields }.not_to raise_error
end
end
end