useless 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/useless.rb +11 -1
- data/lib/useless/rack.rb +18 -26
- data/lib/useless/rack/authentication/access_token.rb +39 -0
- data/lib/useless/rack/authentication/query_string.rb +19 -0
- data/lib/useless/rack/authentication/request_header.rb +19 -0
- data/lib/useless/rack/exceptions.rb +28 -0
- data/lib/useless/rack/files.rb +37 -0
- data/lib/useless/rack/fs.rb +17 -0
- data/lib/useless/rack/mongo.rb +16 -0
- data/lib/useless/version.rb +1 -1
- data/spec/spec_helper.rb +4 -3
- data/spec/useless/fs_spec.rb +1 -0
- data/spec/useless/mongo_spec.rb +1 -0
- data/spec/useless/rack/{middleware/authentication → authentication}/query_string_spec.rb +8 -7
- data/spec/useless/rack/{middleware/authentication → authentication}/request_header_spec.rb +8 -7
- data/spec/useless/rack/exceptions_spec.rb +31 -0
- data/spec/useless/rack/files_spec.rb +49 -0
- data/spec/useless/rack/fs_spec.rb +18 -0
- data/spec/useless/rack/mongo_spec.rb +18 -0
- data/spec/useless/rack_spec.rb +77 -0
- data/useless.gemspec +7 -7
- metadata +49 -50
- data/assets/DOC.html +0 -39
- data/assets/application.css +0 -134
- data/lib/useless/logger.rb +0 -48
- data/lib/useless/rack/base.rb +0 -26
- data/lib/useless/rack/base/files.rb +0 -33
- data/lib/useless/rack/middleware/assets.rb +0 -38
- data/lib/useless/rack/middleware/authentication/access_token.rb +0 -41
- data/lib/useless/rack/middleware/authentication/query_string.rb +0 -21
- data/lib/useless/rack/middleware/authentication/request_header.rb +0 -21
- data/lib/useless/rack/middleware/exceptions.rb +0 -41
- data/lib/useless/rack/middleware/fs.rb +0 -17
- data/lib/useless/rack/middleware/mongo.rb +0 -18
- data/spec/useless/logger_spec.rb +0 -87
- data/spec/useless/rack/base/files_spec.rb +0 -42
- data/spec/useless/rack/middleware/exceptions_spec.rb +0 -47
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
-
require 'useless/rack/middleware/exceptions'
|
3
|
-
|
4
|
-
describe Useless::Rack::Middleware::Exceptions do
|
5
|
-
it 'should proxy transparently if nothing goes wrong in the main app' do
|
6
|
-
main_app = lambda do |env|
|
7
|
-
[200, {'Content-Type' => 'text/plain'}, ['No Problems!']]
|
8
|
-
end
|
9
|
-
exceptions_app = Useless::Rack::Middleware::Exceptions.new(main_app)
|
10
|
-
|
11
|
-
res = Rack::MockRequest.new(exceptions_app).get('http://useless.info')
|
12
|
-
res.should be_ok
|
13
|
-
res.body.should == 'No Problems!'
|
14
|
-
end
|
15
|
-
|
16
|
-
def broken_app
|
17
|
-
main_app = lambda do |env|
|
18
|
-
raise 'It\'s all broken!'
|
19
|
-
[200, {'Content-Type' => 'text/plain'}, ['No Problems!']]
|
20
|
-
end
|
21
|
-
|
22
|
-
Useless::Rack::Middleware::Exceptions.new(main_app)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should return a 500 with a generic message if an exception is raised
|
26
|
-
in the main app and the request is not authenticated' do
|
27
|
-
res = Rack::MockRequest.new(broken_app).get('http://useless.info')
|
28
|
-
res.status.should == 500
|
29
|
-
res.body.should == 'An internal server error occurred. Please try again later.'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should return a 500 with details of the exception if one is raised in
|
33
|
-
the main app and the request is authenticated by an admin user' do
|
34
|
-
res = Rack::MockRequest.new(broken_app).get('http://useless.info',
|
35
|
-
'useless.user' => {'handle' => 'khy', 'admin' => true})
|
36
|
-
res.status.should == 500
|
37
|
-
res.body.should =~ /^It's all broken!/
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should return a 500 with a generic message if an exception is raised
|
41
|
-
in the main app and the request is authenticated by an non-admin user' do
|
42
|
-
res = Rack::MockRequest.new(broken_app).get('http://useless.info',
|
43
|
-
'useless.user' => {'handle' => 'khy'})
|
44
|
-
res.status.should == 500
|
45
|
-
res.body.should == 'An internal server error occurred. Please try again later.'
|
46
|
-
end
|
47
|
-
end
|