diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/notifications.rb | 32 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/railtie.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/railties/subscriber.rb | 17 | ||||
-rw-r--r-- | actionpack/test/activerecord/controller_runtime_test.rb | 19 | ||||
-rw-r--r-- | actionpack/test/controller/subscriber_test.rb | 18 | ||||
-rw-r--r-- | actionpack/test/dispatch/subscriber_test.rb | 111 | ||||
-rw-r--r-- | actionpack/test/template/subscriber_test.rb | 13 |
8 files changed, 9 insertions, 205 deletions
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index 42ff9ca2e4..f0490a5619 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -46,7 +46,6 @@ module ActionDispatch autoload :Cookies autoload :Flash autoload :Head - autoload :Notifications autoload :ParamsParser autoload :Rescue autoload :ShowExceptions diff --git a/actionpack/lib/action_dispatch/middleware/notifications.rb b/actionpack/lib/action_dispatch/middleware/notifications.rb deleted file mode 100644 index 65409f57fd..0000000000 --- a/actionpack/lib/action_dispatch/middleware/notifications.rb +++ /dev/null @@ -1,32 +0,0 @@ -module ActionDispatch - # Provide notifications in the middleware stack. Notice that for the before_dispatch - # and after_dispatch notifications, we just send the original env, so we don't pile - # up large env hashes in the queue. However, in exception cases, the whole env hash - # is actually useful, so we send it all. - class Notifications - def initialize(app) - @app = app - end - - def call(env) - request = Request.new(env) - payload = retrieve_payload_from_env(request.filtered_env) - - ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", payload) - - ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", payload) do - @app.call(env) - end - rescue Exception => exception - ActiveSupport::Notifications.instrument('action_dispatch.exception', - :env => env, :exception => exception) - raise exception - end - - protected - # Remove any rack related constants from the env, like rack.input. - def retrieve_payload_from_env(env) - Hash[:env => env.except(*env.keys.select { |k| k.to_s.index("rack.") == 0 })] - end - end -end diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index 18978bfb39..e4bd143e78 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -5,9 +5,6 @@ module ActionDispatch class Railtie < Rails::Railtie plugin_name :action_dispatch - require "action_dispatch/railties/subscriber" - subscriber ActionDispatch::Railties::Subscriber.new - # Prepare dispatcher callbacks and run 'prepare' callbacks initializer "action_dispatch.prepare_dispatcher" do |app| # TODO: This used to say unless defined?(Dispatcher). Find out why and fix. diff --git a/actionpack/lib/action_dispatch/railties/subscriber.rb b/actionpack/lib/action_dispatch/railties/subscriber.rb deleted file mode 100644 index cdb1162eac..0000000000 --- a/actionpack/lib/action_dispatch/railties/subscriber.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ActionDispatch - module Railties - class Subscriber < Rails::Subscriber - def before_dispatch(event) - request = Request.new(event.payload[:env]) - path = request.request_uri.inspect rescue "unknown" - - info "\n\nStarted #{request.method.to_s.upcase} #{path} " << - "for #{request.remote_ip} at #{event.time.to_s(:db)}" - end - - def logger - ActionController::Base.logger - end - end - end -end
\ No newline at end of file diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb index 37c7738301..ed8e324938 100644 --- a/actionpack/test/activerecord/controller_runtime_test.rb +++ b/actionpack/test/activerecord/controller_runtime_test.rb @@ -6,16 +6,15 @@ require 'action_controller/railties/subscriber' ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime -module ControllerRuntimeSubscriberTest +class ControllerRuntimeSubscriberTest < ActionController::TestCase class SubscriberController < ActionController::Base def show render :inline => "<%= Project.all %>" end end - - def self.included(base) - base.tests SubscriberController - end + + include Rails::Subscriber::TestHelper + tests SubscriberController def setup @old_logger = ActionController::Base.logger @@ -40,14 +39,4 @@ module ControllerRuntimeSubscriberTest assert_equal 2, @logger.logged(:info).size assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1] end - - class SyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::SyncTestHelper - include ControllerRuntimeSubscriberTest - end - - class AsyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::AsyncTestHelper - include ControllerRuntimeSubscriberTest - end end
\ No newline at end of file diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb index 52434426f7..bd0c83413c 100644 --- a/actionpack/test/controller/subscriber_test.rb +++ b/actionpack/test/controller/subscriber_test.rb @@ -35,11 +35,9 @@ module Another end end -module ActionControllerSubscriberTest - - def self.included(base) - base.tests Another::SubscribersController - end +class ACSubscriberTest < ActionController::TestCase + tests Another::SubscribersController + include Rails::Subscriber::TestHelper def setup @old_logger = ActionController::Base.logger @@ -174,14 +172,4 @@ module ActionControllerSubscriberTest def logs @logs ||= @logger.logged(:info) end - - class SyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::SyncTestHelper - include ActionControllerSubscriberTest - end - - class AsyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::AsyncTestHelper - include ActionControllerSubscriberTest - end end diff --git a/actionpack/test/dispatch/subscriber_test.rb b/actionpack/test/dispatch/subscriber_test.rb deleted file mode 100644 index 3096c132e7..0000000000 --- a/actionpack/test/dispatch/subscriber_test.rb +++ /dev/null @@ -1,111 +0,0 @@ -require "abstract_unit" -require "rails/subscriber/test_helper" -require "action_dispatch/railties/subscriber" - -module DispatcherSubscriberTest - Boomer = lambda do |env| - req = ActionDispatch::Request.new(env) - case req.path - when "/" - [200, {}, []] - else - raise "puke!" - end - end - - App = ActionDispatch::Notifications.new(Boomer) - - def setup - Rails::Subscriber.add(:action_dispatch, ActionDispatch::Railties::Subscriber.new) - @app = App - super - - @events = [] - ActiveSupport::Notifications.subscribe do |*args| - @events << args - end - end - - def set_logger(logger) - ActionController::Base.logger = logger - end - - def test_publishes_notifications - get "/" - wait - - assert_equal 2, @events.size - before, after = @events - - assert_equal 'action_dispatch.before_dispatch', before[0] - assert_kind_of Hash, before[4][:env] - assert_equal 'GET', before[4][:env]["REQUEST_METHOD"] - - assert_equal 'action_dispatch.after_dispatch', after[0] - assert_kind_of Hash, after[4][:env] - assert_equal 'GET', after[4][:env]["REQUEST_METHOD"] - end - - def test_publishes_notifications_even_on_failures - begin - get "/puke" - rescue - end - - wait - - assert_equal 3, @events.size - before, after, exception = @events - - assert_equal 'action_dispatch.before_dispatch', before[0] - assert_kind_of Hash, before[4][:env] - assert_equal 'GET', before[4][:env]["REQUEST_METHOD"] - - assert_equal 'action_dispatch.after_dispatch', after[0] - assert_kind_of Hash, after[4][:env] - assert_equal 'GET', after[4][:env]["REQUEST_METHOD"] - - assert_equal 'action_dispatch.exception', exception[0] - assert_kind_of Hash, exception[4][:env] - assert_equal 'GET', exception[4][:env]["REQUEST_METHOD"] - assert_kind_of RuntimeError, exception[4][:exception] - end - - def test_subscriber_logs_notifications - get "/" - wait - - log = @logger.logged(:info).first - assert_equal 1, @logger.logged(:info).size - - assert_match %r{^Started GET "/"}, log - assert_match %r{for 127\.0\.0\.1}, log - end - - def test_subscriber_has_its_logged_flushed_after_request - assert_equal 0, @logger.flush_count - get "/" - wait - assert_equal 1, @logger.flush_count - end - - def test_subscriber_has_its_logged_flushed_even_after_busted_requests - assert_equal 0, @logger.flush_count - begin - get "/puke" - rescue - end - wait - assert_equal 1, @logger.flush_count - end - - class SyncSubscriberTest < ActionController::IntegrationTest - include Rails::Subscriber::SyncTestHelper - include DispatcherSubscriberTest - end - - class AsyncSubscriberTest < ActionController::IntegrationTest - include Rails::Subscriber::AsyncTestHelper - include DispatcherSubscriberTest - end -end
\ No newline at end of file diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb index af0b3102cf..5db2b16ac1 100644 --- a/actionpack/test/template/subscriber_test.rb +++ b/actionpack/test/template/subscriber_test.rb @@ -3,7 +3,8 @@ require "rails/subscriber/test_helper" require "action_view/railties/subscriber" require "controller/fake_models" -module ActionViewSubscriberTest +class AVSubscriberTest < ActiveSupport::TestCase + include Rails::Subscriber::TestHelper def setup @old_logger = ActionController::Base.logger @@ -89,14 +90,4 @@ module ActionViewSubscriberTest assert_equal 1, @logger.logged(:info).size assert_match /Rendered collection/, @logger.logged(:info).last end - - class SyncSubscriberTest < ActiveSupport::TestCase - include Rails::Subscriber::SyncTestHelper - include ActionViewSubscriberTest - end - - class AsyncSubscriberTest < ActiveSupport::TestCase - include Rails::Subscriber::AsyncTestHelper - include ActionViewSubscriberTest - end end
\ No newline at end of file |