* feat: add an error column to the data update script * feat: save the error to the error field * feat: save the error when the script fails * feat: show the script error on the data update script page * chore: pass the error to mark_as_failed instead of having its own function * refactor: use presence * test: ensure that we test an error case of a data update script * chore: rename errorneous to failing * test: update some specs, working on the others * chore: update tests now that there are two files * chore: change error from a string to a text to allow for more char * feat: order the data update scripts by the latest script that ran * feat: when the script has succeeded reset error to nil * feat: create a model function that will allow the script to be force run * chore: oops remove the functions form the worker to the model so it can be re-used * feat: create an endpoint that will call the model method force run when we hit the api by clicking the button * feat: ensure that the we add an ajax call that calls the controller endpoint * chore: remove newline * refactor: change to a more Restful route * refactor: use Stimulus * fix: move the code from the model back into the worker so that we can reuse it in the controller * feat:call the worker in the force_run action and create a show route * feat: very first draft of using a polling mechanism on the show method after we kickoff the sidekiq job (still need to error handle) * chore: some syntax changes and unused variables * fix: call the method correctly with the paramters * feat: do some error handling * feat: error handing on the frontend * chore: use e instead of err * refactor: just pass the id instead of the whole script * chore: remove the button * fix: allow the id to be passed * feat: handle errors better * feat: limit the filename column width * refactor: use a common function to set the banner error * test: add a test fro rerun button * test: v1 of the data update script request * test: write some specs for the js controller * Update app/controllers/admin/data_update_scripts_controller.rb Co-authored-by: Michael Kohl <me@citizen428.net> * tests: update the data worker spec * chore: clean up the js controller and its tests * chore: remove whitespaces * chore: swap the functions based on the controller * chore: updates to the UI * chore: remove the standard error catch * chore: update the alert and error messages * chore: remove test for error handling for sidekiq run Co-authored-by: Michael Kohl <me@citizen428.net>
79 lines
2.4 KiB
Ruby
79 lines
2.4 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "/admin/data_update_scripts", type: :request do
|
|
let(:get_resource) { get "/admin/data_update_scripts" }
|
|
|
|
context "when the user is not an tech admin" do
|
|
let(:user) { create(:user) }
|
|
before { sign_in user }
|
|
|
|
describe "GET /admin/data_update_scripts" do
|
|
it "blocks the request" do
|
|
expect { get_resource }.to raise_error(StandardError)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when the user is a tech admin" do
|
|
let(:user) { create(:user, :admin, :tech_admin) }
|
|
|
|
before { sign_in user }
|
|
|
|
describe "GET /admin/data_update_scripts" do
|
|
it "allows the request" do
|
|
get_resource
|
|
expect(response).to have_http_status(:ok)
|
|
end
|
|
|
|
it "displays the data_update_scripts" do
|
|
script = create(:data_update_script)
|
|
get_resource
|
|
|
|
expect(response.body).to include(script.id.to_s)
|
|
expect(response.body).to include(script.run_at.to_s)
|
|
expect(response.body).to include(script.created_at.to_s)
|
|
expect(response.body).to include(script.status.to_s)
|
|
end
|
|
|
|
it "displays a 'Rerun' button when the script status is failed" do
|
|
script = create(:data_update_script, status: "failed")
|
|
get_resource
|
|
expect(response.body).to include("Re-run")
|
|
end
|
|
end
|
|
|
|
describe "GET /admin/data_update_scripts/:id" do
|
|
let(:script) {
|
|
create(
|
|
:data_update_script,
|
|
file_name: '20200214151804_data_update_test_script',
|
|
status: "succeeded"
|
|
)
|
|
}
|
|
let(:script_id) { script.id }
|
|
|
|
it "returns a data update script" do
|
|
get admin_data_update_script_path(id: script_id)
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
expect(script.id).to eq(response.parsed_body["response"]["id"])
|
|
expect(script.file_name).to eq(response.parsed_body["response"]["file_name"])
|
|
expect(script.status).to eq(response.parsed_body["response"]["status"])
|
|
end
|
|
end
|
|
|
|
describe "POST /admin/:id/force_run" do
|
|
let(:script) { create(:data_update_script, file_name: '20200214151804_data_update_test_script') }
|
|
let(:script_id) { script.id.to_s }
|
|
|
|
it "calls the the sidekiq worker" do
|
|
allow(DataUpdateWorker).to receive(:perform_async)
|
|
|
|
post "/admin/data_update_scripts/#{script_id}/force_run"
|
|
sidekiq_perform_enqueued_jobs
|
|
|
|
expect(DataUpdateWorker).to have_received(:perform_async).with(script_id)
|
|
end
|
|
end
|
|
end
|
|
end
|