Sha256: 5120262d2bab50440fdedc8bac807151bb99f5706e1f294db05532146504f428

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

require 'cases/helper'
require 'models/post'
require 'active_record/relation/record_fetch_warning'

module ActiveRecord
  class RecordFetchWarningTest < ActiveRecord::TestCase
    fixtures :posts

    def setup
      @original_logger = ActiveRecord::Base.logger
      @original_warn_on_records_fetched_greater_than = ActiveRecord::Base.warn_on_records_fetched_greater_than
      @log = StringIO.new
    end

    def teardown
      ActiveRecord::Base.logger = @original_logger
      ActiveRecord::Base.warn_on_records_fetched_greater_than = @original_warn_on_records_fetched_greater_than
    end

    def test_warn_on_records_fetched_greater_than_allowed_limit
      ActiveRecord::Base.logger = ActiveSupport::Logger.new(@log)
      ActiveRecord::Base.logger.level = Logger::WARN
      ActiveRecord::Base.warn_on_records_fetched_greater_than = 1

      Post.all.to_a

      assert_match(/Query fetched/, @log.string)
    end

    def test_does_not_warn_on_records_fetched_less_than_allowed_limit
      ActiveRecord::Base.logger = ActiveSupport::Logger.new(@log)
      ActiveRecord::Base.logger.level = Logger::WARN
      ActiveRecord::Base.warn_on_records_fetched_greater_than = 100

      Post.all.to_a

      assert_no_match(/Query fetched/, @log.string)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ibm_db-5.2.0-x86-mingw32 test/cases/relation/record_fetch_warning_test.rb
ibm_db-5.1.0-x86-mingw32 test/cases/relation/record_fetch_warning_test.rb
ibm_db-5.0.5-x86-mingw32 test/cases/relation/record_fetch_warning_test.rb
ibm_db-5.0.4-x86-mingw32 test/cases/relation/record_fetch_warning_test.rb
ibm_db-5.0.3-x86-mingw32 test/cases/relation/record_fetch_warning_test.rb
ibm_db-5.0.2-x86-mingw32 test/cases/relation/record_fetch_warning_test.rb