File tree Expand file tree Collapse file tree 4 files changed +39
-9
lines changed Expand file tree Collapse file tree 4 files changed +39
-9
lines changed Original file line number Diff line number Diff line change @@ -67,16 +67,17 @@ def default_render
67
67
68
68
def redirect_to ( options = { } , response_options = { } )
69
69
capture_inertia_errors ( response_options )
70
- super ( options , response_options )
70
+ super
71
71
end
72
72
73
- def redirect_back ( fallback_location : , allow_other_host : true , **options )
73
+ def redirect_back ( **options )
74
74
capture_inertia_errors ( options )
75
- super (
76
- fallback_location : fallback_location ,
77
- allow_other_host : allow_other_host ,
78
- **options ,
79
- )
75
+ super
76
+ end
77
+
78
+ def redirect_back_or_to ( _fallback_location , **options )
79
+ capture_inertia_errors ( options )
80
+ super
80
81
end
81
82
82
83
private
Original file line number Diff line number Diff line change @@ -50,6 +50,13 @@ def redirect_back_with_inertia_errors
50
50
)
51
51
end
52
52
53
+ def redirect_back_or_to_with_inertia_errors
54
+ redirect_back_or_to (
55
+ empty_test_path ,
56
+ inertia : { errors : { go : 'back!' } }
57
+ )
58
+ end
59
+
53
60
def error_404
54
61
render inertia : 'ErrorComponent' , status : 404
55
62
end
Original file line number Diff line number Diff line change 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
26
post 'redirect_back_with_inertia_errors' => 'inertia_test#redirect_back_with_inertia_errors'
27
+ post 'redirect_back_or_to_with_inertia_errors' => 'inertia_test#redirect_back_or_to_with_inertia_errors'
27
28
get 'error_404' => 'inertia_test#error_404'
28
29
get 'error_500' => 'inertia_test#error_500'
29
30
get 'content_type_test' => 'inertia_test#content_type_test'
Original file line number Diff line number Diff line change 39
39
redirect_back_with_inertia_errors_path ,
40
40
headers : {
41
41
'X-Inertia' => true ,
42
- 'HTTP_REFERER' => "http://example.com/current-path"
42
+ 'HTTP_REFERER' => "http://www. example.com/current-path"
43
43
}
44
44
)
45
45
expect ( response . status ) . to eq 302
46
- expect ( response . headers [ 'Location' ] ) . to eq ( 'http://example.com/current-path' )
46
+ expect ( response . headers [ 'Location' ] ) . to eq ( 'http://www.example.com/current-path' )
47
+ expect ( session [ :inertia_errors ] ) . to include ( { go : 'back!' } )
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ describe 'redirect_back_or_to' do
54
+ context 'with an [:inertia][:errors] option' do
55
+ context 'with a post request' do
56
+ it 'adds :inertia_errors to the session' do
57
+ skip ( "Requires Rails 7.0 or higher" ) if Rails . version < '7'
58
+
59
+ post (
60
+ redirect_back_or_to_with_inertia_errors_path ,
61
+ headers : {
62
+ 'X-Inertia' => true ,
63
+ 'HTTP_REFERER' => "http://www.example.com/current-path"
64
+ }
65
+ )
66
+ expect ( response . status ) . to eq 302
67
+ expect ( response . headers [ 'Location' ] ) . to eq ( 'http://www.example.com/current-path' )
47
68
expect ( session [ :inertia_errors ] ) . to include ( { go : 'back!' } )
48
69
end
49
70
end
You can’t perform that action at this time.
0 commit comments