mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ControllerRuntime tests also use Rails::Subscriber::TestHelper.
This commit is contained in:
parent
b0d35ad00c
commit
01839834fd
2 changed files with 32 additions and 22 deletions
|
@ -1,38 +1,53 @@
|
|||
require 'active_record_unit'
|
||||
require 'active_record/railties/controller_runtime'
|
||||
require 'fixtures/project'
|
||||
require 'rails/subscriber/test_helper'
|
||||
require 'action_controller/railties/subscriber'
|
||||
|
||||
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
|
||||
|
||||
class ARLoggingController < ActionController::Base
|
||||
module ControllerRuntimeSubscriberTest
|
||||
class SubscriberController < ActionController::Base
|
||||
def show
|
||||
render :inline => "<%= Project.all %>"
|
||||
end
|
||||
end
|
||||
|
||||
class ARLoggingTest < ActionController::TestCase
|
||||
tests ARLoggingController
|
||||
|
||||
def setup
|
||||
super
|
||||
set_logger
|
||||
def self.included(base)
|
||||
base.tests SubscriberController
|
||||
end
|
||||
|
||||
def wait
|
||||
ActiveSupport::Notifications.notifier.wait
|
||||
def setup
|
||||
@old_logger = ActionController::Base.logger
|
||||
Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
Rails::Subscriber.subscribers.clear
|
||||
ActionController::Base.logger = @old_logger
|
||||
end
|
||||
|
||||
def set_logger(logger)
|
||||
ActionController::Base.logger = logger
|
||||
end
|
||||
|
||||
def test_log_with_active_record
|
||||
# Wait pending notifications to be published
|
||||
wait
|
||||
get :show
|
||||
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
|
||||
|
||||
private
|
||||
def set_logger
|
||||
@controller.logger = MockLogger.new
|
||||
class SyncSubscriberTest < ActionController::TestCase
|
||||
include Rails::Subscriber::SyncTestHelper
|
||||
include ControllerRuntimeSubscriberTest
|
||||
end
|
||||
|
||||
class AsyncSubscriberTest < ActionController::TestCase
|
||||
include Rails::Subscriber::AsyncTestHelper
|
||||
include ControllerRuntimeSubscriberTest
|
||||
end
|
||||
end
|
|
@ -41,11 +41,6 @@ module ActionControllerSubscriberTest
|
|||
base.tests Another::SubscribersController
|
||||
end
|
||||
|
||||
def wait
|
||||
sleep(0.01)
|
||||
super
|
||||
end
|
||||
|
||||
def setup
|
||||
@old_logger = ActionController::Base.logger
|
||||
|
||||
|
|
Loading…
Reference in a new issue