Skip to content

Commit d3f86f4

Browse files
committed
Add test for exception handler
1 parent c17171a commit d3f86f4

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

spec/dummy/app/controllers/inertia_share_test_controller.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ class InertiaShareTestController < ApplicationController
44
inertia_share do
55
{
66
position: 'center',
7-
number: 29,
7+
number: number,
88
}
99
end
1010

1111
def share
1212
render inertia: 'ShareTestComponent'
1313
end
14+
15+
def error
16+
raise RuntimeError
17+
end
18+
19+
private
20+
21+
def number
22+
29
23+
end
1424
end

spec/dummy/config/application.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ class Application < Rails::Application
3232

3333
# Required for Rails 5.0 and 5.1
3434
config.secret_key_base = SecureRandom.hex
35+
36+
config.exceptions_app = ->(env) do
37+
Class.new(ActionController::Base) do
38+
def show
39+
render inertia: 'Error', props: {
40+
status: request.path_info[1..-1].to_i
41+
}
42+
end
43+
end.action(:show).call(env)
44+
end
3545
end
3646
end
37-

spec/dummy/config/environments/test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
}
2525

2626
# Show full error reports and disable caching.
27-
config.consider_all_requests_local = true
27+
config.consider_all_requests_local = false
2828
config.action_controller.perform_caching = false
2929
config.cache_store = :null_store
3030

3131
# Raise exceptions instead of rendering exception templates.
32-
config.action_dispatch.show_exceptions = false
32+
config.action_dispatch.show_exceptions = true
3333

3434
# Disable request forgery protection in test environment.
3535
config.action_controller.allow_forgery_protection = false

spec/dummy/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
get 'view_data' => 'inertia_render_test#view_data'
66
get 'component' => 'inertia_render_test#component'
77
get 'share' => 'inertia_share_test#share'
8+
get 'error' => 'inertia_share_test#error'
89
get 'share_with_inherited' => 'inertia_child_share_test#share_with_inherited'
910
get 'empty_test' => 'inertia_test#empty_test'
1011
get 'redirect_test' => 'inertia_test#redirect_test'

spec/inertia/sharing_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,14 @@
6363

6464
it { is_expected.to eq props }
6565
end
66+
67+
context 'using inertia share with exception handler' do
68+
let(:props) { { status: 500 } }
69+
70+
before do
71+
get error_path, headers: {'X-Inertia' => true}
72+
end
73+
74+
it { is_expected.to eq props }
75+
end
6676
end

0 commit comments

Comments
 (0)