-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements [PR 133](https://github.com/brynary/rack-test/pull/133/files)
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "spec_helper" | ||
|
||
describe Rack::Test::CookieJar do | ||
subject(:jar) { Rack::Test::CookieJar.new } | ||
|
||
describe "#get_cookie" do | ||
context "with a populated jar" do | ||
let(:cookie_value) { "foo;abc" } | ||
let(:cookie_name) { "a_cookie_name" } | ||
|
||
before do | ||
jar[cookie_name] = cookie_value | ||
end | ||
|
||
it "returns full cookie objects" do | ||
cookie = jar.get_cookie(cookie_name) | ||
expect(cookie).to be_a(Rack::Test::Cookie) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require "spec_helper" | ||
|
||
describe Rack::Test::Cookie do | ||
subject(:cookie) { Rack::Test::Cookie.new(cookie_string) } | ||
|
||
let(:cookie_string) { raw_cookie_string } | ||
|
||
let(:raw_cookie_string) { | ||
[ | ||
"cookie_name=" + CGI.escape(value), | ||
"domain=" + domain, | ||
"path=" + path, | ||
"expires=" + expires, | ||
].join("; ") | ||
} | ||
|
||
let(:http_only_raw_cookie_string) { | ||
raw_cookie_string + "; HttpOnly" | ||
} | ||
|
||
let(:http_only_secure_raw_cookie_string) { | ||
http_only_raw_cookie_string + "; secure" | ||
} | ||
|
||
let(:value) { "the cookie value" } | ||
let(:domain) { "www.example.org" } | ||
let(:path) { "/" } | ||
let(:expires) { "Mon, 10 Aug 2015 14:40:57 0100" } | ||
|
||
describe "#to_h" do | ||
let(:cookie_string) { http_only_secure_raw_cookie_string } | ||
|
||
it "returns the cookie value and all options" do | ||
expect(cookie.to_h).to eq( | ||
"value" => value, | ||
"domain" => domain, | ||
"path" => path, | ||
"expires" => expires, | ||
"HttpOnly" => true, | ||
"secure" => true, | ||
) | ||
end | ||
end | ||
|
||
describe "#to_hash" do | ||
it "is an alias for #to_h" do | ||
expect(cookie.to_hash).to eq(cookie.to_h) | ||
end | ||
end | ||
|
||
describe "#http_only?" do | ||
context "for a non HTTP only cookie" do | ||
it "returns false" do | ||
expect(cookie.http_only?).to be(false) | ||
end | ||
end | ||
|
||
context "for a HTTP only cookie" do | ||
let(:cookie_string) { http_only_raw_cookie_string } | ||
|
||
it "returns true" do | ||
expect(cookie.http_only?).to be(true) | ||
end | ||
end | ||
end | ||
end |