Browse Source

Add not found case

pull/48/head
baarkerlounger 4 years ago
parent
commit
3705ece2db
  1. 13
      app/controllers/case_logs_controller.rb
  2. 4
      app/views/form/_check_answers_table.html.erb
  3. 6
      app/views/form/check_answers.html.erb
  4. 11
      spec/requests/case_log_controller_spec.rb

13
app/controllers/case_logs_controller.rb

@ -22,11 +22,14 @@ class CaseLogsController < ApplicationController
end
def update
@case_log = CaseLog.find(params[:id])
if @case_log.update(api_case_log_params)
render json: @case_log, status: :ok
if case_log = CaseLog.find_by(id: params[:id])
if case_log.update(api_case_log_params)
render json: case_log, status: :ok
else
render json: { errors: case_log.errors.full_messages }, status: :unprocessable_entity
end
else
render json: { errors: @case_log.errors.full_messages }, status: :unprocessable_entity
render json: { error: "Case Log #{params[:id]} not found" }, status: :not_found
end
end
@ -61,7 +64,7 @@ class CaseLogsController < ApplicationController
@case_log = CaseLog.find(params[:case_log_id])
current_url = request.env["PATH_INFO"]
subsection = current_url.split("/")[-2]
render "form/check_answers", locals: { case_log: @case_log, subsection: subsection }
render "form/check_answers", locals: { subsection: subsection }
end
form = Form.new(2021, 2022)

4
app/views/form/_check_answers_table.html.erb

@ -4,10 +4,10 @@
<%= question_info["check_answer_label"].to_s %>
<dt>
<dd class="govuk-summary-list__value">
<%= case_log[question_title] %>
<%= @case_log[question_title] %>
</dd>
<dd class="govuk-summary-list__actions">
<%= create_update_answer_link(case_log[question_title], case_log["id"], page)%>
<%= create_update_answer_link(@case_log[question_title], @case_log.id, page)%>
</dd>
</div>
</dl>

6
app/views/form/check_answers.html.erb

@ -2,11 +2,11 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l">Check the answers you gave for <%= subsection.humanize(capitalize: false) %></h1>
<%= display_answered_questions_summary(subsection, case_log) %>
<%= display_answered_questions_summary(subsection, @case_log) %>
<% subsection_pages(subsection).each do |page, page_info| %>
<% page_info["questions"].each do |question_title, question_info| %>
<% if total_questions(subsection, case_log).include?(question_title) %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: case_log, page: page } %>
<% if total_questions(subsection, @case_log).include?(question_title) %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: @case_log, page: page } %>
<%end %>
<%end %>
<% end %>

11
spec/requests/case_log_controller_spec.rb

@ -103,9 +103,10 @@ RSpec.describe CaseLogsController, type: :request do
let(:params) do
{ tenant_code: "New Value" }
end
let(:id) { case_log.id }
before do
patch "/case_logs/#{case_log.id}", headers: headers, params: params.to_json
patch "/case_logs/#{id}", headers: headers, params: params.to_json
end
it "returns http success" do
@ -118,6 +119,14 @@ RSpec.describe CaseLogsController, type: :request do
expect(case_log.property_postcode).to eq("Old Value")
end
context "invalid case log id" do
let(:id) { (CaseLog.order(:id).last&.id || 0) + 1 }
it "returns 404" do
expect(response).to have_http_status(:not_found)
end
end
context "request with invalid credentials" do
let(:basic_credentials) do
ActionController::HttpAuthentication::Basic.encode_credentials(api_username, "Oops")

Loading…
Cancel
Save