Sha256: df9267fab2efc2ca5619a60d57c282b58bdfcbd3c5e021acf8933fa7b97471b3

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

require 'test_helper'

class QorCacheKeyTest < ActiveSupport::TestCase
  test "qor_cache_key with one key" do
    cache_key1 = qor_cache_key(:product)
    cache_key2 = qor_cache_key(:product)
    assert_equal cache_key1, cache_key2

    cache_key_pc1 = qor_cache_key(:product_and_color_variation)
    cache_key_pc2 = qor_cache_key(:product_and_color_variation)
    assert_equal cache_key_pc1, cache_key_pc2

    product = FactoryGirl.create(:product)

    cache_key3 = qor_cache_key(:product)
    assert_not_equal cache_key1, cache_key3

    cache_key_pc3 = qor_cache_key(:product_and_color_variation)
    assert_not_equal cache_key_pc1, cache_key_pc3

    product.destroy
    assert_not_equal cache_key3, qor_cache_key(:product)
    assert_not_equal cache_key_pc3, qor_cache_key(:product_and_color_variation)
  end

  test "qor_cache_key with many keys" do
    cache_key1 = qor_cache_key(:product, :color_variation)
    cache_key2 = qor_cache_key(:product, :color_variation)
    assert_equal cache_key1, cache_key2

    product = FactoryGirl.create(:product)

    cache_key3 = qor_cache_key(:product, :color_variation)
    assert_not_equal cache_key1, cache_key3
  end

  test "qor_cache_key with block" do
    def same_value
      "same_value"
    end
    same_1 = qor_cache_key(:product) do
      same_value
    end

    same_2 = qor_cache_key(:product) do
      same_value
    end

    assert_equal same_1, same_2

    def random_value
      rand()
    end
    random_1 = qor_cache_key(:product) do
      random_value
    end

    random_2 = qor_cache_key(:product) do
      random_value
    end

    assert_not_equal random_1, random_2
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
qor_cache-0.0.4 test/qor_cache_key_test.rb
qor_cache-0.0.3 test/qor_cache_key_test.rb
qor_cache-0.0.2 test/qor_cache_key_test.rb
qor_cache-0.0.1 test/qor_cache_key_test.rb