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
6767
6868 def redirect_to ( options = { } , response_options = { } )
6969 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
8071 end
8172
8273 private
Original file line number Diff line number Diff line change @@ -58,6 +58,13 @@ def redirect_back_with_inertia_errors
5858 )
5959 end
6060
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+
6168 def error_404
6269 render inertia : 'ErrorComponent' , status : 404
6370 end
Original file line number Diff line number Diff line change 2525 post 'redirect_with_inertia_errors' => 'inertia_test#redirect_with_inertia_errors'
2626 post 'redirect_with_inertia_error_object' => 'inertia_test#redirect_with_inertia_error_object'
2727 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'
2829 get 'error_404' => 'inertia_test#error_404'
2930 get 'error_500' => 'inertia_test#error_500'
3031 get 'content_type_test' => 'inertia_test#content_type_test'
Original file line number Diff line number Diff line change 4848 redirect_back_with_inertia_errors_path ,
4949 headers : {
5050 'X-Inertia' => true ,
51- 'HTTP_REFERER' => "http://example.com/current-path"
51+ 'HTTP_REFERER' => "http://www. example.com/current-path"
5252 }
5353 )
5454 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' )
5677 expect ( session [ :inertia_errors ] ) . to include ( { go : 'back!' } )
5778 end
5879 end
You can’t perform that action at this time.
0 commit comments