aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/test/cache/cache_entry_test.rb
blob: 80ff7ad564e21661ba75955a96781eaece2373d2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
                             
 













                                                                    
                            





                                                                                         
                                
                         







                                                                         



                                           
# frozen_string_literal: true

require "abstract_unit"
require "active_support/cache"

class CacheEntryTest < ActiveSupport::TestCase
  def test_expired
    entry = ActiveSupport::Cache::Entry.new("value")
    assert !entry.expired?, "entry not expired"
    entry = ActiveSupport::Cache::Entry.new("value", expires_in: 60)
    assert !entry.expired?, "entry not expired"
    Time.stub(:now, Time.now + 61) do
      assert entry.expired?, "entry is expired"
    end
  end

  def test_compressed_values
    value = "value" * 100
    entry = ActiveSupport::Cache::Entry.new(value, compress: true, compress_threshold: 1)
    assert_equal value, entry.value
    assert(value.bytesize > entry.size, "value is compressed")
  end

  def test_compressed_by_default
    value = "value" * 100
    entry = ActiveSupport::Cache::Entry.new(value, compress_threshold: 1)
    assert_equal value, entry.value
    assert(value.bytesize > entry.size, "value is compressed")
  end

  def test_uncompressed_values
    value = "value" * 100
    entry = ActiveSupport::Cache::Entry.new(value, compress: false)
    assert_equal value, entry.value
    assert_equal value.bytesize, entry.size
  end
end