mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Merge pull request #5286 from clockspring/fix-5285
Fix hanging tests for streaming controllers using Devise
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
23
test/rails_app/app/controllers/streaming_controller.rb
Normal file
23
test/rails_app/app/controllers/streaming_controller.rb
Normal 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
|
||||
@@ -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" }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user