Sha256: 3ae8e3461fe56ebecd698d9c25689d75d3ee400734b5bcd011f5d2e1914ce61e

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

require 'test_helper.rb'

class ActiveRecordProfilerTest < ActiveSupport::TestCase
  def setup
    @collector = ActiveRecordProfiler::Collector.instance
    @test_log = StringIO.new
    ActiveRecord::Base.logger = ActiveRecordProfiler::Logger.new(
        ActiveSupport::Logger.new(@test_log))
  end

  def test_caller_location_appears_in_log
    sql = 'SELECT 1 FROM widgets'
    ActiveRecord::Base.connection.select_value(sql)
    @test_log.rewind
    log_data = @test_log.read
    assert_match Regexp.new(Regexp.quote(sql)), log_data
  end

  def test_profiler_records_query_site
    assert @collector
    @collector.flush_query_sites_statistics
    assert @collector.query_sites.blank?
    sql = 'SELECT 1 FROM widgets'
    ActiveRecord::Base.connection.select_value(sql)
    @test_log.rewind
    assert @collector.query_sites.present?
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active-record-profiler-2.0.0 test/active_record_profiler_test.rb