Sha256: 89c4fbbe40f308bb4c004bfbbd8a7e701c2c1ee5b5783ce3bec344d10acb5272

Contents?: true

Size: 1.08 KB

Versions: 28

Compression:

Stored size: 1.08 KB

Contents

require 'test_helper'

module Workarea
  class KeepProductIndexFreshTest < TestCase
    include SearchIndexing

    setup :set_config
    teardown :unset_config

    def set_config
      @current = Workarea.config.stale_products_size
      Workarea.config.stale_products_size = 1
    end

    def unset_config
      Workarea.config.stale_products_size = @current
    end

    def test_indexes_never_indexed_products
      assert_equal(0, Search::Storefront.count)

      3.times { create_product }
      KeepProductIndexFresh.new.perform

      assert_equal(1, Search::Storefront.count)
    end

    def test_indexes_stale_products
      product_1 = create_product
      product_2 = create_product
      product_3 = create_product

      IndexProduct.perform(product_1)
      IndexProduct.perform(product_2)
      IndexProduct.perform(product_3)

      current_last_indexed_at = product_1.reload.last_indexed_at

      travel_to(Time.current + 1.second)
      KeepProductIndexFresh.new.perform

      product_1.reload
      assert(product_1.last_indexed_at > current_last_indexed_at)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.26 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.25 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.23 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.22 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.21 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.20 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.19 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.18 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.17 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.16 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.15 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.14 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.13 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.12 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.11 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.10 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.9 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.8 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.5.7 test/workers/workarea/keep_product_index_fresh_test.rb