Skip to content

Commit 2645f39

Browse files
authored
Merge pull request #6752 from costajohnt/fix/error-page-button
fix: require button click to trigger intentional test exception
2 parents a7cb545 + df511e5 commit 2645f39

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

app/controllers/error_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
class ErrorController < ApplicationController
44
skip_before_action :authenticate_user!
5+
skip_after_action :verify_authorized
56

67
def index
8+
end
9+
10+
def create
711
raise StandardError.new "This is an intentional test exception"
812
end
913
end

app/views/error/index.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div class="card text-center">
22
<div class="card-body">
3-
<h1 class="card-title" style="color:red">We're sorry, but something went wrong.</h1>
4-
<p class="card-text" style="color:grey">If you are the application owner check the logs for more information.</p>
3+
<h1 class="card-title">Intentional Error Test</h1>
4+
<p class="card-text" style="color:grey">Click the button below to trigger an intentional test exception.</p>
5+
<%= button_to "Trigger Exception", error_path, method: :post, class: "btn btn-danger", data: { turbo: false } %>
56
</div>
67
</div>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
end
242242

243243
get "/error", to: "error#index"
244+
post "/error", to: "error#create"
244245

245246
namespace :api do
246247
namespace :v1 do

spec/requests/error_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
require "rails_helper"
22

33
RSpec.describe "/error", type: :request do
4-
it "raises an error causing an internal server error" do
5-
expect {
4+
describe "GET /error" do
5+
it "renders the error test page" do
66
get error_path
7-
}.to raise_error(StandardError, /This is an intentional test exception/)
7+
8+
expect(response).to be_successful
9+
end
10+
end
11+
12+
describe "POST /error" do
13+
it "raises an error causing an internal server error" do
14+
expect {
15+
post error_path
16+
}.to raise_error(StandardError, /This is an intentional test exception/)
17+
end
818
end
919
end

0 commit comments

Comments
 (0)