Merge pull request #49442 from p8/actionpack/notifications-tests

Add tests for send_file and redirect_to instrumentation
This commit is contained in:
Rafael Mendonça França 2023-10-01 17:30:00 -04:00 committed by GitHub
commit 7c303b9ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -601,6 +601,23 @@ class RedirectTest < ActionController::TestCase
end
end
def test_redirect_to_instrumentation
payload = nil
subscriber = proc do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
payload = event.payload
end
ActiveSupport::Notifications.subscribed(subscriber, "redirect_to.action_controller") do
get :simple_redirect
end
assert_equal request, payload[:request]
assert_equal 302, payload[:status]
assert_equal "http://test.host/redirect/hello_world", payload[:location]
end
private
def with_raise_on_open_redirects
old_raise_on_open_redirects = ActionController::Base.raise_on_open_redirects

View File

@ -207,6 +207,36 @@ class SendFileTest < ActionController::TestCase
assert_equal file_data, response.body
end
def test_send_file_instrumentation
payload = nil
subscriber = proc do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
payload = event.payload
end
ActiveSupport::Notifications.subscribed(subscriber, "send_file.action_controller") do
process("file")
end
assert_equal __FILE__, payload[:path]
end
def test_send_data_instrumentation
payload = nil
subscriber = proc do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
payload = event.payload
end
ActiveSupport::Notifications.subscribed(subscriber, "send_data.action_controller") do
process("data")
end
assert_equal({}, payload)
end
%w(file data).each do |method|
define_method "test_send_#{method}_status" do
@controller.options = { stream: false, status: 500 }