Testing Shrine File Upload Integration in rails_admin
This test suite validates Shrine file upload integration within Rails Admin, focusing on file caching behavior and form submission scenarios. The tests ensure proper handling of file attachments during form validation and persistence.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
railsadminteam/rails_admin
spec/integration/fields/shrine_spec.rb
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Shrine field', type: :request, active_record: true do
subject { page }
before do
RailsAdmin.config FieldTest do
edit do
field :string_field
field :shrine_asset
end
end
end
it 'supports caching an uploaded file', js: true do
visit new_path(model_name: 'field_test')
attach_file 'Shrine asset', file_path('test.jpg')
fill_in 'field_test[string_field]', with: 'Invalid'
click_button 'Save'
expect(page).to have_content 'Field test failed to be created'
fill_in 'field_test[string_field]', with: ''
click_button 'Save'
expect(FieldTest.first.shrine_asset).to exist
end
end