Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Return 200 for validation errors #155

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -21,7 +21,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -25,7 +25,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -22,7 +22,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session[:know_nhs_number] == I18n.t("coronavirus_form.questions.know_nhs_number.options.option_yes.label")
redirect_to controller: "coronavirus_form/#{NEXT_PAGE}", action: "show"
elsif session["check_answers_seen"]
Expand Down
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session[:live_in_england] == I18n.t("coronavirus_form.questions.live_in_england.options.option_no.label")
redirect_to controller: "coronavirus_form/not_eligible_england", action: "show"
elsif session["check_answers_seen"]
Expand Down
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session[:medical_conditions] == I18n.t("coronavirus_form.questions.medical_conditions.options.option_no.label")
redirect_to controller: "coronavirus_form/not_eligible_medical", action: "show"
elsif session["check_answers_seen"]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/coronavirus_form/name_controller.rb
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/coronavirus_form/nhs_letter_controller.rb
Expand Up @@ -20,7 +20,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/coronavirus_form/nhs_number_controller.rb
Expand Up @@ -18,7 +18,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -27,7 +27,7 @@ def submit
if invalid_fields.any?
flash.now[:validation] = invalid_fields
log_validation_error(invalid_fields)
render "coronavirus_form/#{PAGE}", status: :unprocessable_entity
render "coronavirus_form/#{PAGE}"
elsif session["check_answers_seen"]
redirect_to controller: "coronavirus_form/check_answers", action: "show"
else
Expand Down
Expand Up @@ -26,13 +26,13 @@

it "validates any option is chosen" do
post :submit, params: { basic_care_needs: "" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates a valid option is chosen" do
post :submit, params: { basic_care_needs: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does render templat imply a 200 or can we do to_have_http_status(:success) or something similar?


expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -27,7 +27,7 @@
it "validates any option is chosen" do
post :submit, params: { carry_supplies: "" }

expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand All @@ -39,7 +39,7 @@
it "validates a valid option is chosen" do
post :submit, params: { carry_supplies: "<script></script>" }

expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -34,7 +34,7 @@

it "does not move to next step with an invalid email address" do
post :submit, params: { email: "not-a-valid-email" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -40,7 +40,7 @@

it "does not move to next step if a field is missing" do
post :submit, params: { "date_of_birth" => { "day" => "31" } }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand All @@ -52,7 +52,7 @@
"year" => "not a number",
},
}
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -26,7 +26,7 @@

it "validates any option is chosen" do
post :submit, params: { dietary_requirements: "" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand All @@ -37,7 +37,7 @@

it "validates a valid option is chosen" do
post :submit, params: { dietary_requirements: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -26,7 +26,7 @@

it "validates any option is chosen" do
post :submit, params: { essential_supplies: "" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand All @@ -37,7 +37,7 @@

it "validates a valid option is chosen" do
post :submit, params: { essential_supplies: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -26,13 +26,13 @@

it "validates any option is chosen" do
post :submit, params: { know_nhs_number: "" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates a valid option is chosen" do
post :submit, params: { know_nhs_number: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -26,13 +26,13 @@

it "validates any option is chosen" do
post :submit, params: { live_in_england: "" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates a valid option is chosen" do
post :submit, params: { live_in_england: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -26,7 +26,7 @@

it "validates any option is chosen" do
post :submit, params: { medical_conditions: "" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand All @@ -42,7 +42,7 @@

it "validates a valid option is chosen" do
post :submit, params: { medical_conditions: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/coronavirus_form/name_controller_spec.rb
Expand Up @@ -38,13 +38,13 @@
%w(first_name last_name).each do |field|
it "validates #{field} is required" do
post :submit, params: params.except(field)
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates a value for #{field} is required" do
post :submit, params: params.merge(field => "")
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end
end
Expand All @@ -58,7 +58,7 @@

it "validates a valid option is chosen" do
post :submit, params: { first_name: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -26,13 +26,13 @@

it "validates any option is chosen" do
post :submit, params: { nhs_letter: "" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates a valid option is chosen" do
post :submit, params: { nhs_letter: "<script></script>" }
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -23,28 +23,28 @@
it "validates the nhs_number is required" do
post :submit, params: {}

expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates the nhs_number is a number" do
post :submit, params: { nhs_number: "abc" }

expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates the nhs_number is a ten digit number" do
post :submit, params: { nhs_number: "123" }

expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

it "validates the nhs_number is passes the checksum" do
post :submit, params: { nhs_number: "1234567890" }

expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end

Expand Down
Expand Up @@ -105,7 +105,7 @@
described_class::REQUIRED_FIELDS.each do |field|
it "requires that key #{field} be provided" do
post :submit, params: params.except(field)
expect(response).to have_http_status(:unprocessable_entity)

expect(response).to render_template(current_template)
end
end
Expand Down