Testing ActionText Field Integration in rails_admin
This integration test suite validates the ActionText field functionality in Rails Admin, focusing on asset loading behavior and warning messages. The tests ensure proper rendering and configuration of ActionText fields while handling different Rails versions and asset loading scenarios.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
railsadminteam/rails_admin
spec/integration/fields/action_text_spec.rb
# frozen_string_literal: true
require 'spec_helper'
if defined?(ActionText)
RSpec.describe 'ActionText field', type: :request, js: true do
subject { page }
before do
RailsAdmin.config FieldTest do
edit do
field :action_text_field
end
end
end
it 'works without error' do
allow(ConsoleLogger).to receive(:warn).with(/ActionText assets should be loaded statically/)
expect { visit new_path(model_name: 'field_test') }.not_to raise_error
is_expected.to have_selector('trix-toolbar')
end
if RailsAdmin.config.asset_source == :sprockets && Rails.gem_version < Gem::Version.new('7.0')
it 'shows a warning if ActionText assets are loaded dynamically' do
expect(ConsoleLogger).to receive(:warn).with(/ActionText assets should be loaded statically/)
visit new_path(model_name: 'field_test')
is_expected.to have_selector('trix-toolbar')
end
it 'allows suppressing the warning' do
RailsAdmin.config FieldTest do
edit do
field :action_text_field do
warn_dynamic_load false
end
end
end
expect(ConsoleLogger).not_to receive(:warn).with(/ActionText assets should be loaded statically/)
visit new_path(model_name: 'field_test')
is_expected.to have_selector('trix-toolbar')
end
end
end
end