Skip to content

Commit

Permalink
Removing the unnecessary WorksWizardController#rescue_aasm_error
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed May 24, 2024
1 parent 4099280 commit 9a2406c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
15 changes: 1 addition & 14 deletions app/controllers/works_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,6 @@ def file_location_url
end
helper_method :file_location_url

def rescue_aasm_error
yield
rescue AASM::InvalidTransition => error
message = message_from_aasm_error(aasm_error: error, work: @work)

Honeybadger.notify("Invalid #{@work.current_transition}: #{error.message} errors: #{message}")
transition_error_message = "We apologize, the following errors were encountered: #{message}."
@errors = [transition_error_message]

# redirect_to root_url, notice: transition_error_message
redirect_aasm_error(transition_error_message)
end

private

def edit_helper(view_name, redirect_url)
Expand Down Expand Up @@ -226,7 +213,7 @@ def readme_file_param
patch_params[:readme_file]
end

def rescue_aasm_error_dis
def rescue_aasm_error
super
rescue StandardError => generic_error
redirect_to root_url, notice: "We apologize, an error was encountered: #{generic_error.message}. Please contact the PDC Describe administrators."
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/works_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,6 @@
post :approve, params: { id: work.id }
expect(response.status).to be 302
# rubocop:disable Layout/LineLength
# binding.pry
# "We apologize, the following errors were encountered: You must include a README. <a href='/works/1/readme-select'>Please upload one</a>, You must include at least one file. <a href='/works/1/file-upload'>Please upload one</a>. Please contact the PDC Describe administrators for any assistance."
expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: You must include a README. <a href='#{work_readme_select_path(work)}'>Please upload one</a>, You must include at least one file. <a href='#{work_file_upload_path(work)}'>Please upload one</a>. Please contact the PDC Describe administrators for any assistance."])
# rubocop:enable Layout/LineLength
end
Expand Down
27 changes: 2 additions & 25 deletions spec/controllers/works_wizard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
expect(response.status).to be 302
expect(work.reload).to be_draft
# rubocop:disable Layout/LineLength
expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: Must provide a description."])
expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: Must provide a description. Please contact the PDC Describe administrators for any assistance."])
# rubocop:enable Layout/LineLength
end
end
Expand All @@ -369,29 +369,6 @@
end
end

context "a work with multiple README files" do
describe "#validate" do
before do
stub_s3(data: [
FactoryBot.build(:s3_readme),
FactoryBot.build(:s3_readme)
])
sign_in(user)
end

it "renders the error message" do
work.save
post :validate, params: { id: work.id }
expect(response).to redirect_to(edit_work_wizard_path(work))
expect(response.status).to be 302
expect(work.reload).to be_draft
# rubocop:disable Layout/LineLength
expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: You must provide only one README file upload."])
# rubocop:enable Layout/LineLength
end
end
end

context "a work with one README but no uploaded files" do
describe "#validate" do
before do
Expand Down Expand Up @@ -425,7 +402,7 @@
expect(response.status).to be 302
expect(work.reload).to be_draft
# rubocop:disable Layout/LineLength
expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: You must include a README. <a href='#{work_readme_select_path(work)}'>Please upload one</a>."])
expect(assigns[:errors]).to eq(["We apologize, the following errors were encountered: You must include a README. <a href='#{work_readme_select_path(work)}'>Please upload one</a>. Please contact the PDC Describe administrators for any assistance."])
# rubocop:enable Layout/LineLength
end
end
Expand Down

0 comments on commit 9a2406c

Please sign in to comment.