strelka 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ChangeLog +156 -9
- data/History.rdoc +15 -0
- data/IDEAS.rdoc +17 -1
- data/MILESTONES.rdoc +1 -1
- data/Manifest.txt +10 -2
- data/Plugins.rdoc +4 -4
- data/README.rdoc +3 -3
- data/Rakefile +5 -4
- data/bin/strelka +19 -10
- data/contrib/hoetemplate/data/project/apps/file_name_app +1 -0
- data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
- data/examples/apps/hello-world +1 -0
- data/examples/apps/ws-chat +69 -0
- data/examples/apps/ws-echo +61 -0
- data/examples/gen-config.rb +6 -5
- data/lib/strelka/app/auth.rb +2 -2
- data/lib/strelka/app/errors.rb +1 -1
- data/lib/strelka/app/filters.rb +3 -2
- data/lib/strelka/app/negotiation.rb +2 -2
- data/lib/strelka/app/parameters.rb +1 -2
- data/lib/strelka/app/restresources.rb +3 -2
- data/lib/strelka/app/routing.rb +1 -1
- data/lib/strelka/app/sessions.rb +2 -2
- data/lib/strelka/app/templating.rb +7 -3
- data/lib/strelka/app.rb +5 -145
- data/lib/strelka/behavior/plugin.rb +4 -4
- data/lib/strelka/discovery.rb +211 -0
- data/lib/strelka/httprequest.rb +1 -0
- data/lib/strelka/httpresponse/negotiation.rb +7 -1
- data/lib/strelka/mixins.rb +4 -1
- data/lib/strelka/paramvalidator.rb +1 -1
- data/lib/strelka/plugins.rb +8 -6
- data/lib/strelka/websocketserver/routing.rb +116 -0
- data/lib/strelka/websocketserver.rb +147 -0
- data/lib/strelka.rb +5 -4
- data/spec/{lib/constants.rb → constants.rb} +3 -2
- data/spec/{lib/helpers.rb → helpers.rb} +15 -14
- data/spec/strelka/app/auth_spec.rb +145 -142
- data/spec/strelka/app/errors_spec.rb +20 -26
- data/spec/strelka/app/filters_spec.rb +67 -54
- data/spec/strelka/app/negotiation_spec.rb +8 -14
- data/spec/strelka/app/parameters_spec.rb +23 -29
- data/spec/strelka/app/restresources_spec.rb +98 -100
- data/spec/strelka/app/routing_spec.rb +57 -57
- data/spec/strelka/app/sessions_spec.rb +11 -17
- data/spec/strelka/app/templating_spec.rb +36 -40
- data/spec/strelka/app_spec.rb +48 -147
- data/spec/strelka/authprovider/basic_spec.rb +5 -11
- data/spec/strelka/authprovider/hostaccess_spec.rb +9 -15
- data/spec/strelka/authprovider_spec.rb +3 -9
- data/spec/strelka/cookie_spec.rb +32 -38
- data/spec/strelka/cookieset_spec.rb +31 -37
- data/spec/strelka/discovery_spec.rb +144 -0
- data/spec/strelka/exceptions_spec.rb +2 -8
- data/spec/strelka/httprequest/acceptparams_spec.rb +74 -83
- data/spec/strelka/httprequest/auth_spec.rb +5 -15
- data/spec/strelka/httprequest/negotiation_spec.rb +93 -103
- data/spec/strelka/httprequest/session_spec.rb +12 -22
- data/spec/strelka/httprequest_spec.rb +1 -7
- data/spec/strelka/httpresponse/negotiation_spec.rb +84 -76
- data/spec/strelka/httpresponse/session_spec.rb +25 -35
- data/spec/strelka/httpresponse_spec.rb +20 -26
- data/spec/strelka/mixins_spec.rb +66 -61
- data/spec/strelka/multipartparser_spec.rb +31 -37
- data/spec/strelka/paramvalidator_spec.rb +389 -373
- data/spec/strelka/plugins_spec.rb +17 -23
- data/spec/strelka/router/default_spec.rb +32 -38
- data/spec/strelka/router/exclusive_spec.rb +28 -34
- data/spec/strelka/router_spec.rb +2 -8
- data/spec/strelka/session/db_spec.rb +17 -15
- data/spec/strelka/session/default_spec.rb +22 -28
- data/spec/strelka/session_spec.rb +3 -9
- data/spec/strelka/websocketserver/routing_spec.rb +119 -0
- data/spec/strelka/websocketserver_spec.rb +149 -0
- data/spec/strelka_spec.rb +11 -13
- data.tar.gz.sig +3 -3
- metadata +22 -14
- metadata.gz.sig +0 -0
@@ -1,20 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
|
8
|
-
libdir = basedir + "lib"
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
11
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
12
|
-
}
|
4
|
+
require_relative '../../helpers'
|
13
5
|
|
14
6
|
require 'rspec'
|
15
7
|
|
16
|
-
require 'spec/lib/helpers'
|
17
|
-
|
18
8
|
require 'strelka'
|
19
9
|
require 'strelka/httprequest/negotiation'
|
20
10
|
require 'strelka/httpresponse/negotiation'
|
@@ -48,7 +38,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
48
38
|
@res.puts( "FOOM!" )
|
49
39
|
@res.content_type = 'text/plain'
|
50
40
|
@res.charset = Encoding::UTF_8
|
51
|
-
@res.to_s.
|
41
|
+
expect( @res.to_s ).to include(
|
52
42
|
'HTTP/1.1 200 OK',
|
53
43
|
'Content-Length: 6',
|
54
44
|
'Content-Type: text/plain; charset=UTF-8',
|
@@ -67,9 +57,9 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
67
57
|
@res.for( 'application/x-yaml' ) { { 'a' => "YAML dump" } }
|
68
58
|
|
69
59
|
@res.negotiated_body.rewind
|
70
|
-
@res.negotiated_body.read.
|
71
|
-
@res.content_type.
|
72
|
-
@res.header_data.
|
60
|
+
expect( @res.negotiated_body.read ).to eq( "---\na: YAML dump\n" )
|
61
|
+
expect( @res.content_type ).to eq( "application/x-yaml" )
|
62
|
+
expect( @res.header_data ).to match( /accept(?!-)/i )
|
73
63
|
end
|
74
64
|
|
75
65
|
it "can provide a single block for bodies of several different mediatypes" do
|
@@ -80,10 +70,11 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
80
70
|
end
|
81
71
|
|
82
72
|
@res.negotiated_body.rewind
|
83
|
-
@res.negotiated_body.read.
|
84
|
-
"\"
|
85
|
-
|
86
|
-
@res.
|
73
|
+
expect( @res.negotiated_body.read ).
|
74
|
+
to eq( "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
|
75
|
+
"\"name\":\"Harlot's Garden\"}" )
|
76
|
+
expect( @res.content_type ).to eq( "application/json" )
|
77
|
+
expect( @res.header_data ).to match( /accept(?!-)/i )
|
87
78
|
end
|
88
79
|
|
89
80
|
it "can provide a block for bodies of several different symbolic mediatypes" do
|
@@ -94,10 +85,11 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
94
85
|
end
|
95
86
|
|
96
87
|
@res.negotiated_body.rewind
|
97
|
-
@res.negotiated_body.read.
|
98
|
-
"\"
|
99
|
-
|
100
|
-
@res.
|
88
|
+
expect( @res.negotiated_body.read ).
|
89
|
+
to eq( "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
|
90
|
+
"\"name\":\"Harlot's Garden\"}" )
|
91
|
+
expect( @res.content_type ).to eq( "application/json" )
|
92
|
+
expect( @res.header_data ).to match( /accept(?!-)/i )
|
101
93
|
end
|
102
94
|
|
103
95
|
it "raises an exception if given a block for an unknown symbolic mediatype" do
|
@@ -106,6 +98,22 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
106
98
|
}.to raise_error( StandardError, /no known mimetype/i )
|
107
99
|
end
|
108
100
|
|
101
|
+
it "treat exceptions raised from the block as failed transformations" do
|
102
|
+
@req.headers.accept = 'application/json, text/plain; q=0.9'
|
103
|
+
|
104
|
+
@res.for( :json ) do
|
105
|
+
raise "Oops! I fail at JSON!"
|
106
|
+
end
|
107
|
+
@res.for( :text ) do
|
108
|
+
"But I can do plain-text all day long!"
|
109
|
+
end
|
110
|
+
|
111
|
+
@res.negotiated_body.rewind
|
112
|
+
expect( @res.negotiated_body.read ).to eq( "But I can do plain-text all day long!" )
|
113
|
+
expect( @res.content_type ).to eq( 'text/plain' )
|
114
|
+
expect( @res.header_data ).to match( /accept(?!-)/i )
|
115
|
+
end
|
116
|
+
|
109
117
|
end
|
110
118
|
|
111
119
|
|
@@ -117,8 +125,8 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
117
125
|
@res.body = File.read( __FILE__, encoding: 'iso-8859-5' )
|
118
126
|
@res.content_type = 'text/plain'
|
119
127
|
|
120
|
-
@res.negotiated_body.external_encoding.
|
121
|
-
@res.header_data.
|
128
|
+
expect( @res.negotiated_body.external_encoding ).to eq( Encoding::KOI8_R )
|
129
|
+
expect( @res.header_data ).to match( /accept-charset(?!-)/i )
|
122
130
|
end
|
123
131
|
|
124
132
|
it "transcodes String entity bodies if the charset is not acceptable" do
|
@@ -127,8 +135,8 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
127
135
|
@res.body = File.read( __FILE__, encoding: 'iso-8859-5' )
|
128
136
|
@res.content_type = 'application/json'
|
129
137
|
|
130
|
-
@res.negotiated_body.external_encoding.
|
131
|
-
@res.header_data.
|
138
|
+
expect( @res.negotiated_body.external_encoding ).to eq( Encoding::UTF_8 )
|
139
|
+
expect( @res.header_data ).to match( /accept-charset(?!-)/i )
|
132
140
|
end
|
133
141
|
|
134
142
|
it "transcodes File entity bodies if the charset is not acceptable" do
|
@@ -138,8 +146,8 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
138
146
|
@res.body = File.open( __FILE__, 'r:iso-8859-5' )
|
139
147
|
@res.content_type = 'text/plain'
|
140
148
|
|
141
|
-
@res.negotiated_body.read.encoding.
|
142
|
-
@res.header_data.
|
149
|
+
expect( @res.negotiated_body.read.encoding ).to eq( Encoding::KOI8_R )
|
150
|
+
expect( @res.header_data ).to match( /accept-charset(?!-)/i )
|
143
151
|
end
|
144
152
|
end
|
145
153
|
|
@@ -159,9 +167,9 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
159
167
|
@res.for_language( :sl ) { "Slovenian translation" }
|
160
168
|
|
161
169
|
@res.negotiated_body.rewind
|
162
|
-
@res.negotiated_body.read.
|
163
|
-
@res.languages.
|
164
|
-
@res.header_data.
|
170
|
+
expect( @res.negotiated_body.read ).to eq( "German translation" )
|
171
|
+
expect( @res.languages ).to eq( ["de"] )
|
172
|
+
expect( @res.header_data ).to match( /accept-language/i )
|
165
173
|
end
|
166
174
|
|
167
175
|
it "can provide blocks for bodies of several different languages without setting a " +
|
@@ -175,9 +183,9 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
175
183
|
@res.for_language( :sl ) { "Slovenian translation" }
|
176
184
|
|
177
185
|
@res.negotiated_body.rewind
|
178
|
-
@res.negotiated_body.read.
|
179
|
-
@res.languages.
|
180
|
-
@res.header_data.
|
186
|
+
expect( @res.negotiated_body.read ).to eq( "German translation" )
|
187
|
+
expect( @res.languages ).to eq( ["de"] )
|
188
|
+
expect( @res.header_data ).to match( /accept-language/i )
|
181
189
|
end
|
182
190
|
|
183
191
|
it "can provide a single block for bodies of several different languages" do
|
@@ -195,9 +203,9 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
195
203
|
end
|
196
204
|
|
197
205
|
@res.negotiated_body.rewind
|
198
|
-
@res.negotiated_body.read.
|
199
|
-
@res.languages.
|
200
|
-
@res.header_data.
|
206
|
+
expect( @res.negotiated_body.read ).to eq( "Portuguese translation" )
|
207
|
+
expect( @res.languages ).to eq( ["pt"] )
|
208
|
+
expect( @res.header_data ).to match( /accept-language/i )
|
201
209
|
end
|
202
210
|
|
203
211
|
it "calls the first block for requests with no accept-language header" do
|
@@ -210,9 +218,9 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
210
218
|
@res.for_language( :sl ) { "Slovenian translation" }
|
211
219
|
|
212
220
|
@res.negotiated_body.rewind
|
213
|
-
@res.negotiated_body.read.
|
214
|
-
@res.languages.
|
215
|
-
@res.header_data.
|
221
|
+
expect( @res.negotiated_body.read ).to eq( "English translation" )
|
222
|
+
expect( @res.languages ).to eq( ["en"] )
|
223
|
+
expect( @res.header_data ).to match( /accept-language/i )
|
216
224
|
end
|
217
225
|
end
|
218
226
|
|
@@ -229,10 +237,10 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
229
237
|
@res.for_encoding( :gzip ) { @res.body << " (gzipped)" }
|
230
238
|
|
231
239
|
@res.negotiated_body.rewind
|
232
|
-
@res.negotiated_body.read.
|
233
|
-
@res.encodings.
|
234
|
-
@res.header_data.
|
235
|
-
@res.header_data.
|
240
|
+
expect( @res.negotiated_body.read ).to eq( "the text body (gzipped)" )
|
241
|
+
expect( @res.encodings ).to include( "gzip" )
|
242
|
+
expect( @res.header_data ).to match( /accept-encoding/i )
|
243
|
+
expect( @res.header_data ).to_not match( /identity/i )
|
236
244
|
end
|
237
245
|
|
238
246
|
it "chooses the content coding with the highest qvalue" do
|
@@ -245,10 +253,10 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
245
253
|
@res.for_encoding( :gzip ) { @res.body << " (gzipped)" }
|
246
254
|
|
247
255
|
@res.negotiated_body.rewind
|
248
|
-
@res.negotiated_body.read.
|
249
|
-
@res.encodings.
|
250
|
-
@res.header_data.
|
251
|
-
@res.header_data.
|
256
|
+
expect( @res.negotiated_body.read ).to eq( "the text body (deflated)" )
|
257
|
+
expect( @res.encodings ).to include( "deflate" )
|
258
|
+
expect( @res.header_data ).to match( /accept-encoding/i )
|
259
|
+
expect( @res.header_data ).to_not match( /identity/i )
|
252
260
|
end
|
253
261
|
|
254
262
|
end
|
@@ -261,14 +269,14 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
261
269
|
@req.headers.accept = 'application/x-yaml, application/json; q=0.7'
|
262
270
|
@res.content_type = 'application/json'
|
263
271
|
|
264
|
-
@res.
|
272
|
+
expect( @res ).to have_acceptable_content_type
|
265
273
|
end
|
266
274
|
|
267
275
|
it "knows that it is acceptable if its request doesn't have accepted types" do
|
268
276
|
@req.headers.delete( :accept )
|
269
277
|
@res.content_type = 'application/x-ruby-marshalled'
|
270
278
|
|
271
|
-
@res.
|
279
|
+
expect( @res ).to have_acceptable_content_type
|
272
280
|
end
|
273
281
|
|
274
282
|
it "knows that it is acceptable if it doesn't have an originating request" do
|
@@ -276,7 +284,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
276
284
|
res.extend( Strelka::HTTPResponse::Negotiation )
|
277
285
|
res.content_type = 'application/x-ruby-marshalled'
|
278
286
|
|
279
|
-
res.
|
287
|
+
expect( res ).to have_acceptable_content_type
|
280
288
|
end
|
281
289
|
|
282
290
|
it "knows that it is not acceptable if its content_type isn't in the list of " +
|
@@ -284,7 +292,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
284
292
|
@req.headers.accept = 'application/x-yaml, application/json; q=0.7'
|
285
293
|
@res.content_type = 'application/x-ruby-marshalled'
|
286
294
|
|
287
|
-
@res.
|
295
|
+
expect( @res ).to_not have_acceptable_content_type
|
288
296
|
end
|
289
297
|
|
290
298
|
end
|
@@ -297,20 +305,20 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
297
305
|
@req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
|
298
306
|
@res.charset = 'iso-8859-5'
|
299
307
|
|
300
|
-
@res.
|
308
|
+
expect( @res ).to have_acceptable_charset()
|
301
309
|
end
|
302
310
|
|
303
311
|
it "knows that it is acceptable if its request doesn't have accepted types" do
|
304
312
|
@req.headers.delete( :accept_charset )
|
305
313
|
@res.charset = 'koi8-u'
|
306
|
-
@res.
|
314
|
+
expect( @res ).to have_acceptable_charset()
|
307
315
|
end
|
308
316
|
|
309
317
|
it "knows that it is acceptable if it doesn't have an originating request" do
|
310
318
|
res = Strelka::HTTPResponse.new( 'appid', 88 )
|
311
319
|
res.charset = 'iso8859-15'
|
312
320
|
|
313
|
-
res.
|
321
|
+
expect( res ).to have_acceptable_charset()
|
314
322
|
end
|
315
323
|
|
316
324
|
it "knows that it is acceptable if its explicit charset is set to ascii-8bit" do
|
@@ -318,7 +326,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
318
326
|
@res.content_type = 'image/jpeg'
|
319
327
|
@res.charset = Encoding::ASCII_8BIT
|
320
328
|
|
321
|
-
@res.
|
329
|
+
expect( @res ).to have_acceptable_charset()
|
322
330
|
end
|
323
331
|
|
324
332
|
it "knows that it is acceptable if no charset can be derived, but the list of " +
|
@@ -327,7 +335,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
327
335
|
@res.content_type = 'text/plain'
|
328
336
|
@res.body = "some stuff".force_encoding( Encoding::ASCII_8BIT )
|
329
337
|
|
330
|
-
@res.
|
338
|
+
expect( @res ).to have_acceptable_charset()
|
331
339
|
end
|
332
340
|
|
333
341
|
it "knows that it is not acceptable if no charset can be derived, the content is a " +
|
@@ -336,7 +344,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
336
344
|
@res.content_type = 'text/plain'
|
337
345
|
@res.body = "some stuff".force_encoding( Encoding::ASCII_8BIT )
|
338
346
|
|
339
|
-
@res.
|
347
|
+
expect( @res ).to_not have_acceptable_charset()
|
340
348
|
end
|
341
349
|
|
342
350
|
it "knows that it is not acceptable if its explicit charset isn't in the list of " +
|
@@ -344,7 +352,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
344
352
|
@req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
|
345
353
|
@res.charset = 'sjis'
|
346
354
|
|
347
|
-
@res.
|
355
|
+
expect( @res ).to_not have_acceptable_charset()
|
348
356
|
end
|
349
357
|
|
350
358
|
it "knows that it is not acceptable if the charset in its content-type header isn't in " +
|
@@ -352,7 +360,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
352
360
|
@req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
|
353
361
|
@res.content_type = 'text/plain; charset=sjis'
|
354
362
|
|
355
|
-
@res.
|
363
|
+
expect( @res ).to_not have_acceptable_charset()
|
356
364
|
end
|
357
365
|
|
358
366
|
it "knows that it is not acceptable if the charset derived from its entity body isn't in " +
|
@@ -361,7 +369,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
361
369
|
@res.content_type = 'text/plain'
|
362
370
|
@res.body = File.open( __FILE__, 'r:iso8859-5' )
|
363
371
|
|
364
|
-
@res.
|
372
|
+
expect( @res ).to_not have_acceptable_charset()
|
365
373
|
end
|
366
374
|
|
367
375
|
end
|
@@ -374,7 +382,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
374
382
|
@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
|
375
383
|
@res.languages << 'ja'
|
376
384
|
|
377
|
-
@res.
|
385
|
+
expect( @res ).to have_acceptable_language()
|
378
386
|
end
|
379
387
|
|
380
388
|
it "knows that it is acceptable if all of its multiple languages are in the list of " +
|
@@ -382,7 +390,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
382
390
|
@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
|
383
391
|
@res.languages << 'ja' << 'en-us'
|
384
392
|
|
385
|
-
@res.
|
393
|
+
expect( @res ).to have_acceptable_language()
|
386
394
|
end
|
387
395
|
|
388
396
|
# I'm not sure if this is what RFC1616 means. It might be that *all* of its languages
|
@@ -392,7 +400,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
392
400
|
@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
|
393
401
|
@res.languages << 'pt' << 'en'
|
394
402
|
|
395
|
-
@res.
|
403
|
+
expect( @res ).to have_acceptable_language()
|
396
404
|
end
|
397
405
|
|
398
406
|
it "knows that it is acceptable if it has a body but doesn't have a language set" do
|
@@ -400,14 +408,14 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
400
408
|
@res.languages.clear
|
401
409
|
@res.puts( "Some content in an unspecified language." )
|
402
410
|
|
403
|
-
@res.
|
411
|
+
expect( @res ).to have_acceptable_language()
|
404
412
|
end
|
405
413
|
|
406
414
|
it "knows that it is acceptable if it has no body yet" do
|
407
415
|
@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
|
408
416
|
@res.languages.clear
|
409
417
|
|
410
|
-
@res.
|
418
|
+
expect( @res ).to have_acceptable_language()
|
411
419
|
end
|
412
420
|
|
413
421
|
it "knows that it is acceptable if it doesn't have an originating request" do
|
@@ -415,7 +423,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
415
423
|
res.extend( Strelka::HTTPResponse::Negotiation )
|
416
424
|
res.languages << 'kh'
|
417
425
|
|
418
|
-
res.
|
426
|
+
expect( res ).to have_acceptable_language()
|
419
427
|
end
|
420
428
|
|
421
429
|
it "knows that it is not acceptable if it has a single language that isn't in the " +
|
@@ -423,7 +431,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
423
431
|
@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
|
424
432
|
@res.languages << 'pt'
|
425
433
|
|
426
|
-
@res.
|
434
|
+
expect( @res ).to_not have_acceptable_language()
|
427
435
|
end
|
428
436
|
|
429
437
|
it "knows that it is not acceptable if it has multiple languages, none of which are " +
|
@@ -431,7 +439,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
431
439
|
@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
|
432
440
|
@res.languages << 'pt-br' << 'fr-ca'
|
433
441
|
|
434
|
-
@res.
|
442
|
+
expect( @res ).to_not have_acceptable_language()
|
435
443
|
end
|
436
444
|
|
437
445
|
end
|
@@ -444,7 +452,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
444
452
|
@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0.5, *;q=0'
|
445
453
|
@res.encodings << 'gzip'
|
446
454
|
|
447
|
-
@res.
|
455
|
+
expect( @res ).to have_acceptable_encoding()
|
448
456
|
end
|
449
457
|
|
450
458
|
it "knows that it is acceptable if all of its content codings are in the list of accepted " +
|
@@ -452,7 +460,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
452
460
|
@req.headers.accept_encoding = 'gzip;q=1.0, frobnify;q=0.9, identity; q=0.5, *;q=0'
|
453
461
|
@res.encodings << 'gzip' << 'frobnify'
|
454
462
|
|
455
|
-
@res.
|
463
|
+
expect( @res ).to have_acceptable_encoding()
|
456
464
|
end
|
457
465
|
|
458
466
|
it "knows that it is not acceptable if one of its content codings is not in the list " +
|
@@ -460,7 +468,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
460
468
|
@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0.5, *;q=0'
|
461
469
|
@res.encodings << 'gzip' << 'frobnify'
|
462
470
|
|
463
|
-
@res.
|
471
|
+
expect( @res ).to_not have_acceptable_encoding()
|
464
472
|
end
|
465
473
|
|
466
474
|
it "knows that it is not acceptable if it doesn't have any explicit content codings " +
|
@@ -468,7 +476,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
468
476
|
@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0'
|
469
477
|
@res.encodings.clear
|
470
478
|
|
471
|
-
@res.
|
479
|
+
expect( @res ).to_not have_acceptable_encoding()
|
472
480
|
end
|
473
481
|
|
474
482
|
it "knows that it is not acceptable if it doesn't have any explicit content codings " +
|
@@ -476,7 +484,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
476
484
|
@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0'
|
477
485
|
@res.encodings.clear
|
478
486
|
|
479
|
-
@res.
|
487
|
+
expect( @res ).to_not have_acceptable_encoding()
|
480
488
|
end
|
481
489
|
|
482
490
|
it "knows that it is not acceptable if it doesn't have any explicit content codings, " +
|
@@ -484,7 +492,7 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
484
492
|
@req.headers.accept_encoding = 'gzip;q=1.0, *;q=0'
|
485
493
|
@res.encodings.clear
|
486
494
|
|
487
|
-
@res.
|
495
|
+
expect( @res ).to_not have_acceptable_encoding()
|
488
496
|
end
|
489
497
|
|
490
498
|
end
|
@@ -1,20 +1,10 @@
|
|
1
1
|
# -*- rspec -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
|
8
|
-
libdir = basedir + "lib"
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
11
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
12
|
-
}
|
4
|
+
require_relative '../../helpers'
|
13
5
|
|
14
6
|
require 'rspec'
|
15
7
|
|
16
|
-
require 'spec/lib/helpers'
|
17
|
-
|
18
8
|
require 'strelka'
|
19
9
|
require 'strelka/app/sessions'
|
20
10
|
require 'strelka/httprequest/session'
|
@@ -51,34 +41,34 @@ describe Strelka::HTTPResponse::Session, "-extended response" do
|
|
51
41
|
|
52
42
|
|
53
43
|
it "has a session_namespace attribute" do
|
54
|
-
@res.
|
44
|
+
expect( @res ).to respond_to( :session_namespace )
|
55
45
|
end
|
56
46
|
|
57
47
|
it "sets its request's session when its session is set" do
|
58
48
|
@res.session = Strelka::Session.create( :default )
|
59
49
|
pending "not sure if it should do this or not" do
|
60
|
-
@req.session.
|
50
|
+
expect( @req.session ).to be( @res.session )
|
61
51
|
end
|
62
52
|
end
|
63
53
|
|
64
54
|
context "for a request with no session ID" do
|
65
55
|
|
66
56
|
it "knows that it doesn't have a session" do
|
67
|
-
@res.
|
57
|
+
expect( @res ).to_not have_session()
|
68
58
|
end
|
69
59
|
|
70
60
|
it "doesn't load the session when the session namespace is set" do
|
71
61
|
@res.session_namespace = 'an_appid'
|
72
|
-
@res.
|
62
|
+
expect( @res ).to_not have_session()
|
73
63
|
end
|
74
64
|
|
75
65
|
it "creates a new session as soon as it's accessed" do
|
76
|
-
@res.session.
|
66
|
+
expect( @res.session ).to be_a( Strelka::Session::Default )
|
77
67
|
end
|
78
68
|
|
79
69
|
it "sets its session's namespace when it loads if the session_namespace is set" do
|
80
70
|
@res.session_namespace = 'an_appid'
|
81
|
-
@res.session.namespace.
|
71
|
+
expect( @res.session.namespace ).to eq( :an_appid )
|
82
72
|
end
|
83
73
|
|
84
74
|
|
@@ -90,16 +80,16 @@ describe Strelka::HTTPResponse::Session, "-extended response" do
|
|
90
80
|
end
|
91
81
|
|
92
82
|
it "knows that it has a session" do
|
93
|
-
@res.
|
83
|
+
expect( @res ).to have_session()
|
94
84
|
end
|
95
85
|
|
96
86
|
it "copies the session from its request when accessed" do
|
97
|
-
@res.session.
|
87
|
+
expect( @res.session ).to be( @session )
|
98
88
|
end
|
99
89
|
|
100
90
|
it "sets the session's namespace when its session_namespace is set" do
|
101
91
|
@res.session_namespace = 'the_appid'
|
102
|
-
@res.session.namespace.
|
92
|
+
expect( @res.session.namespace ).to eq( :the_appid )
|
103
93
|
end
|
104
94
|
|
105
95
|
end
|
@@ -116,7 +106,7 @@ describe Strelka::HTTPResponse::Session, "-extended response" do
|
|
116
106
|
end
|
117
107
|
|
118
108
|
it "knows that it doesn't have a session unless the ID exists" do
|
119
|
-
@res.
|
109
|
+
expect( @res ).to_not have_session()
|
120
110
|
end
|
121
111
|
|
122
112
|
|
@@ -127,49 +117,49 @@ describe Strelka::HTTPResponse::Session, "-extended response" do
|
|
127
117
|
end
|
128
118
|
|
129
119
|
it "knows that it has a session" do
|
130
|
-
@res.
|
120
|
+
expect( @res ).to have_session()
|
131
121
|
end
|
132
122
|
|
133
123
|
it "knows that its session has been loaded if it has one" do
|
134
124
|
@res.session
|
135
|
-
@res.session_loaded
|
125
|
+
expect( @res.session_loaded? ).to be_true()
|
136
126
|
end
|
137
127
|
|
138
128
|
it "knows that its session has been loaded if its request has one" do
|
139
129
|
@res.request.session
|
140
|
-
@res.session_loaded
|
130
|
+
expect( @res.session_loaded? ).to be_true()
|
141
131
|
end
|
142
132
|
|
143
133
|
it "knows that its session hasn't been loaded if neither its request not itself has one" do
|
144
|
-
@res.session_loaded
|
134
|
+
expect( @res.session_loaded? ).to be_false()
|
145
135
|
end
|
146
136
|
|
147
137
|
it "saves the session via itself if it was loaded" do
|
148
|
-
@res.cookies.
|
138
|
+
expect( @res.cookies ).to_not include( @cookie_name )
|
149
139
|
@res.session
|
150
140
|
@res.save_session
|
151
|
-
@res.cookies[ @cookie_name ].value.
|
141
|
+
expect( @res.cookies[ @cookie_name ].value ).to eq( @sess_id )
|
152
142
|
end
|
153
143
|
|
154
144
|
it "doesn't save the session via itself if it wasn't loaded" do
|
155
|
-
@res.cookies.
|
145
|
+
expect( @res.cookies ).to_not include( @cookie_name )
|
156
146
|
@res.save_session
|
157
|
-
@res.cookies.
|
147
|
+
expect( @res.cookies ).to be_empty()
|
158
148
|
end
|
159
149
|
|
160
150
|
it "destroys the session via itself if it was loaded" do
|
161
|
-
@res.cookies.
|
151
|
+
expect( @res.cookies ).to_not include( @cookie_name )
|
162
152
|
@res.session
|
163
153
|
@res.destroy_session
|
164
|
-
@res.cookies[ @cookie_name ].value.
|
165
|
-
@res.cookies[ @cookie_name ].expires.
|
154
|
+
expect( @res.cookies[ @cookie_name ].value ).to eq( @sess_id )
|
155
|
+
expect( @res.cookies[ @cookie_name ].expires ).to be < Time.now
|
166
156
|
end
|
167
157
|
|
168
158
|
it "destroys the session via itself even if it wasn't loaded" do
|
169
|
-
@res.cookies.
|
159
|
+
expect( @res.cookies ).to_not include( @cookie_name )
|
170
160
|
@res.destroy_session
|
171
|
-
@res.cookies[ @cookie_name ].value.
|
172
|
-
@res.cookies[ @cookie_name ].expires.
|
161
|
+
expect( @res.cookies[ @cookie_name ].value ).to eq( @sess_id )
|
162
|
+
expect( @res.cookies[ @cookie_name ].expires ).to be < Time.now
|
173
163
|
end
|
174
164
|
|
175
165
|
end
|