Skip to content

Commit 27a491b

Browse files
authored
Merge pull request #60 from ledermann/fix-redirect
Fix compatibility with "responders" gem (and thus "devise")
2 parents 29fb717 + 285a5f0 commit 27a491b

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

inertia_rails.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
3333
spec.add_development_dependency "rails-controller-testing"
3434
spec.add_development_dependency "sqlite3"
3535
spec.add_development_dependency "appraisal"
36+
spec.add_development_dependency "responders"
3637
end

lib/inertia_rails/controller.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ def inertia_share(**args, &block)
2020
end
2121
end
2222

23-
private
24-
25-
def inertia_location(url)
26-
headers['X-Inertia-Location'] = url
27-
head :conflict
28-
end
29-
3023
def redirect_to(options = {}, response_options = {})
3124
capture_inertia_errors(response_options)
3225
super(options, response_options)
@@ -41,6 +34,13 @@ def redirect_back(fallback_location:, allow_other_host: true, **options)
4134
)
4235
end
4336

37+
private
38+
39+
def inertia_location(url)
40+
headers['X-Inertia-Location'] = url
41+
head :conflict
42+
end
43+
4444
def capture_inertia_errors(options)
4545
if (inertia_errors = options.dig(:inertia, :errors))
4646
session[:inertia_errors] = inertia_errors
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'responders'
2+
3+
class Thing
4+
end
5+
6+
class InertiaRespondersTestController < ApplicationController
7+
self.responder = ActionController::Responder
8+
respond_to :html
9+
10+
def redirect_test
11+
respond_with Thing.new, location: '/foo'
12+
end
13+
end

spec/dummy/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
get 'redirect_test' => 'inertia_test#redirect_test'
1111
get 'inertia_request_test' => 'inertia_test#inertia_request_test'
1212
get 'inertia_partial_request_test' => 'inertia_test#inertia_partial_request_test'
13+
post 'redirect_with_responders' => 'inertia_responders_test#redirect_test'
1314
post 'redirect_test' => 'inertia_test#redirect_test'
1415
patch 'redirect_test' => 'inertia_test#redirect_test'
1516
put 'redirect_test' => 'inertia_test#redirect_test'

spec/inertia/request_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,11 @@
8989
it { is_expected.to eq 'application/xml' }
9090
end
9191
end
92+
93+
describe 'it tests redirecting with responders gem' do
94+
subject { response.status }
95+
before { post redirect_with_responders_path }
96+
97+
it { is_expected.to eq 302 }
98+
end
9299
end

0 commit comments

Comments
 (0)