Skip to content

Commit

Permalink
fix typo, change to making cleaner comparisons in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
bmmcginty committed Oct 9, 2017
1 parent 50bb1cb commit d147d5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions spec/std/http/cookie_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module HTTP
describe "expiration_time" do
it "sets expiration_time to be current when max-age=0" do
cookie = parse_set_cookie("bla=1; max-age=0")
(Time.now - cookie.expiration_time.not_nil! <= 1.seconds).should be_true
(Time.now - cookie.expiration_time.not_nil!).should be.<= 1.seconds
end

it "sets expiration_time with old date" do
Expand All @@ -166,14 +166,14 @@ module HTTP

it "sets future expiration_time with max-age" do
cookie = parse_set_cookie("bla=1; max-age=1")
(cookie.expiration_time.not_nil! > Time.now).should be_true
(cookie.expiration_time.not_nil!).should be.> Time.now
end

it "sets future expiration_time with max-age and future cookie creation time" do
cookie = parse_set_cookie("bla=1; max-age=1")
cookie_expiration = cookie.expiration_time(time_reference: Time.now + 20.seconds).not_nil!
(Time.now + 20.seconds < cookie_expiration).should be_true
(Time.now + 21.seconds >= cookie_expiration).should be_true
(Time.now + 20.seconds).should be.< cookie_expiration
(Time.now + 21.seconds).should be.>= cookie_expiration
end

it "sets future expiration_time with expires" do
Expand Down Expand Up @@ -211,8 +211,8 @@ module HTTP
it "sets past expiration_time with max-age and future time reference" do
cookie = parse_set_cookie("bla=1; max-age=1")
cookie_expiration = cookie.expiration_time(time_reference: Time.now - 20.seconds).not_nil!
(Time.now - cookie_expiration < 20.seconds).should be_true
(Time.now - cookie_expiration > 18.seconds).should be_true
(Time.now - 20.seconds).should be.< cookie_expiration
(Time.now - 18.seconds).should be.> cookie_expiration
cookie_expired = cookie.expired?(time_reference: Time.now - 20.seconds)
cookie_expired.should be_true
end
Expand Down
2 changes: 1 addition & 1 deletion src/http/cookie.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module HTTP
# Returns the `Time` at which this cookie will expire, or `nil` if it will not expire.
# Uses *max-age* and *expires* values to calculate the time.
# By default, this function uses the creation time of this cookie as the offset for max-age, if max-age is set.
# To use a different offset, provide a `Time` object to *time_Reference*.
# To use a different offset, provide a `Time` object to *time_reference*.
def expiration_time(time_reference = @creation_time)
if max_age = @max_age
time_reference + max_age
Expand Down

0 comments on commit d147d5d

Please sign in to comment.