Skip to content

Commit

Permalink
Add direct upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ehasrouni committed Nov 20, 2024
1 parent b9ae4dc commit 9db03bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/views/maintenance_tasks/tasks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% if @task.csv_task? %>
<div class="block">
<%= 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) %>
</div>
<% end %>
<% parameter_names = @task.parameter_names %>
Expand Down
27 changes: 26 additions & 1 deletion test/system/maintenance_tasks/runs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 9db03bc

Please sign in to comment.