File tree Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ def inertia_location(url)
109
109
110
110
def capture_inertia_errors ( options )
111
111
if ( inertia_errors = options . dig ( :inertia , :errors ) )
112
- session [ :inertia_errors ] = inertia_errors
112
+ session [ :inertia_errors ] = inertia_errors . to_hash
113
113
end
114
114
end
115
115
end
Original file line number Diff line number Diff line change
1
+ class MyError
2
+ def to_hash ( ) { uh : 'oh' } end
3
+ end
4
+
1
5
class InertiaTestController < ApplicationController
2
6
layout 'conditional' , only : [ :with_different_layout ]
3
7
@@ -43,6 +47,10 @@ def redirect_with_inertia_errors
43
47
redirect_to empty_test_path , inertia : { errors : { uh : 'oh' } }
44
48
end
45
49
50
+ def redirect_with_inertia_error_object
51
+ redirect_to empty_test_path , inertia : { errors : MyError . new }
52
+ end
53
+
46
54
def redirect_back_with_inertia_errors
47
55
redirect_back (
48
56
fallback_location : empty_test_path ,
Original file line number Diff line number Diff line change 23
23
get 'share_multithreaded_error' => 'inertia_multithreaded_share#share_multithreaded_error'
24
24
get 'redirect_with_inertia_errors' => 'inertia_test#redirect_with_inertia_errors'
25
25
post 'redirect_with_inertia_errors' => 'inertia_test#redirect_with_inertia_errors'
26
+ post 'redirect_with_inertia_error_object' => 'inertia_test#redirect_with_inertia_error_object'
26
27
post 'redirect_back_with_inertia_errors' => 'inertia_test#redirect_back_with_inertia_errors'
27
28
get 'error_404' => 'inertia_test#error_404'
28
29
get 'error_500' => 'inertia_test#error_500'
Original file line number Diff line number Diff line change 27
27
expect ( response . headers [ 'Location' ] ) . to eq ( empty_test_url )
28
28
expect ( session [ :inertia_errors ] ) . to include ( { uh : 'oh' } )
29
29
end
30
+
31
+ it 'serializes :inertia_errors to the session' do
32
+ post redirect_with_inertia_error_object_path ,
33
+ headers : { 'X-Inertia' => true }
34
+
35
+ expect ( response . status ) . to eq 302
36
+ expect ( response . headers [ 'Location' ] ) . to eq ( empty_test_url )
37
+ expect ( session [ :inertia_errors ] ) . to include ( { uh : 'oh' } )
38
+ end
30
39
end
31
40
end
32
41
end
You can’t perform that action at this time.
0 commit comments