Sha256: 33d60f1df5dc735fb43e0edb6eb5b8b2187043f871e1b0168b5fa26fcd5d5ad9

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

require "test_helper"

class MtimeStrategyTest < Minitest::Test
  def setup
    @mtime_strategy = Webpacker::MtimeStrategy.new
    @manifest_timestamp = Time.parse("2021-01-01 12:34:56 UTC")
  end

  def with_stubs(latest_timestamp:, manifest_exists: true)
    @mtime_strategy.stub :latest_modified_timestamp, latest_timestamp do
      FileTest.stub :exist?, manifest_exists do
        File.stub :mtime, @manifest_timestamp do
          yield
        end
      end
    end
  end

  def test_freshness_when_manifest_missing
    latest_timestamp = @manifest_timestamp + 3600

    with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
      assert @mtime_strategy.stale?
    end
  end

  def test_freshness_when_manifest_older
    latest_timestamp = @manifest_timestamp + 3600

    with_stubs(latest_timestamp: latest_timestamp.to_i) do
      assert @mtime_strategy.stale?
    end
  end

  def test_freshness_when_manifest_newer
    latest_timestamp = @manifest_timestamp - 3600

    with_stubs(latest_timestamp: latest_timestamp.to_i) do
      assert @mtime_strategy.fresh?
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shakapacker-6.5.5 test/mtime_strategy_test.rb
shakapacker-6.5.4 test/mtime_strategy_test.rb
shakapacker-6.5.3 test/mtime_strategy_test.rb
shakapacker-6.5.2 test/mtime_strategy_test.rb
shakapacker-6.5.1 test/mtime_strategy_test.rb
shakapacker-6.5.0 test/mtime_strategy_test.rb
shakapacker-6.4.1 test/mtime_strategy_test.rb
shakapacker-6.4.0 test/mtime_strategy_test.rb
shakapacker-6.3.0 test/mtime_strategy_test.rb