mirror of https://github.com/rails/rails
Merge pull request #49442 from p8/actionpack/notifications-tests
Add tests for send_file and redirect_to instrumentation
This commit is contained in:
commit
7c303b9ddf
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in New Issue