|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +RSpec.describe 'MultipleActiveStorage field', type: :request, active_record: true do |
| 6 | + subject { page } |
| 7 | + before do |
| 8 | + RailsAdmin.config FieldTest do |
| 9 | + edit do |
| 10 | + field :active_storage_assets |
| 11 | + end |
| 12 | + end |
| 13 | + # To suppress 'SQLite3::BusyException: database is locked' exception |
| 14 | + @original = page.driver.browser.url_blacklist # rubocop:disable Naming/InclusiveLanguage |
| 15 | + page.driver.browser.url_blacklist = ['/rails/active_storage/'] # rubocop:disable Naming/InclusiveLanguage |
| 16 | + end |
| 17 | + after { page.driver.browser.url_blacklist = @original } # rubocop:disable Naming/InclusiveLanguage |
| 18 | + |
| 19 | + it 'supports uploading multiple files', js: true do |
| 20 | + visit new_path(model_name: 'field_test') |
| 21 | + attach_file 'Active storage assets', [file_path('test.jpg'), file_path('test.png')] |
| 22 | + click_button 'Save' |
| 23 | + is_expected.to have_content 'Field test successfully created' |
| 24 | + expect(FieldTest.first.active_storage_assets.map { |image| image.filename.to_s }).to match_array ['test.jpg', 'test.png'] |
| 25 | + end |
| 26 | + |
| 27 | + context 'when working with existing files' do |
| 28 | + let(:field_test) { FactoryBot.create(:field_test, active_storage_assets: ['test.jpg', 'test.png'].map { |img| {io: File.open(file_path(img)), filename: img} }) } |
| 29 | + |
| 30 | + it 'supports appending a file', js: true do |
| 31 | + visit edit_path(model_name: 'field_test', id: field_test.id) |
| 32 | + attach_file 'Active storage assets', [file_path('test.gif')] |
| 33 | + click_button 'Save' |
| 34 | + is_expected.to have_content 'Field test successfully updated' |
| 35 | + field_test.reload |
| 36 | + expect(field_test.active_storage_assets.map { |image| image.filename.to_s }).to eq ['test.jpg', 'test.png', 'test.gif'] |
| 37 | + end |
| 38 | + |
| 39 | + it 'supports deleting a file', js: true do |
| 40 | + visit edit_path(model_name: 'field_test', id: field_test.id) |
| 41 | + click_link "Delete 'Active storage assets' #1" |
| 42 | + click_button 'Save' |
| 43 | + is_expected.to have_content 'Field test successfully updated' |
| 44 | + field_test.reload |
| 45 | + expect(field_test.active_storage_assets.map { |image| image.filename.to_s }).to eq ['test.png'] |
| 46 | + end |
| 47 | + end |
| 48 | +end |
0 commit comments