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