提交 01839834 编写于 作者: J José Valim

ControllerRuntime tests also use Rails::Subscriber::TestHelper.

上级 b0d35ad0
require 'active_record_unit' require 'active_record_unit'
require 'active_record/railties/controller_runtime' require 'active_record/railties/controller_runtime'
require 'fixtures/project' require 'fixtures/project'
require 'rails/subscriber/test_helper'
require 'action_controller/railties/subscriber'
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
class ARLoggingController < ActionController::Base module ControllerRuntimeSubscriberTest
def show class SubscriberController < ActionController::Base
render :inline => "<%= Project.all %>" def show
render :inline => "<%= Project.all %>"
end
end end
end
class ARLoggingTest < ActionController::TestCase def self.included(base)
tests ARLoggingController base.tests SubscriberController
end
def setup def setup
@old_logger = ActionController::Base.logger
Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
super super
set_logger
end end
def wait def teardown
ActiveSupport::Notifications.notifier.wait super
Rails::Subscriber.subscribers.clear
ActionController::Base.logger = @old_logger
end end
def set_logger(logger)
ActionController::Base.logger = logger
end
def test_log_with_active_record def test_log_with_active_record
# Wait pending notifications to be published
wait
get :show get :show
wait wait
assert_match /ActiveRecord runtime/, @controller.logger.logged[3]
assert_equal 4, @logger.logged(:info).size
assert_match /ActiveRecord runtime/, @logger.logged(:info)[2]
end end
private class SyncSubscriberTest < ActionController::TestCase
def set_logger include Rails::Subscriber::SyncTestHelper
@controller.logger = MockLogger.new include ControllerRuntimeSubscriberTest
end end
end class AsyncSubscriberTest < ActionController::TestCase
include Rails::Subscriber::AsyncTestHelper
include ControllerRuntimeSubscriberTest
end
end
\ No newline at end of file
...@@ -41,11 +41,6 @@ def self.included(base) ...@@ -41,11 +41,6 @@ def self.included(base)
base.tests Another::SubscribersController base.tests Another::SubscribersController
end end
def wait
sleep(0.01)
super
end
def setup def setup
@old_logger = ActionController::Base.logger @old_logger = ActionController::Base.logger
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册