From 9db03bc3645a9fda48af3517f60c4bff80ff241e Mon Sep 17 00:00:00 2001 From: Elio Hasrouni Date: Tue, 19 Nov 2024 09:43:44 -0500 Subject: [PATCH] Add direct upload --- .../maintenance_tasks/tasks/show.html.erb | 2 +- test/system/maintenance_tasks/runs_test.rb | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/views/maintenance_tasks/tasks/show.html.erb b/app/views/maintenance_tasks/tasks/show.html.erb index d7fd6345..eac87667 100644 --- a/app/views/maintenance_tasks/tasks/show.html.erb +++ b/app/views/maintenance_tasks/tasks/show.html.erb @@ -9,7 +9,7 @@ <% if @task.csv_task? %>
<%= form.label :csv_file %> - <%= form.file_field :csv_file, accept: "text/csv" %> + <%= form.file_field :csv_file, accept: "text/csv", direct_upload: Rails.application.config.respond_to?(:assets) %>
<% end %> <% parameter_names = @task.parameter_names %> diff --git a/test/system/maintenance_tasks/runs_test.rb b/test/system/maintenance_tasks/runs_test.rb index 23188d4e..f8e69e47 100644 --- a/test/system/maintenance_tasks/runs_test.rb +++ b/test/system/maintenance_tasks/runs_test.rb @@ -60,10 +60,34 @@ class RunsTest < ApplicationSystemTestCase MaintenanceTasks.metadata = nil end - test "run a CSV Task" do + test "run a CSV Task without direct upload" do + Rails.application.config.stubs(:respond_to?).with(:assets).returns(false) visit maintenance_tasks_path click_on("Maintenance::ImportPostsTask") + + assert_selector("input[type=file]") do |input| + assert_nil(input["data-direct-upload-url"]) + end + + attach_file("csv_file", "test/fixtures/files/sample.csv") + click_on "Run" + + assert_title "Maintenance::ImportPostsTask" + assert_text "Enqueued" + assert_text "Waiting to start." + end + + test "run a CSV Task with direct upload" do + Rails.application.config.stubs(:respond_to?).with(:assets).returns(true) + visit maintenance_tasks_path + + click_on("Maintenance::ImportPostsTask") + + assert_selector("input[type=file]") do |input| + assert_equal(input["data-direct-upload-url"], rails_direct_uploads_url) + end + attach_file("csv_file", "test/fixtures/files/sample.csv") click_on "Run" @@ -105,6 +129,7 @@ class RunsTest < ApplicationSystemTestCase end test "download the CSV attached to a run for a CSV Task" do + Rails.application.config.stubs(:respond_to?).with(:assets).returns(false) visit(maintenance_tasks_path) click_on("Maintenance::ImportPostsTask")