lotus-controller 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/throw_test.rb DELETED
@@ -1,93 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Lotus::Action do
4
- describe '.handle_exception' do
5
- it 'handle an exception with the given status' do
6
- response = HandledExceptionAction.new.call({})
7
-
8
- response[0].must_equal 404
9
- end
10
-
11
- it "returns a 500 if an action isn't handled" do
12
- response = UnhandledExceptionAction.new.call({})
13
-
14
- response[0].must_equal 500
15
- end
16
-
17
- describe 'with global handled exceptions' do
18
- before do
19
- class DomainLogicException < StandardError
20
- end
21
-
22
- Lotus::Controller.handled_exceptions = {DomainLogicException => 400}
23
-
24
- class GlobalHandledExceptionAction
25
- include Lotus::Action
26
-
27
- def call(params)
28
- raise DomainLogicException.new
29
- end
30
- end
31
- end
32
-
33
- after do
34
- Object.send(:remove_const, :DomainLogicException)
35
- Object.send(:remove_const, :GlobalHandledExceptionAction)
36
-
37
- Lotus::Controller.handled_exceptions = {}
38
- end
39
-
40
- it 'handles raised exception' do
41
- response = GlobalHandledExceptionAction.new.call({})
42
-
43
- response[0].must_equal 400
44
- end
45
- end
46
- end
47
-
48
- describe '#throw' do
49
- HTTP_TEST_STATUSES.each do |code, body|
50
- it "throws an HTTP status code: #{ code }" do
51
- response = ThrowCodeAction.new.call({ status: code })
52
-
53
- response[0].must_equal code
54
- response[2].must_equal [body]
55
- end
56
- end
57
-
58
- it 'throws the code as it is, when not recognized' do
59
- response = ThrowCodeAction.new.call({ status: 2131231 })
60
-
61
- response[0].must_equal 500
62
- response[2].must_equal ['Internal Server Error']
63
- end
64
-
65
- it 'stops execution of before filters (method)' do
66
- response = ThrowBeforeMethodAction.new.call({})
67
-
68
- response[0].must_equal 401
69
- response[2].must_equal ['Unauthorized']
70
- end
71
-
72
- it 'stops execution of before filters (block)' do
73
- response = ThrowBeforeBlockAction.new.call({})
74
-
75
- response[0].must_equal 401
76
- response[2].must_equal ['Unauthorized']
77
- end
78
-
79
- it 'stops execution of after filters (method)' do
80
- response = ThrowAfterMethodAction.new.call({})
81
-
82
- response[0].must_equal 408
83
- response[2].must_equal ['Request Timeout']
84
- end
85
-
86
- it 'stops execution of after filters (block)' do
87
- response = ThrowAfterBlockAction.new.call({})
88
-
89
- response[0].must_equal 408
90
- response[2].must_equal ['Request Timeout']
91
- end
92
- end
93
- end
data/test/version_test.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Lotus::Controller::VERSION do
4
- it 'returns the current version' do
5
- Lotus::Controller::VERSION.must_equal '0.1.0'
6
- end
7
- end