summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/zero/response/cookie/add_crumb_spec.rb54
-rw-r--r--spec/unit/zero/response/cookie/get_crumb_spec.rb21
-rw-r--r--spec/unit/zero/response/cookie/to_header_spec.rb29
-rw-r--r--spec/unit/zero/response/to_a_spec.rb7
4 files changed, 111 insertions, 0 deletions
diff --git a/spec/unit/zero/response/cookie/add_crumb_spec.rb b/spec/unit/zero/response/cookie/add_crumb_spec.rb
new file mode 100644
index 0000000..3c8dbee
--- /dev/null
+++ b/spec/unit/zero/response/cookie/add_crumb_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe Zero::Response::Cookie, '#add_crumb' do
+ let(:cookie) { Zero::Response::Cookie.new }
+ subject { cookie.add_crumb(key, value, options) }
+ let(:options) { {} }
+ let(:key) { 'key' }
+ let(:value) { 'value' }
+
+ before :each do
+ subject
+ end
+
+ context 'with no argument' do
+ it 'adds a new crumb' do
+ expect(cookie.get_crumb(key).key).to be(key)
+ end
+ end
+
+ context 'with flags' do
+ let(:options) { {:flags => [:secure, :http_only]} }
+
+ it 'adds a crumb with secure header' do
+ expect(cookie.get_crumb(key).secure).to be(true)
+ end
+
+ it 'adds a crumb with http_only header' do
+ expect(cookie.get_crumb(key).http_only).to be(true)
+ end
+ end
+
+ context 'with expire' do
+ let(:time) { Time.now }
+ let(:options) { {:expire => time} }
+
+ it 'adds a crumb with expire header' do
+ expect(cookie.get_crumb(key).expire).to be(time)
+ end
+ end
+
+ context 'with domain and path' do
+ let(:domain) { 'libzero.org' }
+ let(:path) { '/admin' }
+ let(:options) { {:domain => domain, :path => path} }
+
+ it 'adds a crumb with domain header' do
+ expect(cookie.get_crumb(key).domain).to be(domain)
+ end
+
+ it 'adds a crumb with path header' do
+ expect(cookie.get_crumb(key).path).to be(path)
+ end
+ end
+end
diff --git a/spec/unit/zero/response/cookie/get_crumb_spec.rb b/spec/unit/zero/response/cookie/get_crumb_spec.rb
new file mode 100644
index 0000000..3c315db
--- /dev/null
+++ b/spec/unit/zero/response/cookie/get_crumb_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe Zero::Response::Cookie, '#add_crumb' do
+ let(:cookie) { Zero::Response::Cookie.new }
+ subject { cookie.add_crumb(key, value, options) }
+ let(:options) { {} }
+ let(:key) { 'key' }
+ let(:value) { 'value' }
+
+ before :each do
+ subject
+ end
+
+ it 'returns the crumb when the crumb exists' do
+ expect(cookie.get_crumb(key).key).to be(key)
+ end
+
+ it 'returns nil for the wrong key' do
+ expect(cookie.get_crumb('wrong key')).to be(nil)
+ end
+end
diff --git a/spec/unit/zero/response/cookie/to_header_spec.rb b/spec/unit/zero/response/cookie/to_header_spec.rb
new file mode 100644
index 0000000..7cdc278
--- /dev/null
+++ b/spec/unit/zero/response/cookie/to_header_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe Zero::Response::Cookie, '#add_crumb' do
+ let(:cookie) { Zero::Response::Cookie.new }
+ subject { cookie.add_crumb(key, value, options) }
+ let(:options) { {
+ :domain => domain,
+ :path => path,
+ :expire => time,
+ :flags => flags
+ } }
+ let(:key) { 'key' }
+ let(:value) { 'value' }
+ let(:time) { Time.new }
+ let(:domain) { 'libzero.org' }
+ let(:path) { '/admin' }
+ let(:flags) { [:secure, :http_only] }
+
+ before :each do
+ subject
+ end
+
+ it 'returns the header line' do
+ expect(cookie.to_header).to eq(
+ {'Set-Cookie' => "#{key}=#{value}; Expires=#{time.rfc2822};" +
+ " Path=#{path}; Domain=#{domain}; HttpOnly; Secure"}
+ )
+ end
+end
diff --git a/spec/unit/zero/response/to_a_spec.rb b/spec/unit/zero/response/to_a_spec.rb
index b016eb9..b547f98 100644
--- a/spec/unit/zero/response/to_a_spec.rb
+++ b/spec/unit/zero/response/to_a_spec.rb
@@ -69,5 +69,12 @@ describe Zero::Response do
value[1].should eq({}) # Headers
value[2].should eq([]) # Body
end
+
+ it "adds the cookie to the headers" do
+ key = 'key'
+ value = 'value'
+ subject.cookie.add_crumb(key, value)
+ expect(subject.to_a[1]['Set-Cookie']).to eq("#{key}=#{value}")
+ end
end
end