Sha256: 90257d1a23b3084e5897e67530b65f0fe5bb2aa7350524b7f2ec19b55f453ab1

Contents?: true

Size: 909 Bytes

Versions: 5

Compression:

Stored size: 909 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) + '.*' + Regexp.quote('active_record_profiler_test.rb')), 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

5 entries across 5 versions & 1 rubygems

Version Path
active-record-profiler-1.2.1 test/active_record_profiler_test.rb
active-record-profiler-1.2.0 test/active_record_profiler_test.rb
active-record-profiler-1.1.0 test/active_record_profiler_test.rb
active-record-profiler-1.0 test/active_record_profiler_test.rb
active-record-profiler-0.1 test/active_record_profiler_test.rb