Merge pull request #5286 from clockspring/fix-5285

Fix hanging tests for streaming controllers using Devise
This commit is contained in:
Carlos Antonio da Silva
2020-08-27 08:52:17 -03:00
committed by GitHub
4 changed files with 36 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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" }

View File

@@ -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 "<html><body>You are being <a href=\"http://test.host/users/sign_in\">redirected</a>.</body></html>", response.body
end
end