diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694e..d93dcb7c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + def not_found + raise ActiveRecord::RecordNotFound + end end diff --git a/app/controllers/correspondence_controller.rb b/app/controllers/correspondence_controller.rb index f4675220..7125ebec 100644 --- a/app/controllers/correspondence_controller.rb +++ b/app/controllers/correspondence_controller.rb @@ -1,6 +1,6 @@ class CorrespondenceController < ApplicationController rescue_from Redis::CannotConnectError do - render file: "public/500-redis-down.html", status: :internal_server_error, layout: false + render "errors/internal_error", status: :internal_server_error, layout: false end def start; end @@ -42,7 +42,7 @@ def search def authenticate @correspondence = Correspondence.where(uuid: params[:uuid]).first if @correspondence.nil? - render file: Rails.root.join("public/404.html"), status: :not_found, layout: false + not_found and return else @correspondence.authenticate! CorrespondenceMailer.new_correspondence(@correspondence).deliver_later diff --git a/spec/controllers/correspondence_controller_spec.rb b/spec/controllers/correspondence_controller_spec.rb index c183b3e5..8b0eb9cf 100644 --- a/spec/controllers/correspondence_controller_spec.rb +++ b/spec/controllers/correspondence_controller_spec.rb @@ -106,8 +106,9 @@ context "when uuid not in database" do it "responds Not found" do - get :authenticate, params: { uuid: "ffffffff-eeee-dddd-cccc-bbbbbbbbbbb" } - expect(response).to have_http_status(:not_found) + expect { + get :authenticate, params: { uuid: "ffffffff-eeee-dddd-cccc-bbbbbbbbbbb" } + }.to raise_error(ActiveRecord::RecordNotFound) end end @@ -117,12 +118,18 @@ before { correspondence.authenticated_at = authenticated_time } it "does not update the authenticated at date" do - get :authenticate, params: { uuid: "3cc98e93-d11c-42ad-832d-f40113d3ec27" } + expect { + get :authenticate, params: { uuid: "3cc98e93-d11c-42ad-832d-f40113d3ec27" } + }.to raise_error(ActiveRecord::RecordNotFound) + expect(correspondence.authenticated_at).to eq authenticated_time end it "does not resend the email" do - get :authenticate, params: { uuid: "3cc98e93-d11c-42ad-832d-f40113d3ec27" } + expect { + get :authenticate, params: { uuid: "3cc98e93-d11c-42ad-832d-f40113d3ec27" } + }.to raise_error(ActiveRecord::RecordNotFound) + expect(CorrespondenceMailer).not_to receive(:new_correspondence) end end diff --git a/spec/controllers/errors_controller_spec.rb b/spec/controllers/errors_controller_spec.rb index 5988357c..e9fb7827 100644 --- a/spec/controllers/errors_controller_spec.rb +++ b/spec/controllers/errors_controller_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "rails_helper" RSpec.describe ErrorsController, type: :controller do context "when not found" do