-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ActiveStorage direct uploads
Closes #3296
- Loading branch information
Showing
13 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//= require activestorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import "rails_admin/src/rails_admin/base"; | ||
import "flatpickr/dist/l10n/fr.js"; | ||
import * as ActiveStorage from "@rails/activestorage"; | ||
ActiveStorage.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
pin '@hotwired/turbo-rails', to: 'https://ga.jspm.io/npm:@hotwired/[email protected]/app/javascript/turbo/index.js' | ||
pin '@popperjs/core', to: 'https://ga.jspm.io/npm:@popperjs/[email protected]/dist/esm/popper.js' | ||
pin '@rails/actioncable/src', to: 'https://ga.jspm.io/npm:@rails/[email protected]/src/index.js' | ||
pin '@rails/activestorage', to: 'https://ga.jspm.io/npm:@rails/[email protected]/app/assets/javascripts/activestorage.esm.js' | ||
pin '@rails/ujs', to: 'https://ga.jspm.io/npm:@rails/[email protected]/lib/assets/compiled/rails-ujs.js' | ||
pin 'bootstrap', to: 'https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.esm.js' | ||
pin 'flatpickr', to: 'https://ga.jspm.io/npm:[email protected]/dist/flatpickr.js' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe 'ActiveStorage field', type: :request, active_record: true do | ||
subject { page } | ||
let(:field_test) { FactoryBot.create :field_test } | ||
before do | ||
# To suppress 'SQLite3::BusyException: database is locked' exception | ||
@original = page.driver.browser.url_blacklist # rubocop:disable Naming/InclusiveLanguage | ||
page.driver.browser.url_blacklist = ['/rails/active_storage/representations'] # rubocop:disable Naming/InclusiveLanguage | ||
end | ||
after { page.driver.browser.url_blacklist = @original } # rubocop:disable Naming/InclusiveLanguage | ||
|
||
describe 'direct upload', js: true do | ||
before do | ||
RailsAdmin.config FieldTest do | ||
edit do | ||
field(:active_storage_asset) { direct true } | ||
end | ||
end | ||
end | ||
|
||
it 'works' do | ||
visit edit_path(model_name: 'field_test', id: field_test.id) | ||
attach_file 'Active storage asset', file_path('test.jpg') | ||
expect_any_instance_of(ActiveStorage::DirectUploadsController).to receive(:create).and_call_original | ||
click_button 'Save' | ||
expect(page).to have_content 'Field test successfully updated' | ||
field_test.reload | ||
expect(field_test.active_storage_asset.filename).to eq 'test.jpg' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters