Sha256: 38ebe55986bda52b04456e94b9659c0ff40ccdf04bf2c271834ea1abb6d96bd2

Contents?: true

Size: 1.95 KB

Versions: 6

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

describe 'products', type: :feature, caching: true do
  let!(:product) { create(:product) }
  let!(:product2) { create(:product) }
  let!(:taxonomy) { create(:taxonomy) }
  let!(:taxon) { create(:taxon, taxonomy: taxonomy) }

  before do
    product2.update_column(:updated_at, 1.day.ago)
    # warm up the cache
    visit spree.root_path
    assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
    assert_written_to_cache("views/en/USD/spree/products/#{product.id}-#{product.updated_at.utc.to_s(:number)}")
    assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")

    clear_cache_events
  end

  it "reads from cache upon a second viewing" do
    visit spree.root_path
    expect(cache_writes.count).to eq(0)
  end

  it "busts the cache when a product is updated" do
    product.update_column(:updated_at, 1.day.from_now)
    visit spree.root_path
    assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
    assert_written_to_cache("views/en/USD/spree/products/#{product.id}-#{product.updated_at.utc.to_s(:number)}")
    expect(cache_writes.count).to eq(2)
  end

  it "busts the cache when all products are soft-deleted" do
    product.discard
    product2.discard
    visit spree.root_path
    assert_written_to_cache("views/en/USD/spree/products/all--#{Date.today.to_s(:number)}-0")
    expect(cache_writes.count).to eq(1)
  end

  it "busts the cache when the newest product is soft-deleted" do
    product.discard
    visit spree.root_path
    assert_written_to_cache("views/en/USD/spree/products/all--#{product2.updated_at.utc.to_s(:number)}")
    expect(cache_writes.count).to eq(1)
  end

  it "busts the cache when an older product is soft-deleted" do
    product2.discard
    visit spree.root_path
    assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
    expect(cache_writes.count).to eq(1)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solidus_frontend-2.5.2 spec/features/caching/products_spec.rb
solidus_frontend-2.5.1 spec/features/caching/products_spec.rb
solidus_frontend-2.5.0 spec/features/caching/products_spec.rb
solidus_frontend-2.5.0.rc1 spec/features/caching/products_spec.rb
solidus_frontend-2.5.0.beta2 spec/features/caching/products_spec.rb
solidus_frontend-2.5.0.beta1 spec/features/caching/products_spec.rb