Skip to content

Commit

Permalink
add specs for global settings max age and asset serving response
Browse files Browse the repository at this point in the history
  • Loading branch information
kates committed May 23, 2024
1 parent b7506f1 commit 690649d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/marten/conf/global_settings/assets_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,19 @@ describe Marten::Conf::GlobalSettings::Assets do
assets_conf.url.should eq "/assets/url/"
end
end

describe "#max_age" do
it "returns the expected default value" do
assets_conf = Marten::Conf::GlobalSettings::Assets.new
assets_conf.max_age.should eq 3600
end
end

describe "#max_age=" do
it "allows to set max_age value" do
assets_conf = Marten::Conf::GlobalSettings::Assets.new
assets_conf.max_age = 7200
assets_conf.max_age.should eq 7200
end
end
end
25 changes: 24 additions & 1 deletion spec/marten/middleware/asset_serving_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe Marten::Middleware::AssetServing do
end
end

it "properly sets the Cache-Control header" do
it "properly sets the default Cache-Control header" do
middleware = Marten::Middleware::AssetServing.new

["BigApp.js", "css/BigApp.css"].each do |path|
Expand All @@ -280,5 +280,28 @@ describe Marten::Middleware::AssetServing do
response.headers[:"Cache-Control"].should eq "private, max-age=3600"
end
end
it "properly sets the custom Cache-Control header" do
Marten.settings.assets.max_age = 7200
middleware = Marten::Middleware::AssetServing.new

["BigApp.js", "css/BigApp.css"].each do |path|
response = middleware.call(
Marten::HTTP::Request.new(
::HTTP::Request.new(
method: "GET",
resource: "/assets/#{path}",
headers: HTTP::Headers{
"Host" => "example.com",
"Accept-Encoding" => "gzip, deflate, br",
}
)
),
->{ Marten::HTTP::Response.new("Unknown!", content_type: "text/plain", status: 200) }
)

uncompressed_content = File.read(File.join(__DIR__, "asset_serving/assets/#{path}"))
response.headers[:"Cache-Control"].should eq "private, max-age=7200"
end
end
end
end

0 comments on commit 690649d

Please sign in to comment.