Skip to content

Commit

Permalink
Use config.asset_host
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha committed Oct 31, 2023
1 parent 48a03bc commit 968da1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/shakapacker/digest_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def record_compilation_digest

def compilation_digest_path
path = "last-compilation-digest-#{Shakapacker.env}"
if Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"].present?
host_hash = Digest::SHA1.hexdigest(Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"])
if Shakapacker.config.asset_host.present?
host_hash = Digest::SHA1.hexdigest(Shakapacker.config.asset_host)
path += "-#{host_hash}"
end

Expand Down
42 changes: 22 additions & 20 deletions spec/shakapacker/digest_strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,33 @@ def remove_compilation_digest_path
end

it "is stale when host changes" do
old_host = Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"]

Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"] = "the-host"

@digest_strategy.after_compile_hook

Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"] = "new-host"

expect(@digest_strategy.stale?).to be true
expect(@digest_strategy.fresh?).to be_falsey

Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"] = old_host
with_env_variable("SHAKAPACKER_ASSET_HOST" => "old-host") do
# Record the digests for old-host
@digest_strategy.after_compile_hook

with_env_variable("SHAKAPACKER_ASSET_HOST" => "new-host") do
expect(@digest_strategy.stale?).to be true
expect(@digest_strategy.fresh?).to be_falsey
end
end
end

it "generates correct compilation_digest_path" do
old_host = Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"]

Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"] = "custom-path"
with_env_variable("SHAKAPACKER_ASSET_HOST" => "custom-path") do
actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
host_hash = Digest::SHA1.hexdigest("custom-path")
expected_path = "last-compilation-digest-#{Shakapacker.env}-#{host_hash}"

actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
host_hash = Digest::SHA1.hexdigest("custom-path")
expected_path = "last-compilation-digest-#{Shakapacker.env}-#{host_hash}"
expect(actual_path).to eq expected_path
end
end

expect(actual_path).to eq expected_path
it "generates correct compilation_digest_path without the digest of the asset host if asset host is not set" do
with_env_variable("SHAKAPACKER_ASSET_HOST" => nil) do
actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
expected_path = "last-compilation-digest-#{Shakapacker.env}"

Shakapacker::Compiler.env["SHAKAPACKER_ASSET_HOST"] = old_host
expect(actual_path).to eq expected_path
end
end
end

0 comments on commit 968da1f

Please sign in to comment.