Sha256: 1fa6639ef42f0f05c52f1656e7fe401b07c3ba451ea604a7374452d30fff5ec3

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

require "abstract_unit"
require "active_support/cache"

class CacheStoreLoggerTest < ActiveSupport::TestCase
  def setup
    @cache = ActiveSupport::Cache.lookup_store(:memory_store)

    @buffer = StringIO.new
    @cache.logger = ActiveSupport::Logger.new(@buffer)
  end

  def test_logging
    @cache.fetch("foo") { "bar" }
    assert @buffer.string.present?
  end

  def test_log_with_string_namespace
    @cache.fetch("foo", namespace: "string_namespace") { "bar" }
    assert_match %r{string_namespace:foo}, @buffer.string
  end

  def test_log_with_proc_namespace
    proc = Proc.new do
      "proc_namespace"
    end
    @cache.fetch("foo", namespace: proc) { "bar" }
    assert_match %r{proc_namespace:foo}, @buffer.string
  end

  def test_mute_logging
    @cache.mute { @cache.fetch("foo") { "bar" } }
    assert @buffer.string.blank?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-on-quails-0.1.0 activesupport/test/cache/cache_store_logger_test.rb