Namespace
Methods
S
T
Included Modules
Instance Public methods
set_logger(logger)
# File activerecord/test/cases/log_subscriber_test.rb, line 41
def set_logger(logger)
  ActiveRecord::Base.logger = logger
end
setup()
# File activerecord/test/cases/log_subscriber_test.rb, line 25
def setup
  @old_logger = ActiveRecord::Base.logger
  @using_identity_map = ActiveRecord::IdentityMap.enabled?
  ActiveRecord::IdentityMap.enabled = false
  Developer.primary_key
  super
  ActiveRecord::LogSubscriber.attach_to(:active_record)
end
teardown()
# File activerecord/test/cases/log_subscriber_test.rb, line 34
def teardown
  super
  ActiveRecord::LogSubscriber.log_subscribers.pop
  ActiveRecord::Base.logger = @old_logger
  ActiveRecord::IdentityMap.enabled = @using_identity_map
end
test_basic_query_doesnt_log_when_level_is_not_debug()
# File activerecord/test/cases/log_subscriber_test.rb, line 96
def test_basic_query_doesnt_log_when_level_is_not_debug
  @logger.level = INFO
  Developer.all
  wait
  assert_equal 0, @logger.logged(:debug).size
end
test_basic_query_logging()
# File activerecord/test/cases/log_subscriber_test.rb, line 69
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.?/i, @logger.logged(:debug).last)
end
test_cached_queries()
# File activerecord/test/cases/log_subscriber_test.rb, line 85
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.?/i, @logger.logged(:debug).last)
end
test_cached_queries_doesnt_log_when_level_is_not_debug()
# File activerecord/test/cases/log_subscriber_test.rb, line 103
def test_cached_queries_doesnt_log_when_level_is_not_debug
  @logger.level = INFO
  ActiveRecord::Base.cache do
    Developer.all
    Developer.all
  end
  wait
  assert_equal 0, @logger.logged(:debug).size
end
test_exists_query_logging()
# File activerecord/test/cases/log_subscriber_test.rb, line 77
def test_exists_query_logging
  Developer.exists? 1
  wait
  assert_equal 1, @logger.logged(:debug).size
  assert_match(/Developer Exists/, @logger.logged(:debug).last)
  assert_match(/SELECT .*?FROM .?developers.?/i, @logger.logged(:debug).last)
end
test_ignore_binds_payload_with_nil_column()
# File activerecord/test/cases/log_subscriber_test.rb, line 61
def test_ignore_binds_payload_with_nil_column
  event = Struct.new(:duration, :payload)

  logger = TestDebugLogSubscriber.new
  logger.sql(event.new(0, :sql => 'hi mom!', :binds => [[nil, 1]]))
  assert_equal 1, logger.debugs.length
end
test_initializes_runtime()
# File activerecord/test/cases/log_subscriber_test.rb, line 113
def test_initializes_runtime
  Thread.new { assert_equal 0, ActiveRecord::LogSubscriber.runtime }.join
end
test_log()
# File activerecord/test/cases/log_subscriber_test.rb, line 117
def test_log
  ActiveRecord::IdentityMap.use do
    Post.find 1
    Post.find 1
  end
  wait
  assert_match(/From Identity Map/, @logger.logged(:debug).last)
end
test_request_notification()
# File activeresource/test/cases/log_subscriber_test.rb, line 25
def test_request_notification
  Person.find(1)
  wait
  assert_equal 2, @logger.logged(:info).size
  assert_equal "GET http://37s.sunrise.i:3000/people/1.json", @logger.logged(:info)[0]
  assert_match(/\-\-\> 200 200 33/, @logger.logged(:info)[1])
end
test_schema_statements_are_ignored()
# File activerecord/test/cases/log_subscriber_test.rb, line 45
def test_schema_statements_are_ignored
  event = Struct.new(:duration, :payload)

  logger = TestDebugLogSubscriber.new
  assert_equal 0, logger.debugs.length

  logger.sql(event.new(0, { :sql => 'hi mom!' }))
  assert_equal 1, logger.debugs.length

  logger.sql(event.new(0, { :sql => 'hi mom!', :name => 'foo' }))
  assert_equal 2, logger.debugs.length

  logger.sql(event.new(0, { :sql => 'hi mom!', :name => 'SCHEMA' }))
  assert_equal 2, logger.debugs.length
end