sinatra-contrib 2.0.0.rc1 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +2 -1
- data/lib/sinatra/decompile.rb +5 -0
- data/lib/sinatra/runner.rb +155 -0
- data/lib/sinatra/webdav.rb +93 -0
- data/sinatra-contrib.gemspec +5 -199
- metadata +13 -175
- data/spec/capture_spec.rb +0 -100
- data/spec/config_file/key_value.yml +0 -7
- data/spec/config_file/key_value.yml.erb +0 -6
- data/spec/config_file/key_value_override.yml +0 -2
- data/spec/config_file/missing_env.yml +0 -4
- data/spec/config_file/with_envs.yml +0 -7
- data/spec/config_file/with_nested_envs.yml +0 -11
- data/spec/config_file_spec.rb +0 -76
- data/spec/content_for/different_key.erb +0 -1
- data/spec/content_for/different_key.erubis +0 -1
- data/spec/content_for/different_key.haml +0 -2
- data/spec/content_for/different_key.slim +0 -2
- data/spec/content_for/footer.erb +0 -3
- data/spec/content_for/footer.erubis +0 -3
- data/spec/content_for/footer.haml +0 -2
- data/spec/content_for/footer.slim +0 -2
- data/spec/content_for/layout.erb +0 -1
- data/spec/content_for/layout.erubis +0 -1
- data/spec/content_for/layout.haml +0 -1
- data/spec/content_for/layout.slim +0 -1
- data/spec/content_for/multiple_blocks.erb +0 -4
- data/spec/content_for/multiple_blocks.erubis +0 -4
- data/spec/content_for/multiple_blocks.haml +0 -8
- data/spec/content_for/multiple_blocks.slim +0 -8
- data/spec/content_for/multiple_yields.erb +0 -3
- data/spec/content_for/multiple_yields.erubis +0 -3
- data/spec/content_for/multiple_yields.haml +0 -3
- data/spec/content_for/multiple_yields.slim +0 -3
- data/spec/content_for/passes_values.erb +0 -1
- data/spec/content_for/passes_values.erubis +0 -1
- data/spec/content_for/passes_values.haml +0 -1
- data/spec/content_for/passes_values.slim +0 -1
- data/spec/content_for/same_key.erb +0 -1
- data/spec/content_for/same_key.erubis +0 -1
- data/spec/content_for/same_key.haml +0 -2
- data/spec/content_for/same_key.slim +0 -2
- data/spec/content_for/takes_values.erb +0 -1
- data/spec/content_for/takes_values.erubis +0 -1
- data/spec/content_for/takes_values.haml +0 -3
- data/spec/content_for/takes_values.slim +0 -3
- data/spec/content_for_spec.rb +0 -241
- data/spec/cookies_spec.rb +0 -826
- data/spec/custom_logger_spec.rb +0 -43
- data/spec/extension_spec.rb +0 -32
- data/spec/json_spec.rb +0 -115
- data/spec/link_header_spec.rb +0 -99
- data/spec/multi_route_spec.rb +0 -59
- data/spec/namespace/foo.erb +0 -1
- data/spec/namespace/nested/foo.erb +0 -1
- data/spec/namespace_spec.rb +0 -791
- data/spec/okjson.rb +0 -581
- data/spec/reloader/app.rb.erb +0 -40
- data/spec/reloader_spec.rb +0 -465
- data/spec/required_params_spec.rb +0 -68
- data/spec/respond_with/bar.erb +0 -1
- data/spec/respond_with/bar.json.erb +0 -1
- data/spec/respond_with/baz.yajl +0 -1
- data/spec/respond_with/foo.html.erb +0 -1
- data/spec/respond_with/not_html.sass +0 -2
- data/spec/respond_with_spec.rb +0 -317
- data/spec/spec_helper.rb +0 -7
- data/spec/streaming_spec.rb +0 -415
@@ -1 +0,0 @@
|
|
1
|
-
<% content_for :bar do %>bar<% end %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<% content_for :bar do %>bar<% end %>
|
data/spec/content_for/footer.erb
DELETED
data/spec/content_for/layout.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<%= yield_content :foo %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= yield_content :foo %>
|
@@ -1 +0,0 @@
|
|
1
|
-
= yield_content :foo
|
@@ -1 +0,0 @@
|
|
1
|
-
= yield_content :foo
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= yield_content :foo, 1, 2 %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= yield_content :foo, 1, 2 %>
|
@@ -1 +0,0 @@
|
|
1
|
-
= yield_content :foo, 1, 2
|
@@ -1 +0,0 @@
|
|
1
|
-
== yield_content :foo, 1, 2
|
@@ -1 +0,0 @@
|
|
1
|
-
<% content_for :foo do %>foo<% end %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<% content_for :foo do %>foo<% end %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<% content_for :foo do |a, b| %><i><%= a %></i> <%= b %><% end %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<% content_for :foo do |a, b| %><i><%= a %></i> <%= b %><% end %>
|
data/spec/content_for_spec.rb
DELETED
@@ -1,241 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Sinatra::ContentFor do
|
4
|
-
subject do
|
5
|
-
Sinatra.new do
|
6
|
-
helpers Sinatra::ContentFor
|
7
|
-
set :views, File.expand_path("../content_for", __FILE__)
|
8
|
-
end.new!
|
9
|
-
end
|
10
|
-
|
11
|
-
Tilt.prefer Tilt::ERBTemplate
|
12
|
-
|
13
|
-
extend Forwardable
|
14
|
-
def_delegators :subject, :content_for, :clear_content_for, :yield_content
|
15
|
-
def render(engine, template)
|
16
|
-
subject.send(:render, engine, template, :layout => false).gsub(/\s/, '')
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "without templates" do
|
20
|
-
it 'renders blocks declared with the same key you use when rendering' do
|
21
|
-
content_for(:foo) { "foo" }
|
22
|
-
expect(yield_content(:foo)).to eq("foo")
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'renders blocks more than once' do
|
26
|
-
content_for(:foo) { "foo" }
|
27
|
-
3.times { expect(yield_content(:foo)).to eq("foo") }
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'does not render a block with a different key' do
|
31
|
-
content_for(:bar) { "bar" }
|
32
|
-
expect(yield_content(:foo)).to be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'renders default content if no block matches the key and a default block is specified' do
|
36
|
-
content_for(:bar) { "bar" }
|
37
|
-
expect(yield_content(:foo) { "foo" }).to eq("foo")
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'renders multiple blocks with the same key' do
|
41
|
-
content_for(:foo) { "foo" }
|
42
|
-
content_for(:foo) { "bar" }
|
43
|
-
content_for(:bar) { "WON'T RENDER ME" }
|
44
|
-
content_for(:foo) { "baz" }
|
45
|
-
expect(yield_content(:foo)).to eq("foobarbaz")
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'renders multiple blocks more than once' do
|
49
|
-
content_for(:foo) { "foo" }
|
50
|
-
content_for(:foo) { "bar" }
|
51
|
-
content_for(:bar) { "WON'T RENDER ME" }
|
52
|
-
content_for(:foo) { "baz" }
|
53
|
-
3.times { expect(yield_content(:foo)).to eq("foobarbaz") }
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'passes values to the blocks' do
|
57
|
-
content_for(:foo) { |a| a.upcase }
|
58
|
-
expect(yield_content(:foo, 'a')).to eq("A")
|
59
|
-
expect(yield_content(:foo, 'b')).to eq("B")
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'clears named blocks with the specified key' do
|
63
|
-
content_for(:foo) { "foo" }
|
64
|
-
expect(yield_content(:foo)).to eq("foo")
|
65
|
-
clear_content_for(:foo)
|
66
|
-
expect(yield_content(:foo)).to be_empty
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'takes an immediate value instead of a block' do
|
70
|
-
content_for(:foo, "foo")
|
71
|
-
expect(yield_content(:foo)).to eq("foo")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# TODO: liquid radius markaby builder nokogiri
|
76
|
-
engines = %w[erb erubis haml slim]
|
77
|
-
|
78
|
-
engines.each do |inner|
|
79
|
-
describe inner.capitalize do
|
80
|
-
before :all do
|
81
|
-
begin
|
82
|
-
require inner
|
83
|
-
rescue LoadError => e
|
84
|
-
skip "Skipping: " << e.message
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "with yield_content in Ruby" do
|
89
|
-
it 'renders blocks declared with the same key you use when rendering' do
|
90
|
-
render inner, :same_key
|
91
|
-
expect(yield_content(:foo).strip).to eq("foo")
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'renders blocks more than once' do
|
95
|
-
render inner, :same_key
|
96
|
-
3.times { expect(yield_content(:foo).strip).to eq("foo") }
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'does not render a block with a different key' do
|
100
|
-
render inner, :different_key
|
101
|
-
expect(yield_content(:foo)).to be_empty
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'renders default content if no block matches the key and a default block is specified' do
|
105
|
-
render inner, :different_key
|
106
|
-
expect(yield_content(:foo) { "foo" }).to eq("foo")
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'renders multiple blocks with the same key' do
|
110
|
-
render inner, :multiple_blocks
|
111
|
-
expect(yield_content(:foo).gsub(/\s/, '')).to eq("foobarbaz")
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'renders multiple blocks more than once' do
|
115
|
-
render inner, :multiple_blocks
|
116
|
-
3.times { expect(yield_content(:foo).gsub(/\s/, '')).to eq("foobarbaz") }
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'passes values to the blocks' do
|
120
|
-
render inner, :takes_values
|
121
|
-
expect(yield_content(:foo, 1, 2).gsub(/\s/, '')).to eq("<i>1</i>2")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "with content_for in Ruby" do
|
126
|
-
it 'renders blocks declared with the same key you use when rendering' do
|
127
|
-
content_for(:foo) { "foo" }
|
128
|
-
expect(render(inner, :layout)).to eq("foo")
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'renders blocks more than once' do
|
132
|
-
content_for(:foo) { "foo" }
|
133
|
-
expect(render(inner, :multiple_yields)).to eq("foofoofoo")
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'does not render a block with a different key' do
|
137
|
-
content_for(:bar) { "foo" }
|
138
|
-
expect(render(inner, :layout)).to be_empty
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'renders multiple blocks with the same key' do
|
142
|
-
content_for(:foo) { "foo" }
|
143
|
-
content_for(:foo) { "bar" }
|
144
|
-
content_for(:bar) { "WON'T RENDER ME" }
|
145
|
-
content_for(:foo) { "baz" }
|
146
|
-
expect(render(inner, :layout)).to eq("foobarbaz")
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'renders multiple blocks more than once' do
|
150
|
-
content_for(:foo) { "foo" }
|
151
|
-
content_for(:foo) { "bar" }
|
152
|
-
content_for(:bar) { "WON'T RENDER ME" }
|
153
|
-
content_for(:foo) { "baz" }
|
154
|
-
expect(render(inner, :multiple_yields)).to eq("foobarbazfoobarbazfoobarbaz")
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'passes values to the blocks' do
|
158
|
-
content_for(:foo) { |a,b| "<i>#{a}</i>#{b}" }
|
159
|
-
expect(render(inner, :passes_values)).to eq("<i>1</i>2")
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'clears named blocks with the specified key' do
|
163
|
-
content_for(:foo) { "foo" }
|
164
|
-
expect(render(inner, :layout)).to eq("foo")
|
165
|
-
clear_content_for(:foo)
|
166
|
-
expect(render(inner, :layout)).to be_empty
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "with content_for? in Ruby" do
|
171
|
-
it 'renders block if key is set' do
|
172
|
-
content_for(:foo) { "foot" }
|
173
|
-
expect(render(inner, :footer)).to eq("foot")
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'does not render a block if different key' do
|
177
|
-
content_for(:different_key) { "foot" }
|
178
|
-
expect(render(inner, :footer)).to be_empty
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
engines.each do |outer|
|
183
|
-
describe "with yield_content in #{outer.capitalize}" do
|
184
|
-
def body
|
185
|
-
last_response.body.gsub(/\s/, '')
|
186
|
-
end
|
187
|
-
|
188
|
-
before :all do
|
189
|
-
begin
|
190
|
-
require outer
|
191
|
-
rescue LoadError => e
|
192
|
-
skip "Skipping: " << e.message
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
before do
|
197
|
-
mock_app do
|
198
|
-
helpers Sinatra::ContentFor
|
199
|
-
set inner, :layout_engine => outer
|
200
|
-
set :views, File.expand_path("../content_for", __FILE__)
|
201
|
-
get('/:view') { render(inner, params[:view].to_sym) }
|
202
|
-
get('/:layout/:view') do
|
203
|
-
render inner, params[:view].to_sym, :layout => params[:layout].to_sym
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'renders blocks declared with the same key you use when rendering' do
|
209
|
-
expect(get('/same_key')).to be_ok
|
210
|
-
expect(body).to eq("foo")
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'renders blocks more than once' do
|
214
|
-
expect(get('/multiple_yields/same_key')).to be_ok
|
215
|
-
expect(body).to eq("foofoofoo")
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'does not render a block with a different key' do
|
219
|
-
expect(get('/different_key')).to be_ok
|
220
|
-
expect(body).to be_empty
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'renders multiple blocks with the same key' do
|
224
|
-
expect(get('/multiple_blocks')).to be_ok
|
225
|
-
expect(body).to eq("foobarbaz")
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'renders multiple blocks more than once' do
|
229
|
-
expect(get('/multiple_yields/multiple_blocks')).to be_ok
|
230
|
-
expect(body).to eq("foobarbazfoobarbazfoobarbaz")
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'passes values to the blocks' do
|
234
|
-
expect(get('/passes_values/takes_values')).to be_ok
|
235
|
-
expect(body).to eq("<i>1</i>2")
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
data/spec/cookies_spec.rb
DELETED
@@ -1,826 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Sinatra::Cookies do
|
4
|
-
def cookie_route(*cookies, &block)
|
5
|
-
result = nil
|
6
|
-
set_cookie(cookies)
|
7
|
-
@cookie_app.get('/') do
|
8
|
-
result = instance_eval(&block)
|
9
|
-
"ok"
|
10
|
-
end
|
11
|
-
get '/', {}, @headers || {}
|
12
|
-
expect(last_response).to be_ok
|
13
|
-
expect(body).to eq("ok")
|
14
|
-
result
|
15
|
-
end
|
16
|
-
|
17
|
-
def cookies(*set_cookies)
|
18
|
-
cookie_route(*set_cookies) { cookies }
|
19
|
-
end
|
20
|
-
|
21
|
-
before do
|
22
|
-
app = nil
|
23
|
-
mock_app do
|
24
|
-
helpers Sinatra::Cookies
|
25
|
-
app = self
|
26
|
-
end
|
27
|
-
@cookie_app = app
|
28
|
-
clear_cookies
|
29
|
-
end
|
30
|
-
|
31
|
-
describe :cookie_route do
|
32
|
-
it 'runs the block' do
|
33
|
-
ran = false
|
34
|
-
cookie_route { ran = true }
|
35
|
-
expect(ran).to be true
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'returns the block result' do
|
39
|
-
expect(cookie_route { 42 }).to eq(42)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe :== do
|
44
|
-
it 'is comparable to hashes' do
|
45
|
-
expect(cookies).to eq({})
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'is comparable to anything that responds to to_hash' do
|
49
|
-
other = Struct.new(:to_hash).new({})
|
50
|
-
expect(cookies).to eq(other)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe :[] do
|
55
|
-
it 'allows access to request cookies' do
|
56
|
-
expect(cookies("foo=bar")["foo"]).to eq("bar")
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'takes symbols as keys' do
|
60
|
-
expect(cookies("foo=bar")[:foo]).to eq("bar")
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'returns nil for missing keys' do
|
64
|
-
expect(cookies("foo=bar")['bar']).to be_nil
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'allows access to response cookies' do
|
68
|
-
expect(cookie_route do
|
69
|
-
response.set_cookie 'foo', 'bar'
|
70
|
-
cookies['foo']
|
71
|
-
end).to eq('bar')
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'favors response cookies over request cookies' do
|
75
|
-
expect(cookie_route('foo=bar') do
|
76
|
-
response.set_cookie 'foo', 'baz'
|
77
|
-
cookies['foo']
|
78
|
-
end).to eq('baz')
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
it 'takes the last value for response cookies' do
|
83
|
-
expect(cookie_route do
|
84
|
-
response.set_cookie 'foo', 'bar'
|
85
|
-
response.set_cookie 'foo', 'baz'
|
86
|
-
cookies['foo']
|
87
|
-
end).to eq('baz')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe :[]= do
|
92
|
-
it 'sets cookies to httponly' do
|
93
|
-
expect(cookie_route do
|
94
|
-
cookies['foo'] = 'bar'
|
95
|
-
response['Set-Cookie'].lines.detect { |l| l.start_with? 'foo=' }
|
96
|
-
end).to include('HttpOnly')
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'sets domain to nil if localhost' do
|
100
|
-
@headers = {'HTTP_HOST' => 'localhost'}
|
101
|
-
expect(cookie_route do
|
102
|
-
cookies['foo'] = 'bar'
|
103
|
-
response['Set-Cookie']
|
104
|
-
end).not_to include("domain")
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'sets the domain' do
|
108
|
-
expect(cookie_route do
|
109
|
-
cookies['foo'] = 'bar'
|
110
|
-
response['Set-Cookie'].lines.detect { |l| l.start_with? 'foo=' }
|
111
|
-
end).to include('domain=example.org')
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'sets path to / by default' do
|
115
|
-
expect(cookie_route do
|
116
|
-
cookies['foo'] = 'bar'
|
117
|
-
response['Set-Cookie'].lines.detect { |l| l.start_with? 'foo=' }
|
118
|
-
end).to include('path=/')
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'sets path to the script_name if app is nested' do
|
122
|
-
expect(cookie_route do
|
123
|
-
request.script_name = '/foo'
|
124
|
-
cookies['foo'] = 'bar'
|
125
|
-
response['Set-Cookie'].lines.detect { |l| l.start_with? 'foo=' }
|
126
|
-
end).to include('path=/foo')
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'sets a cookie' do
|
130
|
-
cookie_route { cookies['foo'] = 'bar' }
|
131
|
-
expect(cookie_jar['foo']).to eq('bar')
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'adds a value to the cookies hash' do
|
135
|
-
expect(cookie_route do
|
136
|
-
cookies['foo'] = 'bar'
|
137
|
-
cookies['foo']
|
138
|
-
end).to eq('bar')
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe :assoc do
|
143
|
-
it 'behaves like Hash#assoc' do
|
144
|
-
cookies('foo=bar').assoc('foo') == ['foo', 'bar']
|
145
|
-
end
|
146
|
-
end if Hash.method_defined? :assoc
|
147
|
-
|
148
|
-
describe :clear do
|
149
|
-
it 'removes request cookies from cookies hash' do
|
150
|
-
jar = cookies('foo=bar')
|
151
|
-
expect(jar['foo']).to eq('bar')
|
152
|
-
jar.clear
|
153
|
-
expect(jar['foo']).to be_nil
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'removes response cookies from cookies hash' do
|
157
|
-
expect(cookie_route do
|
158
|
-
cookies['foo'] = 'bar'
|
159
|
-
cookies.clear
|
160
|
-
cookies['foo']
|
161
|
-
end).to be_nil
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'expires existing cookies' do
|
165
|
-
expect(cookie_route("foo=bar") do
|
166
|
-
cookies.clear
|
167
|
-
response['Set-Cookie']
|
168
|
-
end).to include("foo=;", "expires=", "1970 00:00:00")
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe :compare_by_identity? do
|
173
|
-
it { expect(cookies).not_to be_compare_by_identity }
|
174
|
-
end
|
175
|
-
|
176
|
-
describe :default do
|
177
|
-
it { expect(cookies.default).to be_nil }
|
178
|
-
end
|
179
|
-
|
180
|
-
describe :default_proc do
|
181
|
-
it { expect(cookies.default_proc).to be_nil }
|
182
|
-
end
|
183
|
-
|
184
|
-
describe :delete do
|
185
|
-
it 'removes request cookies from cookies hash' do
|
186
|
-
jar = cookies('foo=bar')
|
187
|
-
expect(jar['foo']).to eq('bar')
|
188
|
-
jar.delete 'foo'
|
189
|
-
expect(jar['foo']).to be_nil
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'removes response cookies from cookies hash' do
|
193
|
-
expect(cookie_route do
|
194
|
-
cookies['foo'] = 'bar'
|
195
|
-
cookies.delete 'foo'
|
196
|
-
cookies['foo']
|
197
|
-
end).to be_nil
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'expires existing cookies' do
|
201
|
-
expect(cookie_route("foo=bar") do
|
202
|
-
cookies.delete 'foo'
|
203
|
-
response['Set-Cookie']
|
204
|
-
end).to include("foo=;", "expires=", "1970 00:00:00")
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'honours the app cookie_options' do
|
208
|
-
@cookie_app.class_eval do
|
209
|
-
set :cookie_options, {
|
210
|
-
:path => '/foo',
|
211
|
-
:domain => 'bar.com',
|
212
|
-
:secure => true,
|
213
|
-
:httponly => true
|
214
|
-
}
|
215
|
-
end
|
216
|
-
cookie_header = cookie_route("foo=bar") do
|
217
|
-
cookies.delete 'foo'
|
218
|
-
response['Set-Cookie']
|
219
|
-
end
|
220
|
-
expect(cookie_header).to include("path=/foo;", "domain=bar.com;", "secure;", "HttpOnly")
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'does not touch other cookies' do
|
224
|
-
expect(cookie_route("foo=bar", "bar=baz") do
|
225
|
-
cookies.delete 'foo'
|
226
|
-
cookies['bar']
|
227
|
-
end).to eq('baz')
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'returns the previous value for request cookies' do
|
231
|
-
expect(cookie_route("foo=bar") do
|
232
|
-
cookies.delete "foo"
|
233
|
-
end).to eq("bar")
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'returns the previous value for response cookies' do
|
237
|
-
expect(cookie_route do
|
238
|
-
cookies['foo'] = 'bar'
|
239
|
-
cookies.delete "foo"
|
240
|
-
end).to eq("bar")
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'returns nil for non-existing cookies' do
|
244
|
-
expect(cookie_route { cookies.delete("foo") }).to be_nil
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe :delete_if do
|
249
|
-
it 'deletes cookies that match the block' do
|
250
|
-
expect(cookie_route('foo=bar') do
|
251
|
-
cookies['bar'] = 'baz'
|
252
|
-
cookies['baz'] = 'foo'
|
253
|
-
cookies.delete_if { |*a| a.include? 'bar' }
|
254
|
-
cookies.values_at 'foo', 'bar', 'baz'
|
255
|
-
end).to eq([nil, nil, 'foo'])
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
describe :each do
|
260
|
-
it 'loops through cookies' do
|
261
|
-
keys = []
|
262
|
-
foo = nil
|
263
|
-
bar = nil
|
264
|
-
|
265
|
-
cookie_route('foo=bar', 'bar=baz') do
|
266
|
-
cookies.each do |key, value|
|
267
|
-
foo = value if key == 'foo'
|
268
|
-
bar = value if key == 'bar'
|
269
|
-
keys << key
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
expect(keys.sort).to eq(['bar', 'foo'])
|
274
|
-
expect(foo).to eq('bar')
|
275
|
-
expect(bar).to eq('baz')
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'favors response over request cookies' do
|
279
|
-
seen = false
|
280
|
-
key = nil
|
281
|
-
value = nil
|
282
|
-
cookie_route('foo=bar') do
|
283
|
-
cookies[:foo] = 'baz'
|
284
|
-
cookies.each do |k,v|
|
285
|
-
key = k
|
286
|
-
value = v
|
287
|
-
end
|
288
|
-
end
|
289
|
-
expect(key).to eq('foo')
|
290
|
-
expect(value).to eq('baz')
|
291
|
-
expect(seen).to eq(false)
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'does not loop through deleted cookies' do
|
295
|
-
cookie_route('foo=bar') do
|
296
|
-
cookies.delete :foo
|
297
|
-
cookies.each { fail }
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'returns an enumerator' do
|
302
|
-
keys = []
|
303
|
-
cookie_route('foo=bar') do
|
304
|
-
enum = cookies.each
|
305
|
-
enum.each { |key, value| keys << key }
|
306
|
-
end
|
307
|
-
keys.each{ |key| expect(key).to eq('foo')}
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
describe :each_key do
|
312
|
-
it 'loops through cookies' do
|
313
|
-
keys = []
|
314
|
-
|
315
|
-
cookie_route('foo=bar', 'bar=baz') do
|
316
|
-
cookies.each_key do |key|
|
317
|
-
keys << key
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
expect(keys.sort).to eq(['bar', 'foo'])
|
322
|
-
end
|
323
|
-
|
324
|
-
it 'only yields keys once' do
|
325
|
-
seen = false
|
326
|
-
cookie_route('foo=bar') do
|
327
|
-
cookies[:foo] = 'baz'
|
328
|
-
end
|
329
|
-
expect(seen).to eq(false)
|
330
|
-
end
|
331
|
-
|
332
|
-
it 'does not loop through deleted cookies' do
|
333
|
-
cookie_route('foo=bar') do
|
334
|
-
cookies.delete :foo
|
335
|
-
cookies.each_key { fail }
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'returns an enumerator' do
|
340
|
-
keys = []
|
341
|
-
cookie_route('foo=bar') do
|
342
|
-
enum = cookies.each_key
|
343
|
-
enum.each { |key| keys << key }
|
344
|
-
end
|
345
|
-
keys.each{ |key| expect(key).to eq('foo')}
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
describe :each_pair do
|
350
|
-
it 'loops through cookies' do
|
351
|
-
keys = []
|
352
|
-
foo = nil
|
353
|
-
bar = nil
|
354
|
-
|
355
|
-
cookie_route('foo=bar', 'bar=baz') do
|
356
|
-
cookies.each_pair do |key, value|
|
357
|
-
foo = value if key == 'foo'
|
358
|
-
bar = value if key == 'bar'
|
359
|
-
keys << key
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
expect(keys.sort).to eq(['bar', 'foo'])
|
364
|
-
expect(foo).to eq('bar')
|
365
|
-
expect(bar).to eq('baz')
|
366
|
-
end
|
367
|
-
|
368
|
-
it 'favors response over request cookies' do
|
369
|
-
seen = false
|
370
|
-
key = nil
|
371
|
-
value = nil
|
372
|
-
cookie_route('foo=bar') do
|
373
|
-
cookies[:foo] = 'baz'
|
374
|
-
cookies.each_pair do |k, v|
|
375
|
-
key = k
|
376
|
-
value = v
|
377
|
-
end
|
378
|
-
end
|
379
|
-
expect(key).to eq('foo')
|
380
|
-
expect(value).to eq('baz')
|
381
|
-
expect(seen).to eq(false)
|
382
|
-
end
|
383
|
-
|
384
|
-
it 'does not loop through deleted cookies' do
|
385
|
-
cookie_route('foo=bar') do
|
386
|
-
cookies.delete :foo
|
387
|
-
cookies.each_pair { fail }
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
it 'returns an enumerator' do
|
392
|
-
keys = []
|
393
|
-
cookie_route('foo=bar') do
|
394
|
-
enum = cookies.each_pair
|
395
|
-
enum.each { |key, value| keys << key }
|
396
|
-
end
|
397
|
-
keys.each{ |key| expect(key).to eq('foo')}
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
describe :each_value do
|
402
|
-
it 'loops through cookies' do
|
403
|
-
values = []
|
404
|
-
|
405
|
-
cookie_route('foo=bar', 'bar=baz') do
|
406
|
-
cookies.each_value do |value|
|
407
|
-
values << value
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
expect(values.sort).to eq(['bar', 'baz'])
|
412
|
-
end
|
413
|
-
|
414
|
-
it 'favors response over request cookies' do
|
415
|
-
seen = false
|
416
|
-
value = nil
|
417
|
-
cookie_route('foo=bar') do
|
418
|
-
cookies[:foo] = 'baz'
|
419
|
-
cookies.each_value do |v|
|
420
|
-
value = v
|
421
|
-
end
|
422
|
-
end
|
423
|
-
expect(value).to eq('baz')
|
424
|
-
end
|
425
|
-
|
426
|
-
it 'does not loop through deleted cookies' do
|
427
|
-
cookie_route('foo=bar') do
|
428
|
-
cookies.delete :foo
|
429
|
-
cookies.each_value { fail }
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
it 'returns an enumerator' do
|
434
|
-
enum = nil
|
435
|
-
cookie_route('foo=bar') do
|
436
|
-
enum = cookies.each_value
|
437
|
-
end
|
438
|
-
enum.each { |value| expect(value).to eq('bar') }
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
describe :empty? do
|
443
|
-
it 'returns true if there are no cookies' do
|
444
|
-
expect(cookies).to be_empty
|
445
|
-
end
|
446
|
-
|
447
|
-
it 'returns false if there are request cookies' do
|
448
|
-
expect(cookies('foo=bar')).not_to be_empty
|
449
|
-
end
|
450
|
-
|
451
|
-
it 'returns false if there are response cookies' do
|
452
|
-
expect(cookie_route do
|
453
|
-
cookies['foo'] = 'bar'
|
454
|
-
cookies.empty?
|
455
|
-
end).to be false
|
456
|
-
end
|
457
|
-
|
458
|
-
it 'becomes true if response cookies are removed' do
|
459
|
-
expect(cookie_route do
|
460
|
-
cookies['foo'] = 'bar'
|
461
|
-
cookies.delete :foo
|
462
|
-
cookies.empty?
|
463
|
-
end).to be true
|
464
|
-
end
|
465
|
-
|
466
|
-
it 'becomes true if request cookies are removed' do
|
467
|
-
expect(cookie_route('foo=bar') do
|
468
|
-
cookies.delete :foo
|
469
|
-
cookies.empty?
|
470
|
-
end).to be_truthy
|
471
|
-
end
|
472
|
-
|
473
|
-
it 'becomes true after clear' do
|
474
|
-
expect(cookie_route('foo=bar', 'bar=baz') do
|
475
|
-
cookies['foo'] = 'bar'
|
476
|
-
cookies.clear
|
477
|
-
cookies.empty?
|
478
|
-
end).to be_truthy
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
describe :fetch do
|
483
|
-
it 'returns values from request cookies' do
|
484
|
-
expect(cookies('foo=bar').fetch('foo')).to eq('bar')
|
485
|
-
end
|
486
|
-
|
487
|
-
it 'returns values from response cookies' do
|
488
|
-
expect(cookie_route do
|
489
|
-
cookies['foo'] = 'bar'
|
490
|
-
cookies.fetch('foo')
|
491
|
-
end).to eq('bar')
|
492
|
-
end
|
493
|
-
|
494
|
-
it 'favors response over request cookies' do
|
495
|
-
expect(cookie_route('foo=baz') do
|
496
|
-
cookies['foo'] = 'bar'
|
497
|
-
cookies.fetch('foo')
|
498
|
-
end).to eq('bar')
|
499
|
-
end
|
500
|
-
|
501
|
-
it 'raises an exception if key does not exist' do
|
502
|
-
error = if defined? JRUBY_VERSION
|
503
|
-
IndexError
|
504
|
-
else
|
505
|
-
KeyError
|
506
|
-
end
|
507
|
-
expect { cookies.fetch('foo') }.to raise_exception(error)
|
508
|
-
end
|
509
|
-
|
510
|
-
it 'returns the block result if missing' do
|
511
|
-
expect(cookies.fetch('foo') { 'bar' }).to eq('bar')
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|
515
|
-
describe :flatten do
|
516
|
-
it { expect(cookies('foo=bar').flatten).to eq({'foo' => 'bar'}.flatten) }
|
517
|
-
end if Hash.method_defined? :flatten
|
518
|
-
|
519
|
-
describe :has_key? do
|
520
|
-
it 'checks request cookies' do
|
521
|
-
expect(cookies('foo=bar')).to have_key('foo')
|
522
|
-
end
|
523
|
-
|
524
|
-
it 'checks response cookies' do
|
525
|
-
jar = cookies
|
526
|
-
jar['foo'] = 'bar'
|
527
|
-
expect(jar).to have_key(:foo)
|
528
|
-
end
|
529
|
-
|
530
|
-
it 'does not use deleted cookies' do
|
531
|
-
jar = cookies('foo=bar')
|
532
|
-
jar.delete :foo
|
533
|
-
expect(jar).not_to have_key('foo')
|
534
|
-
end
|
535
|
-
end
|
536
|
-
|
537
|
-
describe :has_value? do
|
538
|
-
it 'checks request cookies' do
|
539
|
-
expect(cookies('foo=bar')).to have_value('bar')
|
540
|
-
end
|
541
|
-
|
542
|
-
it 'checks response cookies' do
|
543
|
-
jar = cookies
|
544
|
-
jar[:foo] = 'bar'
|
545
|
-
expect(jar).to have_value('bar')
|
546
|
-
end
|
547
|
-
|
548
|
-
it 'does not use deleted cookies' do
|
549
|
-
jar = cookies('foo=bar')
|
550
|
-
jar.delete :foo
|
551
|
-
expect(jar).not_to have_value('bar')
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
describe :include? do
|
556
|
-
it 'checks request cookies' do
|
557
|
-
expect(cookies('foo=bar')).to include('foo')
|
558
|
-
end
|
559
|
-
|
560
|
-
it 'checks response cookies' do
|
561
|
-
jar = cookies
|
562
|
-
jar['foo'] = 'bar'
|
563
|
-
expect(jar).to include(:foo)
|
564
|
-
end
|
565
|
-
|
566
|
-
it 'does not use deleted cookies' do
|
567
|
-
jar = cookies('foo=bar')
|
568
|
-
jar.delete :foo
|
569
|
-
expect(jar).not_to include('foo')
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
describe :keep_if do
|
574
|
-
it 'removes entries' do
|
575
|
-
jar = cookies('foo=bar', 'bar=baz')
|
576
|
-
jar.keep_if { |*args| args == ['bar', 'baz'] }
|
577
|
-
expect(jar).to eq({'bar' => 'baz'})
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
describe :key do
|
582
|
-
it 'checks request cookies' do
|
583
|
-
expect(cookies('foo=bar').key('bar')).to eq('foo')
|
584
|
-
end
|
585
|
-
|
586
|
-
it 'checks response cookies' do
|
587
|
-
jar = cookies
|
588
|
-
jar['foo'] = 'bar'
|
589
|
-
expect(jar.key('bar')).to eq('foo')
|
590
|
-
end
|
591
|
-
|
592
|
-
it 'returns nil when missing' do
|
593
|
-
expect(cookies('foo=bar').key('baz')).to be_nil
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
describe :key? do
|
598
|
-
it 'checks request cookies' do
|
599
|
-
expect(cookies('foo=bar').key?('foo')).to be true
|
600
|
-
end
|
601
|
-
|
602
|
-
it 'checks response cookies' do
|
603
|
-
jar = cookies
|
604
|
-
jar['foo'] = 'bar'
|
605
|
-
expect(jar.key?(:foo)).to be true
|
606
|
-
end
|
607
|
-
|
608
|
-
it 'does not use deleted cookies' do
|
609
|
-
jar = cookies('foo=bar')
|
610
|
-
jar.delete :foo
|
611
|
-
expect(jar.key?('foo')).to be false
|
612
|
-
end
|
613
|
-
end
|
614
|
-
|
615
|
-
describe :keys do
|
616
|
-
it { expect(cookies('foo=bar').keys).to eq(['foo']) }
|
617
|
-
end
|
618
|
-
|
619
|
-
describe :length do
|
620
|
-
it { expect(cookies.length).to eq(0) }
|
621
|
-
it { expect(cookies('foo=bar').length).to eq(1) }
|
622
|
-
end
|
623
|
-
|
624
|
-
describe :member? do
|
625
|
-
it 'checks request cookies' do
|
626
|
-
expect(cookies('foo=bar').member?('foo')).to be true
|
627
|
-
end
|
628
|
-
|
629
|
-
it 'checks response cookies' do
|
630
|
-
jar = cookies
|
631
|
-
jar['foo'] = 'bar'
|
632
|
-
expect(jar.member?(:foo)).to be true
|
633
|
-
end
|
634
|
-
|
635
|
-
it 'does not use deleted cookies' do
|
636
|
-
jar = cookies('foo=bar')
|
637
|
-
jar.delete :foo
|
638
|
-
expect(jar.member?('foo')).to be false
|
639
|
-
end
|
640
|
-
end
|
641
|
-
|
642
|
-
describe :merge do
|
643
|
-
it 'is mergable with a hash' do
|
644
|
-
expect(cookies('foo=bar').merge(:bar => :baz)).to eq({"foo" => "bar", :bar => :baz})
|
645
|
-
end
|
646
|
-
|
647
|
-
it 'does not create cookies' do
|
648
|
-
jar = cookies('foo=bar')
|
649
|
-
jar.merge(:bar => 'baz')
|
650
|
-
expect(jar).not_to include(:bar)
|
651
|
-
end
|
652
|
-
|
653
|
-
it 'takes a block for conflict resolution' do
|
654
|
-
update = {'foo' => 'baz', 'bar' => 'baz'}
|
655
|
-
merged = cookies('foo=bar').merge(update) do |key, old, other|
|
656
|
-
expect(key).to eq('foo')
|
657
|
-
expect(old).to eq('bar')
|
658
|
-
expect(other).to eq('baz')
|
659
|
-
'foo'
|
660
|
-
end
|
661
|
-
expect(merged['foo']).to eq('foo')
|
662
|
-
end
|
663
|
-
end
|
664
|
-
|
665
|
-
describe :merge! do
|
666
|
-
it 'creates cookies' do
|
667
|
-
jar = cookies('foo=bar')
|
668
|
-
jar.merge! :bar => 'baz'
|
669
|
-
expect(jar).to include('bar')
|
670
|
-
end
|
671
|
-
|
672
|
-
it 'overrides existing values' do
|
673
|
-
jar = cookies('foo=bar')
|
674
|
-
jar.merge! :foo => "baz"
|
675
|
-
expect(jar["foo"]).to eq("baz")
|
676
|
-
end
|
677
|
-
|
678
|
-
it 'takes a block for conflict resolution' do
|
679
|
-
update = {'foo' => 'baz', 'bar' => 'baz'}
|
680
|
-
jar = cookies('foo=bar')
|
681
|
-
jar.merge!(update) do |key, old, other|
|
682
|
-
expect(key).to eq('foo')
|
683
|
-
expect(old).to eq('bar')
|
684
|
-
expect(other).to eq('baz')
|
685
|
-
'foo'
|
686
|
-
end
|
687
|
-
expect(jar['foo']).to eq('foo')
|
688
|
-
end
|
689
|
-
end
|
690
|
-
|
691
|
-
describe :rassoc do
|
692
|
-
it 'behaves like Hash#assoc' do
|
693
|
-
cookies('foo=bar').rassoc('bar') == ['foo', 'bar']
|
694
|
-
end
|
695
|
-
end if Hash.method_defined? :rassoc
|
696
|
-
|
697
|
-
describe :reject do
|
698
|
-
it 'removes entries from new hash' do
|
699
|
-
jar = cookies('foo=bar', 'bar=baz')
|
700
|
-
sub = jar.reject { |*args| args == ['bar', 'baz'] }
|
701
|
-
expect(sub).to eq({'foo' => 'bar'})
|
702
|
-
expect(jar['bar']).to eq('baz')
|
703
|
-
end
|
704
|
-
end
|
705
|
-
|
706
|
-
describe :reject! do
|
707
|
-
it 'removes entries' do
|
708
|
-
jar = cookies('foo=bar', 'bar=baz')
|
709
|
-
jar.reject! { |*args| args == ['bar', 'baz'] }
|
710
|
-
expect(jar).to eq({'foo' => 'bar'})
|
711
|
-
end
|
712
|
-
end
|
713
|
-
|
714
|
-
describe :replace do
|
715
|
-
it 'replaces entries' do
|
716
|
-
jar = cookies('foo=bar', 'bar=baz')
|
717
|
-
jar.replace 'foo' => 'baz', 'baz' => 'bar'
|
718
|
-
expect(jar).to eq({'foo' => 'baz', 'baz' => 'bar'})
|
719
|
-
end
|
720
|
-
end
|
721
|
-
|
722
|
-
describe :set do
|
723
|
-
it 'sets a cookie' do
|
724
|
-
cookie_route { cookies.set('foo', value: 'bar') }
|
725
|
-
expect(cookie_jar['foo']).to eq('bar')
|
726
|
-
end
|
727
|
-
|
728
|
-
it 'sets a cookie with HttpOnly' do
|
729
|
-
expect(cookie_route do
|
730
|
-
request.script_name = '/foo'
|
731
|
-
cookies.set('foo', value: 'bar', httponly: true)
|
732
|
-
response['Set-Cookie'].lines.detect { |l| l.start_with? 'foo=' }
|
733
|
-
end).to include('HttpOnly')
|
734
|
-
end
|
735
|
-
|
736
|
-
it 'sets a cookie without HttpOnly' do
|
737
|
-
expect(cookie_route do
|
738
|
-
request.script_name = '/foo'
|
739
|
-
cookies.set('foo', value: 'bar', httponly: false)
|
740
|
-
response['Set-Cookie'].lines.detect { |l| l.start_with? 'foo=' }
|
741
|
-
end).not_to include('HttpOnly')
|
742
|
-
end
|
743
|
-
end
|
744
|
-
|
745
|
-
describe :select do
|
746
|
-
it 'removes entries from new hash' do
|
747
|
-
jar = cookies('foo=bar', 'bar=baz')
|
748
|
-
sub = jar.select { |*args| args != ['bar', 'baz'] }
|
749
|
-
expect(sub).to eq({'foo' => 'bar'}.select { true })
|
750
|
-
expect(jar['bar']).to eq('baz')
|
751
|
-
end
|
752
|
-
end
|
753
|
-
|
754
|
-
describe :select! do
|
755
|
-
it 'removes entries' do
|
756
|
-
jar = cookies('foo=bar', 'bar=baz')
|
757
|
-
jar.select! { |*args| args != ['bar', 'baz'] }
|
758
|
-
expect(jar).to eq({'foo' => 'bar'})
|
759
|
-
end
|
760
|
-
end if Hash.method_defined? :select!
|
761
|
-
|
762
|
-
describe :shift do
|
763
|
-
it 'removes from the hash' do
|
764
|
-
jar = cookies('foo=bar')
|
765
|
-
expect(jar.shift).to eq(['foo', 'bar'])
|
766
|
-
expect(jar).not_to include('bar')
|
767
|
-
end
|
768
|
-
end
|
769
|
-
|
770
|
-
describe :size do
|
771
|
-
it { expect(cookies.size).to eq(0) }
|
772
|
-
it { expect(cookies('foo=bar').size).to eq(1) }
|
773
|
-
end
|
774
|
-
|
775
|
-
describe :update do
|
776
|
-
it 'creates cookies' do
|
777
|
-
jar = cookies('foo=bar')
|
778
|
-
jar.update :bar => 'baz'
|
779
|
-
expect(jar).to include('bar')
|
780
|
-
end
|
781
|
-
|
782
|
-
it 'overrides existing values' do
|
783
|
-
jar = cookies('foo=bar')
|
784
|
-
jar.update :foo => "baz"
|
785
|
-
expect(jar["foo"]).to eq("baz")
|
786
|
-
end
|
787
|
-
|
788
|
-
it 'takes a block for conflict resolution' do
|
789
|
-
merge = {'foo' => 'baz', 'bar' => 'baz'}
|
790
|
-
jar = cookies('foo=bar')
|
791
|
-
jar.update(merge) do |key, old, other|
|
792
|
-
expect(key).to eq('foo')
|
793
|
-
expect(old).to eq('bar')
|
794
|
-
expect(other).to eq('baz')
|
795
|
-
'foo'
|
796
|
-
end
|
797
|
-
expect(jar['foo']).to eq('foo')
|
798
|
-
end
|
799
|
-
end
|
800
|
-
|
801
|
-
describe :value? do
|
802
|
-
it 'checks request cookies' do
|
803
|
-
expect(cookies('foo=bar').value?('bar')).to be true
|
804
|
-
end
|
805
|
-
|
806
|
-
it 'checks response cookies' do
|
807
|
-
jar = cookies
|
808
|
-
jar[:foo] = 'bar'
|
809
|
-
expect(jar.value?('bar')).to be true
|
810
|
-
end
|
811
|
-
|
812
|
-
it 'does not use deleted cookies' do
|
813
|
-
jar = cookies('foo=bar')
|
814
|
-
jar.delete :foo
|
815
|
-
expect(jar.value?('bar')).to be false
|
816
|
-
end
|
817
|
-
end
|
818
|
-
|
819
|
-
describe :values do
|
820
|
-
it { expect(cookies('foo=bar', 'bar=baz').values.sort).to eq(['bar', 'baz']) }
|
821
|
-
end
|
822
|
-
|
823
|
-
describe :values_at do
|
824
|
-
it { expect(cookies('foo=bar', 'bar=baz').values_at('foo')).to eq(['bar']) }
|
825
|
-
end
|
826
|
-
end
|