strelka 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -3
  4. data/History.rdoc +19 -0
  5. data/Rakefile +6 -5
  6. data/lib/strelka.rb +2 -2
  7. data/lib/strelka/app.rb +8 -21
  8. data/lib/strelka/app/auth.rb +1 -1
  9. data/lib/strelka/app/restresources.rb +72 -20
  10. data/lib/strelka/app/sessions.rb +6 -4
  11. data/lib/strelka/authprovider.rb +1 -1
  12. data/lib/strelka/cookie.rb +2 -1
  13. data/lib/strelka/httprequest.rb +47 -43
  14. data/lib/strelka/httprequest/acceptparams.rb +3 -3
  15. data/lib/strelka/httprequest/negotiation.rb +4 -0
  16. data/lib/strelka/mixins.rb +27 -28
  17. data/lib/strelka/multipartparser.rb +1 -3
  18. data/lib/strelka/plugins.rb +1 -2
  19. data/lib/strelka/router.rb +2 -2
  20. data/lib/strelka/session.rb +3 -2
  21. data/lib/strelka/session/db.rb +1 -0
  22. data/spec/strelka/app/auth_spec.rb +48 -48
  23. data/spec/strelka/app/filters_spec.rb +8 -8
  24. data/spec/strelka/app/parameters_spec.rb +1 -1
  25. data/spec/strelka/app/restresources_spec.rb +69 -35
  26. data/spec/strelka/app/routing_spec.rb +1 -1
  27. data/spec/strelka/app/templating_spec.rb +1 -1
  28. data/spec/strelka/authprovider/basic_spec.rb +1 -1
  29. data/spec/strelka/authprovider/hostaccess_spec.rb +3 -3
  30. data/spec/strelka/cookie_spec.rb +6 -5
  31. data/spec/strelka/cookieset_spec.rb +1 -1
  32. data/spec/strelka/discovery_spec.rb +2 -2
  33. data/spec/strelka/httprequest/acceptparams_spec.rb +16 -16
  34. data/spec/strelka/httprequest/negotiation_spec.rb +73 -67
  35. data/spec/strelka/httprequest/session_spec.rb +2 -2
  36. data/spec/strelka/httprequest_spec.rb +38 -6
  37. data/spec/strelka/httpresponse/session_spec.rb +3 -3
  38. data/spec/strelka/mixins_spec.rb +3 -3
  39. data/spec/strelka/multipartparser_spec.rb +2 -2
  40. data/spec/strelka/paramvalidator_spec.rb +22 -22
  41. data/spec/strelka/plugins_spec.rb +1 -1
  42. data/spec/strelka/session/default_spec.rb +4 -4
  43. data/spec/strelka/websocketserver/routing_spec.rb +1 -1
  44. metadata +29 -15
  45. metadata.gz.sig +0 -0
@@ -74,7 +74,7 @@ describe Strelka::App::RestResources do
74
74
  end
75
75
 
76
76
  it "keeps track of what resources are mounted where" do
77
- expect( @app.resource_verbs ).to have( 1 ).member
77
+ expect( @app.resource_verbs.size ).to eq( 1 )
78
78
  expect( @app.resource_verbs ).to include( 'servers' )
79
79
  @app.resource_verbs[ 'servers' ].
80
80
  should include( :OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE )
@@ -87,6 +87,7 @@ describe Strelka::App::RestResources do
87
87
 
88
88
  # Writer regular routes
89
89
  it { should have_route(:POST, 'servers') }
90
+ it { should have_route(:POST, 'servers/:id') }
90
91
  it { should have_route(:PUT, 'servers') }
91
92
  it { should have_route(:PUT, 'servers/:id') }
92
93
  it { should have_route(:DELETE, 'servers') }
@@ -111,7 +112,7 @@ describe Strelka::App::RestResources do
111
112
  end
112
113
 
113
114
  it "keeps track of what resources are mounted where" do
114
- expect( @app.resource_verbs ).to have( 1 ).member
115
+ expect( @app.resource_verbs.size ).to eq( 1 )
115
116
  expect( @app.resource_verbs ).to include( 'servers' )
116
117
  @app.resource_verbs[ 'servers' ].
117
118
  should include( :OPTIONS, :GET, :HEAD )
@@ -126,6 +127,7 @@ describe Strelka::App::RestResources do
126
127
 
127
128
  # Writer regular routes
128
129
  it { should_not have_route(:POST, 'servers') }
130
+ it { should_not have_route(:POST, 'servers/:id') }
129
131
  it { should_not have_route(:PUT, 'servers') }
130
132
  it { should_not have_route(:PUT, 'servers/:id') }
131
133
  it { should_not have_route(:DELETE, 'servers') }
@@ -191,7 +193,7 @@ describe Strelka::App::RestResources do
191
193
  expect( res.content_type ).to eq( 'application/json' )
192
194
  body = Yajl.load( res.body )
193
195
 
194
- expect( body ).to have( 2 ).members
196
+ expect( body.size ).to eq( 2 )
195
197
  expect( body.map {|record| record['uuid'] } ).to include( 'test-server', 'step-server' )
196
198
  end
197
199
 
@@ -204,7 +206,7 @@ describe Strelka::App::RestResources do
204
206
  expect( res.content_type ).to eq( 'application/json' )
205
207
  body = Yajl.load( res.body )
206
208
 
207
- expect( body ).to have( 1 ).member
209
+ expect( body.size ).to eq( 1 )
208
210
  expect( body[0]['uuid'] ).to eq( 'test-server' )
209
211
  end
210
212
 
@@ -217,7 +219,7 @@ describe Strelka::App::RestResources do
217
219
  expect( res.content_type ).to eq( 'application/json' )
218
220
  body = Yajl.load( res.body )
219
221
 
220
- expect( body ).to have( 1 ).member
222
+ expect( body.size ).to eq( 1 )
221
223
  expect( body[0]['uuid'] ).to eq( 'step-server' )
222
224
  end
223
225
 
@@ -230,7 +232,7 @@ describe Strelka::App::RestResources do
230
232
  expect( res.content_type ).to eq( 'application/json' )
231
233
  body = Yajl.load( res.body )
232
234
 
233
- expect( body ).to have( 2 ).members
235
+ expect( body.size ).to eq( 2 )
234
236
  expect( body[0]['name'] ).to eq( 'Step' )
235
237
  end
236
238
 
@@ -243,7 +245,7 @@ describe Strelka::App::RestResources do
243
245
  expect( res.content_type ).to eq( 'application/json' )
244
246
  body = Yajl.load( res.body )
245
247
 
246
- expect( body ).to have( 2 ).members
248
+ expect( body.size ).to eq( 2 )
247
249
  expect( body[0]['name'] ).to eq( 'Test' )
248
250
  end
249
251
 
@@ -285,7 +287,7 @@ describe Strelka::App::RestResources do
285
287
  body = Yajl.load( res.body )
286
288
 
287
289
  expect( body ).to be_an( Array )
288
- expect( body ).to have( 1 ).member
290
+ expect( body.size ).to eq( 1 )
289
291
  expect( body.first ).to be_a( Hash )
290
292
  expect( body.first['uuid'] ).to eq( 'test-server' )
291
293
  end
@@ -299,7 +301,7 @@ describe Strelka::App::RestResources do
299
301
  body = Yajl.load( res.body )
300
302
 
301
303
  expect( body ).to be_an( Array )
302
- expect( body ).to have( 1 ).member
304
+ expect( body.size ).to eq( 1 )
303
305
  expect( body.first ).to be_a( Hash )
304
306
  expect( body.first['port'] ).to be > 1024
305
307
  end
@@ -313,7 +315,7 @@ describe Strelka::App::RestResources do
313
315
  body = Yajl.load( res.body )
314
316
 
315
317
  expect( body ).to be_an( Array )
316
- expect( body ).to have( 1 ).member
318
+ expect( body.size ).to eq( 1 )
317
319
  expect( body.first ).to be_a( Hash )
318
320
  expect( body.first['name'] ).to eq( 'Step' )
319
321
  end
@@ -327,7 +329,7 @@ describe Strelka::App::RestResources do
327
329
  body = Yajl.load( res.body )
328
330
 
329
331
  expect( body ).to be_an( Array )
330
- expect( body ).to have( 4 ).members
332
+ expect( body.size ).to eq( 4 )
331
333
  expect( body.first ).to be_a( Hash )
332
334
  expect( body.first['server_id'] ).to eq( 1 )
333
335
  expect( body.first['id'] ).to eq( 1 )
@@ -341,7 +343,7 @@ describe Strelka::App::RestResources do
341
343
  body = Yajl.load( res.body )
342
344
 
343
345
  expect( body ).to be_an( Array )
344
- expect( body ).to have( 2 ).members
346
+ expect( body.size ).to eq( 2 )
345
347
  expect( body.first ).to be_a( Hash )
346
348
  expect( body.first['server_id'] ).to eq( 1 )
347
349
  expect( body.first['id'] ).to eq( 3 )
@@ -350,7 +352,7 @@ describe Strelka::App::RestResources do
350
352
  end # GET routes
351
353
 
352
354
 
353
- context "POST route" do
355
+ context "POST routes" do
354
356
 
355
357
  before( :each ) do
356
358
  @server_values = {
@@ -395,52 +397,83 @@ describe Strelka::App::RestResources do
395
397
  expect( new_server.use_ssl ).to eq( 0 )
396
398
  end
397
399
 
398
- it "has a POST route to update instances"
399
-
400
- end # POST routes
400
+ it "has a POST route to update a single resource" do
401
+ server = Mongrel2::Config::Server.create( @server_values )
401
402
 
403
+ req = @request_factory.post( "/api/v1/servers/#{server.id}" )
404
+ req.content_type = 'application/json'
405
+ req.body = Yajl.dump({ 'name' => 'Staging Server' })
402
406
 
403
- context "PUT route" do
407
+ res = @app.new.handle( req )
408
+ server.refresh
404
409
 
405
- before( :each ) do
406
- @posted_values = {
407
- 'name' => 'Not A Testing Server',
408
- 'bind_addr' => '0.0.0.0',
409
- }
410
+ expect( res.status ).to eq( HTTP::NO_CONTENT )
411
+ expect( server.name ).to eq( 'Staging Server' )
412
+ expect( server.uuid ).to eq( @server_values['uuid'] )
410
413
  end
411
414
 
415
+ it "ignores attributes that aren't in the allowed columns list"
416
+
417
+ end # POST routes
418
+
419
+
420
+ context "PUT routes" do
421
+
412
422
  it "has a PUT route to replace instances in the resource collection" do
413
423
  req = @request_factory.put( '/api/v1/servers/1' )
414
424
  req.content_type = 'application/json'
415
425
  req.headers.accept = 'application/json'
416
- req.body = Yajl.dump( @posted_values )
426
+ req.body = Yajl.dump({
427
+ 'name' => 'Staging',
428
+ 'uuid' => 'staging',
429
+ 'access_log' => "/logs/staging-access.log",
430
+ 'error_log' => "/logs/staging-error.log",
431
+ 'chroot' => "",
432
+ 'pid_file' => "/var/run/staging.pid",
433
+ 'default_host' => "staging.local",
434
+ 'port' => '6455',
435
+ })
417
436
 
418
437
  res = @app.new.handle( req )
419
438
 
420
439
  expect( res.status ).to eq( HTTP::NO_CONTENT )
421
440
 
422
- expect( Mongrel2::Config::Server[ 1 ].name ).to eq( 'Not A Testing Server' )
423
- expect( Mongrel2::Config::Server[ 1 ].bind_addr ).to eq( '0.0.0.0' )
441
+ server = Mongrel2::Config::Server[1]
442
+ expect( server.name ).to eq( 'Staging' )
443
+ expect( server.bind_addr ).to eq( '0.0.0.0' )
444
+ expect( server.uuid ).to eq( 'staging' )
424
445
  end
425
446
 
426
447
  it "has a PUT route to replace all resources in a collection" do
427
- pending "fix the semantics of PUT and POST" do
428
- req = @request_factory.put( '/api/v1/servers' )
429
- req.content_type = 'application/json'
430
- req.body = Yajl.dump({ 'bind_addr' => '0.0.0.0' })
448
+ req = @request_factory.put( '/api/v1/servers' )
449
+ req.content_type = 'application/json'
450
+ req.body = Yajl.dump([
451
+ {
452
+ 'name' => 'Staging Server',
453
+ 'uuid' => 'staging',
454
+ 'access_log' => "/logs/staging-access.log",
455
+ 'error_log' => "/logs/staging-error.log",
456
+ 'chroot' => "",
457
+ 'pid_file' => "/var/run/staging.pid",
458
+ 'default_host' => "staging.local",
459
+ 'port' => '6455',
460
+ }
461
+ ])
431
462
 
432
- res = @app.new.handle( req )
463
+ res = @app.new.handle( req )
433
464
 
434
- expect( res.status ).to eq( HTTP::NO_CONTENT )
465
+ expect( res.status ).to eq( HTTP::NO_CONTENT )
435
466
 
436
- expect( Mongrel2::Config::Server.map( :bind_addr ) ).to eq( ['0.0.0.0'] )
437
- end
467
+ expect( Mongrel2::Config::Server.count ).to eq( 1 )
468
+ server = Mongrel2::Config::Server.first
469
+ expect( server.name ).to eq( 'Staging Server' )
470
+ expect( server.uuid ).to eq( 'staging' )
438
471
  end
439
472
 
440
473
  end # PUT routes
441
474
 
442
475
 
443
- context "DELETE route" do
476
+ context "DELETE routes" do
444
477
 
445
478
  it "has a DELETE route to delete single instances in the resource collection" do
446
479
  req = @request_factory.delete( '/api/v1/servers/1' )
@@ -449,6 +482,7 @@ describe Strelka::App::RestResources do
449
482
 
450
483
  expect( res.status ).to eq( HTTP::NO_CONTENT )
451
484
 
485
+ expect( Mongrel2::Config::Server[1] ).to be_nil
452
486
  expect( Mongrel2::Config::Server.count ).to eq( 1 )
453
487
  end
454
488
 
@@ -481,7 +515,7 @@ describe Strelka::App::RestResources do
481
515
  end
482
516
 
483
517
  it "has its metadata inherited by subclasses" do
484
- expect( subject.resource_verbs ).to have( 1 ).member
518
+ expect( subject.resource_verbs.size ).to eq( 1 )
485
519
  expect( subject.resource_verbs ).to include( 'servers' )
486
520
  subject.resource_verbs[ 'servers' ].
487
521
  should include( :OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE )
@@ -214,7 +214,7 @@ describe Strelka::App::Routing do
214
214
  get( '/origami' ) {}
215
215
  end
216
216
 
217
- expect( subclass.routes ).to have( 3 ).members
217
+ expect( subclass.routes.size ).to eq( 3 )
218
218
 
219
219
  subclass.routes.
220
220
  should include([ :GET, ['info'], {action: @app.instance_method(:GET_info), options: {}} ])
@@ -69,7 +69,7 @@ describe Strelka::App::Templating do
69
69
 
70
70
  template_dirs = described_class.discover_template_dirs
71
71
 
72
- expect( template_dirs ).to have( 3 ).pathnames
72
+ expect( template_dirs.size ).to eq( 3 )
73
73
  expect( template_dirs ).to include(
74
74
  Pathname("data/foom/templates"),
75
75
  Pathname("#{javelin_path}/data/javelin/templates"),
@@ -165,7 +165,7 @@ describe Strelka::AuthProvider::Basic do
165
165
  req = @request_factory.get( '/admin/console' )
166
166
  req.header.authorization = make_authorization_header( 'lessa', 'ramoth' )
167
167
 
168
- expect( @provider.authenticate(req) ).to be_true()
168
+ expect( @provider.authenticate(req) ).to be_truthy()
169
169
  end
170
170
  end
171
171
 
@@ -38,7 +38,7 @@ describe Strelka::AuthProvider::HostAccess do
38
38
 
39
39
  it "allows its netblocks to be set" do
40
40
  @provider.allowed_netblocks = %w[10.5.2.0/22 10.6.2.0/24]
41
- expect( @provider.allowed_netblocks ).to have( 2 ).members
41
+ expect( @provider.allowed_netblocks.size ).to eq( 2 )
42
42
  expect( @provider.allowed_netblocks ).to include( IPAddr.new('10.5.2.0/22'), IPAddr.new('10.6.2.0/24') )
43
43
  end
44
44
 
@@ -50,13 +50,13 @@ describe Strelka::AuthProvider::HostAccess do
50
50
 
51
51
  it "allows a request that originates from one of its allowed netblocks" do
52
52
  req = @request_factory.get( '/admin/console', :x_forwarded_for => '127.0.0.1' )
53
- expect( @provider.authorize( nil, req, nil ) ).to be_true()
53
+ expect( @provider.authorize( nil, req, nil ) ).to be_truthy()
54
54
  end
55
55
 
56
56
 
57
57
  it "doesn't allow a request which is not from one of its allowed netblocks" do
58
58
  req = @request_factory.get( '/admin/console', :x_forwarded_for => '8.8.8.8' )
59
- expect( @provider.authorize( nil, req, nil ) ).to be_false()
59
+ expect( @provider.authorize( nil, req, nil ) ).to be_falsey()
60
60
  end
61
61
 
62
62
 
@@ -35,7 +35,7 @@ describe Strelka::Cookie do
35
35
  result = Strelka::Cookie.parse( 'a=b' )
36
36
 
37
37
  expect( result ).to be_a( Hash )
38
- expect( result ).to have(1).member
38
+ expect( result.size ).to eq( 1 )
39
39
  expect( result[:a] ).to be_a( Strelka::Cookie )
40
40
  expect( result[:a].name ).to eq( 'a' )
41
41
  expect( result[:a].value ).to eq( 'b' )
@@ -44,15 +44,16 @@ describe Strelka::Cookie do
44
44
  it "parses a cookie header field with an empty value as a cookie with a nil value" do
45
45
  result = Strelka::Cookie.parse( 'a=' )
46
46
 
47
- expect( result ).to have( 1 ).member
47
+ expect( result.size ).to eq( 1 )
48
48
  expect( result[:a] ).to be_a( Strelka::Cookie )
49
49
  expect( result[:a].name ).to eq( 'a' )
50
50
  expect( result[:a].value ).to be_nil()
51
51
  end
52
52
 
53
- it "doesn't raise an error if asked to parse an invalid cookie header" do
54
- result = Strelka::Cookie.parse( "{a}=foo" )
55
- expect( result ).to eq( {} )
53
+ it "raises an error if asked to parse an invalid cookie header" do
54
+ expect {
55
+ Strelka::Cookie.parse( "{a}=foo" )
56
+ }.to raise_error( Strelka::ParseError, /malformed/i )
56
57
  end
57
58
 
58
59
  it "guards against a nil options hash" do
@@ -26,7 +26,7 @@ describe Strelka::CookieSet do
26
26
 
27
27
  expect( @cookieset ).to be_empty()
28
28
  expect( @cookieset.length ).to eq( 0 )
29
- expect( @cookieset.member?( cookie ) ).to be_false()
29
+ expect( @cookieset.member?( cookie ) ).to be_falsey()
30
30
  end
31
31
 
32
32
  it "is able to enummerate over each cookie in the set" do
@@ -87,7 +87,7 @@ describe Strelka::Discovery do
87
87
 
88
88
  app_paths = described_class.discover_paths
89
89
 
90
- expect( app_paths ).to have( 4 ).members
90
+ expect( app_paths.size ).to eq( 4 )
91
91
  expect( app_paths ).to include(
92
92
  'donkey' => [Pathname("#{donkey_path}/data/donkey/apps/app.rb")],
93
93
  'rabbit' => [Pathname("#{rabbit_path}/data/rabbit/apps/subdir/app1.rb"),
@@ -115,7 +115,7 @@ describe Strelka::Discovery do
115
115
  end
116
116
 
117
117
  app_classes = described_class.discover
118
- expect( app_classes ).to have( 1 ).member
118
+ expect( app_classes.size ).to eq( 1 )
119
119
  expect( app_classes.first ).to be_a( Class )
120
120
  expect( app_classes.first ).to be < discoverable_class
121
121
  end
@@ -136,12 +136,12 @@ describe Strelka::HTTPRequest, "accept params" do
136
136
  specific_param = Strelka::HTTPRequest::MediaType.parse( 'text/html' )
137
137
  subtype_wildcard_param = Strelka::HTTPRequest::MediaType.parse( 'image/*' )
138
138
 
139
- expect( ( specific_param =~ 'text/html' ) ).to be_true()
140
- expect( ( specific_param =~ 'image/png' ) ).to be_false()
139
+ expect( ( specific_param =~ 'text/html' ) ).to be_truthy()
140
+ expect( ( specific_param =~ 'image/png' ) ).to be_falsey()
141
141
 
142
- expect( ( subtype_wildcard_param =~ 'image/png' ) ).to be_true()
143
- expect( ( subtype_wildcard_param =~ 'image/jpeg' ) ).to be_true()
144
- expect( ( subtype_wildcard_param =~ 'text/plain' ) ).to be_false()
142
+ expect( ( subtype_wildcard_param =~ 'image/png' ) ).to be_truthy()
143
+ expect( ( subtype_wildcard_param =~ 'image/jpeg' ) ).to be_truthy()
144
+ expect( ( subtype_wildcard_param =~ 'text/plain' ) ).to be_falsey()
145
145
  end
146
146
  end
147
147
 
@@ -217,17 +217,17 @@ describe Strelka::HTTPRequest, "accept params" do
217
217
  it "can be compared against strings" do
218
218
  specific_param = Strelka::HTTPRequest::Charset.parse( 'us-ascii' )
219
219
 
220
- expect( ( specific_param =~ 'us-ascii' ) ).to be_true()
221
- expect( ( specific_param =~ 'ansi_x3.4-1968' ) ).to be_true()
222
- expect( ( specific_param =~ 'utf-8' ) ).to be_false()
220
+ expect( ( specific_param =~ 'us-ascii' ) ).to be_truthy()
221
+ expect( ( specific_param =~ 'ansi_x3.4-1968' ) ).to be_truthy()
222
+ expect( ( specific_param =~ 'utf-8' ) ).to be_falsey()
223
223
  end
224
224
 
225
225
  it "can be compared against Encoding objects" do
226
226
  specific_param = Strelka::HTTPRequest::Charset.parse( 'utf-8' )
227
227
 
228
- expect( ( specific_param =~ Encoding::UTF_8 ) ).to be_true()
229
- expect( ( specific_param =~ Encoding::CP65001 ) ).to be_true()
230
- expect( ( specific_param =~ Encoding::MacThai ) ).to be_false()
228
+ expect( ( specific_param =~ Encoding::UTF_8 ) ).to be_truthy()
229
+ expect( ( specific_param =~ Encoding::CP65001 ) ).to be_truthy()
230
+ expect( ( specific_param =~ Encoding::MacThai ) ).to be_falsey()
231
231
  end
232
232
  end
233
233
 
@@ -260,12 +260,12 @@ describe Strelka::HTTPRequest, "accept params" do
260
260
  specific_param = Strelka::HTTPRequest::MediaType.parse( 'text/html' )
261
261
  subtype_wildcard_param = Strelka::HTTPRequest::MediaType.parse( 'image/*' )
262
262
 
263
- expect( ( specific_param =~ 'text/html' ) ).to be_true()
264
- expect( ( specific_param =~ 'image/png' ) ).to be_false()
263
+ expect( ( specific_param =~ 'text/html' ) ).to be_truthy()
264
+ expect( ( specific_param =~ 'image/png' ) ).to be_falsey()
265
265
 
266
- expect( ( subtype_wildcard_param =~ 'image/png' ) ).to be_true()
267
- expect( ( subtype_wildcard_param =~ 'image/jpeg' ) ).to be_true()
268
- expect( ( subtype_wildcard_param =~ 'text/plain' ) ).to be_false()
266
+ expect( ( subtype_wildcard_param =~ 'image/png' ) ).to be_truthy()
267
+ expect( ( subtype_wildcard_param =~ 'image/jpeg' ) ).to be_truthy()
268
+ expect( ( subtype_wildcard_param =~ 'text/plain' ) ).to be_falsey()
269
269
  end
270
270
  end
271
271
 
@@ -38,7 +38,7 @@ describe Strelka::HTTPRequest::Negotiation do
38
38
  it "know what content-types are accepted by the client" do
39
39
  @req.headers.accept = 'application/x-yaml, application/json; q=0.2, text/xml; q=0.75'
40
40
 
41
- expect( @req.accepted_types ).to have(3).members
41
+ expect( @req.accepted_types.size ).to eq( 3 )
42
42
  expect( @req.accepted_types[0].mediatype ).to eq( 'application/x-yaml' )
43
43
  expect( @req.accepted_types[0].qvalue ).to eq( 1.0 )
44
44
  expect( @req.accepted_types[1].mediatype ).to eq( 'application/json' )
@@ -50,41 +50,47 @@ describe Strelka::HTTPRequest::Negotiation do
50
50
  it "knows what mimetypes are acceptable responses" do
51
51
  @req.headers.accept = 'text/html, text/plain; q=0.5, image/*;q=0.1'
52
52
 
53
- expect( @req.accepts?( 'text/html' ) ).to be_true()
54
- expect( @req.accepts?( 'text/plain' ) ).to be_true()
55
- expect( @req.accepts?( 'text/ascii' ) ).to be_false()
56
- expect( @req.accepts?( 'image/png' ) ).to be_true()
57
- expect( @req.accepts?( 'application/x-yaml' ) ).to be_false()
53
+ expect( @req.accepts?( 'text/html' ) ).to be_truthy()
54
+ expect( @req.accepts?( 'text/plain' ) ).to be_truthy()
55
+ expect( @req.accepts?( 'text/ascii' ) ).to be_falsey()
56
+ expect( @req.accepts?( 'image/png' ) ).to be_truthy()
57
+ expect( @req.accepts?( 'application/x-yaml' ) ).to be_falsey()
58
58
  end
59
59
 
60
60
  it "knows what mimetypes are explicitly acceptable responses" do
61
61
  @req.headers.accept = 'text/html, text/plain; q=0.5, image/*;q=0.1, */*'
62
62
 
63
- expect( @req.explicitly_accepts?( 'text/html' ) ).to be_true()
64
- expect( @req.explicitly_accepts?( 'text/plain' ) ).to be_true()
65
- expect( @req.explicitly_accepts?( 'text/ascii' ) ).to be_false()
66
- expect( @req.explicitly_accepts?( 'image/png' ) ).to be_false()
67
- expect( @req.explicitly_accepts?( 'application/x-yaml' ) ).to be_false()
63
+ expect( @req.explicitly_accepts?( 'text/html' ) ).to be_truthy()
64
+ expect( @req.explicitly_accepts?( 'text/plain' ) ).to be_truthy()
65
+ expect( @req.explicitly_accepts?( 'text/ascii' ) ).to be_falsey()
66
+ expect( @req.explicitly_accepts?( 'image/png' ) ).to be_falsey()
67
+ expect( @req.explicitly_accepts?( 'application/x-yaml' ) ).to be_falsey()
68
68
  end
69
69
 
70
70
  it "accepts anything if the client doesn't provide an Accept header" do
71
71
  @req.headers.delete( :accept )
72
72
 
73
- expect( @req.accepts?( 'text/html' ) ).to be_true()
74
- expect( @req.accepts?( 'text/plain' ) ).to be_true()
75
- expect( @req.accepts?( 'text/ascii' ) ).to be_true()
76
- expect( @req.accepts?( 'image/png' ) ).to be_true()
77
- expect( @req.accepts?( 'application/x-yaml' ) ).to be_true()
73
+ expect( @req.accepts?( 'text/html' ) ).to be_truthy()
74
+ expect( @req.accepts?( 'text/plain' ) ).to be_truthy()
75
+ expect( @req.accepts?( 'text/ascii' ) ).to be_truthy()
76
+ expect( @req.accepts?( 'image/png' ) ).to be_truthy()
77
+ expect( @req.accepts?( 'application/x-yaml' ) ).to be_truthy()
78
78
  end
79
79
 
80
80
  it "doesn't explicitly accept anything if the client doesn't provide an Accept header" do
81
81
  @req.headers.delete( :accept )
82
82
 
83
- expect( @req.explicitly_accepts?( 'text/html' ) ).to be_false()
84
- expect( @req.explicitly_accepts?( 'text/plain' ) ).to be_false()
85
- expect( @req.explicitly_accepts?( 'text/ascii' ) ).to be_false()
86
- expect( @req.explicitly_accepts?( 'image/png' ) ).to be_false()
87
- expect( @req.explicitly_accepts?( 'application/x-yaml' ) ).to be_false()
83
+ expect( @req.explicitly_accepts?( 'text/html' ) ).to be_falsey()
84
+ expect( @req.explicitly_accepts?( 'text/plain' ) ).to be_falsey()
85
+ expect( @req.explicitly_accepts?( 'text/ascii' ) ).to be_falsey()
86
+ expect( @req.explicitly_accepts?( 'image/png' ) ).to be_falsey()
87
+ expect( @req.explicitly_accepts?( 'application/x-yaml' ) ).to be_falsey()
88
+ end
89
+
90
+ it "finishes with a BAD REQUEST response if the Accept header is malformed" do
91
+ @req.headers.accept = 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2'
92
+
93
+ expect { @req.accepted_types }.to finish_with( HTTP::BAD_REQUEST, /malformed/i )
88
94
  end
89
95
 
90
96
  end
@@ -95,7 +101,7 @@ describe Strelka::HTTPRequest::Negotiation do
95
101
  it "knows what character sets are accepted by the client" do
96
102
  @req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
97
103
 
98
- expect( @req.accepted_charsets ).to have(2).members
104
+ expect( @req.accepted_charsets.size ).to eq( 2 )
99
105
  expect( @req.accepted_charsets[0].name ).to eq( 'iso-8859-5' )
100
106
  expect( @req.accepted_charsets[0].qvalue ).to eq( 1.0 )
101
107
  expect( @req.accepted_charsets[1].name ).to eq( 'utf-8' )
@@ -105,23 +111,23 @@ describe Strelka::HTTPRequest::Negotiation do
105
111
  it "knows what charsets are acceptable responses" do
106
112
  @req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
107
113
 
108
- expect( @req.accepts_charset?( 'iso8859-5' ) ).to be_true()
109
- expect( @req.accepts_charset?( 'iso-8859-5' ) ).to be_true()
110
- expect( @req.accepts_charset?( 'utf-8' ) ).to be_true()
111
- expect( @req.accepts_charset?( Encoding::CP65001 ) ).to be_true()
112
- expect( @req.accepts_charset?( 'mac' ) ).to be_false()
113
- expect( @req.accepts_charset?( Encoding::SJIS ) ).to be_false()
114
+ expect( @req.accepts_charset?( 'iso8859-5' ) ).to be_truthy()
115
+ expect( @req.accepts_charset?( 'iso-8859-5' ) ).to be_truthy()
116
+ expect( @req.accepts_charset?( 'utf-8' ) ).to be_truthy()
117
+ expect( @req.accepts_charset?( Encoding::CP65001 ) ).to be_truthy()
118
+ expect( @req.accepts_charset?( 'mac' ) ).to be_falsey()
119
+ expect( @req.accepts_charset?( Encoding::SJIS ) ).to be_falsey()
114
120
  end
115
121
 
116
122
  it "accepts any charset if the client doesn't provide an Accept-Charset header" do
117
123
  @req.headers.delete( :accept_charset )
118
124
 
119
- expect( @req.accepts_charset?( 'iso8859-5' ) ).to be_true()
120
- expect( @req.accepts_charset?( 'iso-8859-5' ) ).to be_true()
121
- expect( @req.accepts_charset?( 'utf-8' ) ).to be_true()
122
- expect( @req.accepts_charset?( Encoding::CP65001 ) ).to be_true()
123
- expect( @req.accepts_charset?( 'mac' ) ).to be_true()
124
- expect( @req.accepts_charset?( Encoding::SJIS ) ).to be_true()
125
+ expect( @req.accepts_charset?( 'iso8859-5' ) ).to be_truthy()
126
+ expect( @req.accepts_charset?( 'iso-8859-5' ) ).to be_truthy()
127
+ expect( @req.accepts_charset?( 'utf-8' ) ).to be_truthy()
128
+ expect( @req.accepts_charset?( Encoding::CP65001 ) ).to be_truthy()
129
+ expect( @req.accepts_charset?( 'mac' ) ).to be_truthy()
130
+ expect( @req.accepts_charset?( Encoding::SJIS ) ).to be_truthy()
125
131
  end
126
132
 
127
133
  end
@@ -132,7 +138,7 @@ describe Strelka::HTTPRequest::Negotiation do
132
138
  it "knows what encodings are accepted by the client" do
133
139
  @req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0.5, *;q=0'
134
140
 
135
- expect( @req.accepted_encodings ).to have(3).members
141
+ expect( @req.accepted_encodings.size ).to eq( 3 )
136
142
  expect( @req.accepted_encodings[0].content_coding ).to eq( 'gzip' )
137
143
  expect( @req.accepted_encodings[0].qvalue ).to eq( 1.0 )
138
144
  expect( @req.accepted_encodings[1].content_coding ).to eq( 'identity' )
@@ -144,51 +150,51 @@ describe Strelka::HTTPRequest::Negotiation do
144
150
  it "knows what encodings are acceptable" do
145
151
  @req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0.5, *;q=0'
146
152
 
147
- expect( @req.accepts_encoding?( 'gzip' ) ).to be_true()
148
- expect( @req.accepts_encoding?( 'identity' ) ).to be_true()
149
- expect( @req.accepts_encoding?( 'compress' ) ).to be_false()
153
+ expect( @req.accepts_encoding?( 'gzip' ) ).to be_truthy()
154
+ expect( @req.accepts_encoding?( 'identity' ) ).to be_truthy()
155
+ expect( @req.accepts_encoding?( 'compress' ) ).to be_falsey()
150
156
  end
151
157
 
152
158
  it "knows that the identity encoding is acceptable if it isn't disabled" do
153
159
  @req.headers.accept_encoding = 'gzip;q=1.0, compress; q=0.5'
154
160
 
155
- expect( @req.accepts_encoding?( 'gzip' ) ).to be_true()
156
- expect( @req.accepts_encoding?( 'identity' ) ).to be_true()
157
- expect( @req.accepts_encoding?( 'compress' ) ).to be_true()
158
- expect( @req.accepts_encoding?( 'clowns' ) ).to be_false()
161
+ expect( @req.accepts_encoding?( 'gzip' ) ).to be_truthy()
162
+ expect( @req.accepts_encoding?( 'identity' ) ).to be_truthy()
163
+ expect( @req.accepts_encoding?( 'compress' ) ).to be_truthy()
164
+ expect( @req.accepts_encoding?( 'clowns' ) ).to be_falsey()
159
165
  end
160
166
 
161
167
  it "accepts only the 'identity' encoding if the Accept-Encoding field is empty" do
162
168
  @req.headers.accept_encoding = ''
163
169
 
164
- expect( @req.accepts_encoding?( 'identity' ) ).to be_true()
165
- expect( @req.accepts_encoding?( 'gzip' ) ).to be_false()
166
- expect( @req.accepts_encoding?( 'compress' ) ).to be_false()
170
+ expect( @req.accepts_encoding?( 'identity' ) ).to be_truthy()
171
+ expect( @req.accepts_encoding?( 'gzip' ) ).to be_falsey()
172
+ expect( @req.accepts_encoding?( 'compress' ) ).to be_falsey()
167
173
  end
168
174
 
169
175
  it "doesn't accept the 'identity' encoding if the Accept-Encoding field explicitly disables it" do
170
176
  @req.headers.accept_encoding = 'gzip;q=0.5, identity;q=0'
171
177
 
172
- expect( @req.accepts_encoding?( 'identity' ) ).to be_false()
173
- expect( @req.accepts_encoding?( 'gzip' ) ).to be_true()
174
- expect( @req.accepts_encoding?( 'compress' ) ).to be_false()
178
+ expect( @req.accepts_encoding?( 'identity' ) ).to be_falsey()
179
+ expect( @req.accepts_encoding?( 'gzip' ) ).to be_truthy()
180
+ expect( @req.accepts_encoding?( 'compress' ) ).to be_falsey()
175
181
  end
176
182
 
177
183
  it "doesn't accept the 'identity' encoding if the Accept-Encoding field has a wildcard " +
178
184
  "with q-value of 0 and doesn't explicitly include 'identity'" do
179
185
  @req.headers.accept_encoding = 'gzip;q=0.5, *;q=0'
180
186
 
181
- expect( @req.accepts_encoding?( 'identity' ) ).to be_false()
182
- expect( @req.accepts_encoding?( 'gzip' ) ).to be_true()
183
- expect( @req.accepts_encoding?( 'compress' ) ).to be_false()
187
+ expect( @req.accepts_encoding?( 'identity' ) ).to be_falsey()
188
+ expect( @req.accepts_encoding?( 'gzip' ) ).to be_truthy()
189
+ expect( @req.accepts_encoding?( 'compress' ) ).to be_falsey()
184
190
  end
185
191
 
186
192
  it "accepts every encoding if the request doesn't have an Accept-Encoding header" do
187
193
  @req.headers.delete( :accept_encoding )
188
194
 
189
- expect( @req.accepts_encoding?( 'identity' ) ).to be_true()
190
- expect( @req.accepts_encoding?( 'gzip' ) ).to be_true()
191
- expect( @req.accepts_encoding?( 'compress' ) ).to be_true()
195
+ expect( @req.accepts_encoding?( 'identity' ) ).to be_truthy()
196
+ expect( @req.accepts_encoding?( 'gzip' ) ).to be_truthy()
197
+ expect( @req.accepts_encoding?( 'compress' ) ).to be_truthy()
192
198
  end
193
199
 
194
200
  end
@@ -199,7 +205,7 @@ describe Strelka::HTTPRequest::Negotiation do
199
205
  it "knows what languages are accepted by the client" do
200
206
  @req.headers.accept_language = 'da, en-gb;q=0.8, en;q=0.7'
201
207
 
202
- expect( @req.accepted_languages ).to have(3).members
208
+ expect( @req.accepted_languages.size ).to eq( 3 )
203
209
  expect( @req.accepted_languages[0].primary_tag ).to eq( 'da' )
204
210
  expect( @req.accepted_languages[0].subtag ).to eq( nil )
205
211
  expect( @req.accepted_languages[0].qvalue ).to eq( 1.0 )
@@ -214,23 +220,23 @@ describe Strelka::HTTPRequest::Negotiation do
214
220
  it "knows what languages may be used in acceptable responses" do
215
221
  @req.headers.accept_language = 'da, en-gb;q=0.8, en;q=0.7'
216
222
 
217
- expect( @req.accepts_language?( 'da' ) ).to be_true()
218
- expect( @req.accepts_language?( 'en' ) ).to be_true()
219
- expect( @req.accepts_language?( 'en-gb' ) ).to be_true()
220
- expect( @req.accepts_language?( 'en-cockney' ) ).to be_true()
221
- expect( @req.accepts_language?( 'de' ) ).to be_false()
222
- expect( @req.accepts_language?( 'tlh' ) ).to be_false()
223
+ expect( @req.accepts_language?( 'da' ) ).to be_truthy()
224
+ expect( @req.accepts_language?( 'en' ) ).to be_truthy()
225
+ expect( @req.accepts_language?( 'en-gb' ) ).to be_truthy()
226
+ expect( @req.accepts_language?( 'en-cockney' ) ).to be_truthy()
227
+ expect( @req.accepts_language?( 'de' ) ).to be_falsey()
228
+ expect( @req.accepts_language?( 'tlh' ) ).to be_falsey()
223
229
  end
224
230
 
225
231
  it "accepts any language if the client doesn't provide an Accept-Language header" do
226
232
  @req.headers.delete( :accept_language )
227
233
 
228
- expect( @req.accepts_language?( 'da' ) ).to be_true()
229
- expect( @req.accepts_language?( 'en' ) ).to be_true()
230
- expect( @req.accepts_language?( 'en-gb' ) ).to be_true()
231
- expect( @req.accepts_language?( 'en-cockney' ) ).to be_true()
232
- expect( @req.accepts_language?( 'de' ) ).to be_true()
233
- expect( @req.accepts_language?( 'tlh' ) ).to be_true()
234
+ expect( @req.accepts_language?( 'da' ) ).to be_truthy()
235
+ expect( @req.accepts_language?( 'en' ) ).to be_truthy()
236
+ expect( @req.accepts_language?( 'en-gb' ) ).to be_truthy()
237
+ expect( @req.accepts_language?( 'en-cockney' ) ).to be_truthy()
238
+ expect( @req.accepts_language?( 'de' ) ).to be_truthy()
239
+ expect( @req.accepts_language?( 'tlh' ) ).to be_truthy()
234
240
  end
235
241
 
236
242
  end