Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/error_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

class ErrorController < ApplicationController
skip_before_action :authenticate_user!
skip_after_action :verify_authorized

def index
end

def create
raise StandardError.new "This is an intentional test exception"
end
end
5 changes: 3 additions & 2 deletions app/views/error/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="card text-center">
<div class="card-body">
<h1 class="card-title" style="color:red">We're sorry, but something went wrong.</h1>
<p class="card-text" style="color:grey">If you are the application owner check the logs for more information.</p>
<h1 class="card-title">Intentional Error Test</h1>
<p class="card-text" style="color:grey">Click the button below to trigger an intentional test exception.</p>
<%= button_to "Trigger Exception", error_path, method: :post, class: "btn btn-danger", data: { turbo: false } %>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
end

get "/error", to: "error#index"
post "/error", to: "error#create"

namespace :api do
namespace :v1 do
Expand Down
16 changes: 13 additions & 3 deletions spec/requests/error_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
require "rails_helper"

RSpec.describe "/error", type: :request do
it "raises an error causing an internal server error" do
expect {
describe "GET /error" do
it "renders the error test page" do
get error_path
}.to raise_error(StandardError, /This is an intentional test exception/)

expect(response).to be_successful
end
end

describe "POST /error" do
it "raises an error causing an internal server error" do
expect {
post error_path
}.to raise_error(StandardError, /This is an intentional test exception/)
end
end
end
Loading