-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Background processing and UI Forms for CSV exports (#198)
This change adds the scaffolding to let an administrator: 1. Select 1-3 objects for a CSV export 2. Submit an Export job 3. Run the job in the background 4. View the results 5. Download the exported file We expect to provide a different UX for selecting items for export, so the submission form is very bare-bones but functional. The status (show) page for exports need additional design but provides enough functionality to download the exported CSV for testing.
- Loading branch information
Showing
7 changed files
with
175 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
class BatchExportJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(export_job) | ||
# probably not optimal, but enough until we get | ||
# import hammered out | ||
Tenejo::CsvExporter.new(export_job).run | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<h1>New <%= @job.class %></h1> | ||
|
||
<%= form_with(model: @job, local: true) do |form| %> | ||
<% if @job.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@job.errors.count, "error") %> prohibited this job from being saved:</h2> | ||
|
||
<ul> | ||
<% @job.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= form.label :identifiers %> | ||
<%= form.text_field :identifiers, id: 'export_identifiers_0', value: @job.identifiers[0], multiple: true %> | ||
</div> | ||
<div class="field"> | ||
<%= form.label :identifiers %> | ||
<%= form.text_field :identifiers, id: 'export_identifiers_1', value: @job.identifiers[1], multiple: true %> | ||
</div> | ||
<div class="field"> | ||
<%= form.label :identifiers %> | ||
<%= form.text_field :identifiers, id: 'export_identifiers_2', value: @job.identifiers[2], multiple: true %> | ||
</div> | ||
<br/> | ||
<div class="actions"> | ||
<%= form.submit 'Submit', type: 'submit' %> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe "/exports", type: :request do | ||
let(:admin) { FactoryBot.create(:user, :admin) } | ||
let(:export) { Export.new(user: admin) } | ||
|
||
before do | ||
sign_in admin | ||
end | ||
|
||
describe "GET /index" do | ||
it "redirects to /jobs/index" do | ||
get exports_path | ||
expect(response).to redirect_to jobs_path | ||
end | ||
end | ||
|
||
describe "GET /new" do | ||
it "renders a successful response" do | ||
get new_export_path | ||
expect(response).to render_template('exports/new') | ||
end | ||
end | ||
|
||
describe "GET /show" do | ||
it "displays info for an export job" do | ||
export.save! | ||
get export_path export | ||
expect(response).to render_template('exports/show') | ||
end | ||
end | ||
|
||
describe "POST /create" do | ||
it "creates a new export job" do | ||
expect { | ||
post exports_path, params: { export: { identifiers: [] } } | ||
}.to change(Export, :count).by(1) | ||
end | ||
|
||
it "queues a new background job" do | ||
ActiveJob::Base.queue_adapter = :test | ||
expect { | ||
post exports_path, params: { export: { identifiers: [] } } | ||
} .to enqueue_job(BatchExportJob).with(Job.last).on_queue(:default) | ||
end | ||
|
||
it "redirects to the submitted export show view" do | ||
post exports_path, params: { export: { identifiers: [] } } | ||
expect(response).to redirect_to Export.last | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe ExportsController, type: :routing do | ||
describe "routing" do | ||
it "routes to #index" do | ||
expect(get: "/exports").to route_to("exports#index") | ||
end | ||
|
||
it "routes to #new" do | ||
expect(get: "/exports/new").to route_to("exports#new") | ||
end | ||
|
||
it "routes to #show" do | ||
expect(get: "/exports/1").to route_to("exports#show", id: "1") | ||
end | ||
|
||
it "routes to #create" do | ||
expect(post: "/exports").to route_to("exports#create") | ||
end | ||
|
||
# Preflight jobs are not editable after creation | ||
context 'invalid routes' do | ||
it "does not route to #edit" do | ||
expect(get: "/exports/1/edit").not_to be_routable | ||
end | ||
|
||
it "does not route to #update via PUT" do | ||
expect(put: "/exports/1").not_to be_routable | ||
end | ||
|
||
it "does not route to #update via PATCH" do | ||
expect(patch: "/exports/1").not_to be_routable | ||
end | ||
|
||
it "does not route to #destroy" do | ||
expect(delete: "/exports/1").not_to be_routable | ||
end | ||
end | ||
end | ||
end |