diff --git a/lib/devise/test/controller_helpers.rb b/lib/devise/test/controller_helpers.rb index eeef694d..30b45b3a 100644 --- a/lib/devise/test/controller_helpers.rb +++ b/lib/devise/test/controller_helpers.rb @@ -143,7 +143,7 @@ module Devise @controller.response.headers.merge!(headers) @controller.response.content_type = headers["Content-Type"] unless Rails::VERSION::MAJOR >= 5 @controller.status = status - @controller.response.body = response.body + @controller.response_body = response.body nil # causes process return @response end diff --git a/test/rails_app/app/controllers/streaming_controller.rb b/test/rails_app/app/controllers/streaming_controller.rb new file mode 100644 index 00000000..6d3f0248 --- /dev/null +++ b/test/rails_app/app/controllers/streaming_controller.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class StreamingController < ApplicationController + include ActionController::Live + + before_action :authenticate_user! + + def index + render (Devise::Test.rails5_and_up? ? :body : :text) => 'Index' + end + + # Work around https://github.com/heartcombo/devise/issues/2332, which affects + # tests in Rails 4.x (and affects production in Rails >= 5) + def process(name) + super(name) + rescue ArgumentError => e + if e.message == 'uncaught throw :warden' + throw :warden + else + raise e + end + end +end diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index 8687dae2..0b748f3f 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -17,6 +17,8 @@ Rails.application.routes.draw do resources :admins, only: [:index] + resources :streaming, only: [:index] + # Users scope devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" } diff --git a/test/test/controller_helpers_test.rb b/test/test/controller_helpers_test.rb index f285cbbf..588ca791 100644 --- a/test/test/controller_helpers_test.rb +++ b/test/test/controller_helpers_test.rb @@ -196,3 +196,13 @@ class TestControllerHelpersTest < Devise::ControllerTestCase assert_equal old_warden_proxy, new_warden_proxy end end + +class TestControllerHelpersForStreamingControllerTest < Devise::ControllerTestCase + tests StreamingController + include Devise::Test::ControllerHelpers + + test "doesn't hang when sending an authentication error response body" do + get :index + assert_equal "
You are being redirected.", response.body + end +end