Permalink
Browse files

Merge pull request #79 from pvdb/round_max_age_to_integer_value

Ensure duration_in_seconds - and hence max-age - has an integer value
  • Loading branch information...
2 parents 951760b + 46d85e4 commit 6ff3ca2b2d988911ca52a2712f6a7da5e064aa27 @manveru manveru committed Dec 26, 2013
Showing with 14 additions and 1 deletion.
  1. +1 −1 lib/rack/contrib/static_cache.rb
  2. +13 −0 test/spec_rack_static_cache.rb
@@ -87,7 +87,7 @@ def duration_in_words
end
def duration_in_seconds
- 60 * 60 * 24 * 365 * @cache_duration
+ (60 * 60 * 24 * 365 * @cache_duration).to_i
end
end
end
@@ -59,6 +59,14 @@ def call(env)
res.headers['Expires'].should =~ Regexp.new("#{next_next_year}")
end
+ it "should round max-age if duration is part of a year" do
+ one_week_duration_app_request
+ res = @request.get("/statics/test")
+ res.should.be.ok
+ res.body.should =~ /rubyrack/
+ res.headers['Cache-Control'].should == "max-age=606461, public"
+ end
+
it "should return 404s if requested with version number but versioning is disabled" do
configured_app_request
res = @request.get("/statics/test-0.0.1")
@@ -79,6 +87,11 @@ def default_app_request
request
end
+ def one_week_duration_app_request
+ @options = {:urls => ["/statics"], :root => @root, :duration => 1.fdiv(52)}
+ request
+ end
+
def configured_app_request
@options = {:urls => ["/statics", "/documents*"], :root => @root, :versioning => false, :duration => 2}
request

0 comments on commit 6ff3ca2

Please sign in to comment.