diff options
Diffstat (limited to 'activerecord/test/cases/subscriber_test.rb')
-rw-r--r-- | activerecord/test/cases/subscriber_test.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/activerecord/test/cases/subscriber_test.rb b/activerecord/test/cases/subscriber_test.rb new file mode 100644 index 0000000000..f569d64ee5 --- /dev/null +++ b/activerecord/test/cases/subscriber_test.rb @@ -0,0 +1,51 @@ +require "cases/helper" +require "models/developer" +require "rails/subscriber/test_helper" +require "active_record/railties/subscriber" + +module SubscriberTest + Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new) + + def super + @old_logger = ActiveRecord::Base.logger + super + end + + def teardown + super + ActiveRecord::Base.logger = @old_logger + end + + def set_logger(logger) + ActiveRecord::Base.logger = @logger + end + + def test_basic_query_logging + Developer.all + wait + assert_equal 1, @logger.logged(:debug).size + assert_match /Developer Load/, @logger.logged(:debug).last + assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last + end + + def test_cached_queries + ActiveRecord::Base.cache do + Developer.all + Developer.all + end + wait + assert_equal 2, @logger.logged(:debug).size + assert_match /CACHE/, @logger.logged(:debug).last + assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last + end + + class SyncSubscriberTest < ActiveSupport::TestCase + include Rails::Subscriber::SyncTestHelper + include SubscriberTest + end + + class AsyncSubscriberTest < ActiveSupport::TestCase + include Rails::Subscriber::AsyncTestHelper + include SubscriberTest + end +end
\ No newline at end of file |