File: cookie_object_spec.rb

package info (click to toggle)
ruby-rack-test 0.7.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 296 kB
  • sloc: ruby: 1,900; makefile: 5
file content (66 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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