Permalink
Browse files

Ensure duration_in_seconds has an integer value

  • Loading branch information...
1 parent 951760b commit 46d85e40f31e47aea6f48a1f3455d5b90d0a0c49 @pvdb pvdb committed Nov 2, 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 46d85e4

Please sign in to comment.