Skip to content

Commit 0196c62

Browse files
Add test case to demonstrate Thread.current locals are cleared in the test environment
Co-authored-by: Ates Goral <[email protected]>
1 parent be9aa73 commit 0196c62

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

actionpack/test/controller/live_stream_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,30 @@ def test_response_buffer_do_not_respond_to_to_ary
658658
end
659659
end
660660

661+
class LiveControllerThreadTest < ActionController::TestCase
662+
class TestController < ActionController::Base
663+
include ActionController::Live
664+
665+
def greet
666+
response.headers["Content-Type"] = "text/event-stream"
667+
%w{ hello world }.each do |word|
668+
response.stream.write word
669+
end
670+
response.stream.close
671+
end
672+
end
673+
674+
tests TestController
675+
676+
def test_thread_locals_do_not_get_reset_in_test_environment
677+
Thread.current[:setting] = "aaron"
678+
679+
get :greet
680+
681+
assert_equal "aaron", Thread.current[:setting]
682+
end
683+
end
684+
661685
class BufferTest < ActionController::TestCase
662686
def test_nil_callback
663687
buf = ActionController::Live::Buffer.new nil

0 commit comments

Comments
 (0)