rocketio 0.1.0 → 0.2.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
- data/lib/rocketio.rb +6 -3
- data/lib/rocketio/application.rb +3 -7
- data/lib/rocketio/controller.rb +62 -90
- data/lib/rocketio/controller/authentication.rb +38 -44
- data/lib/rocketio/controller/authorization.rb +8 -4
- data/lib/rocketio/controller/error_handlers.rb +12 -8
- data/lib/rocketio/controller/filters.rb +14 -19
- data/lib/rocketio/controller/helpers.rb +1 -1
- data/lib/rocketio/controller/middleware.rb +1 -1
- data/lib/rocketio/controller/render/engine.rb +3 -3
- data/lib/rocketio/controller/render/layout.rb +1 -1
- data/lib/rocketio/controller/render/layouts.rb +6 -6
- data/lib/rocketio/controller/render/template_vars.rb +3 -3
- data/lib/rocketio/controller/render/templates.rb +6 -6
- data/lib/rocketio/controller/sessions.rb +1 -1
- data/lib/rocketio/error_templates/409.html +11 -7
- data/lib/rocketio/error_templates/501.html +4 -4
- data/lib/rocketio/router.rb +35 -21
- data/lib/rocketio/version.rb +1 -1
- data/rocketio.gemspec +2 -0
- data/test/aliases_test.rb +2 -2
- data/test/api_test.rb +24 -117
- data/test/authentication_test.rb +96 -60
- data/test/authorization_test.rb +28 -17
- data/test/cache_control_test.rb +12 -12
- data/test/content_type_test.rb +7 -7
- data/test/cookies_test.rb +4 -4
- data/test/error_handlers_test.rb +14 -12
- data/test/etag_test.rb +32 -32
- data/test/filters_test.rb +96 -79
- data/test/halt_test.rb +1 -1
- data/test/helpers_test.rb +6 -6
- data/test/middleware_test.rb +4 -4
- data/test/redirect_test.rb +6 -7
- data/test/render/{post.erb → b.erb} +0 -0
- data/test/render/{put.erb → c.erb} +0 -0
- data/test/render/engine_test.rb +5 -5
- data/test/render/{get.erb → index.erb} +0 -0
- data/test/render/layout_test.rb +21 -17
- data/test/render/layouts_test.rb +14 -14
- data/test/render/render_test.rb +17 -14
- data/test/render/template_vars_test.rb +9 -9
- data/test/render/templates_test.rb +16 -16
- data/test/response_test.rb +4 -4
- data/test/routes_test.rb +21 -42
- data/test/sendfile_test.rb +8 -8
- data/test/sessions_test.rb +27 -27
- data/test/setup.rb +2 -0
- metadata +34 -6
data/test/filters_test.rb
CHANGED
@@ -6,172 +6,189 @@ spec :Filters do
|
|
6
6
|
it 'inherits filters from superclass' do
|
7
7
|
before, around, after = [], [], []
|
8
8
|
a = mock_controller {
|
9
|
-
before(:
|
10
|
-
around(:
|
11
|
-
after(:
|
12
|
-
|
9
|
+
before(:a) {before << :a}
|
10
|
+
around(:a) {|a| around << :a}
|
11
|
+
after(:a) {after << :a}
|
12
|
+
}
|
13
|
+
b = mock_controller(a) {
|
14
|
+
def a; end
|
13
15
|
}
|
14
|
-
b = mock_controller(a)
|
15
16
|
app(b)
|
16
|
-
get
|
17
|
+
get :a
|
17
18
|
assert([before, around, after]).all? {|a| a.include?(:a)}
|
18
19
|
end
|
19
20
|
|
20
21
|
it 'inherits filters explicitly' do
|
21
22
|
before, around, after = [], [], []
|
22
23
|
a = mock_controller {
|
23
|
-
before(:
|
24
|
-
around(:
|
25
|
-
after(:
|
26
|
-
def get; end
|
24
|
+
before(:a) {before << :x}
|
25
|
+
around(:a) {|a| around << :x}
|
26
|
+
after(:a) {after << :x}
|
27
27
|
}
|
28
28
|
b = mock_controller {
|
29
29
|
import :before, from: a
|
30
30
|
import :around, from: a
|
31
31
|
import :after, from: a
|
32
|
+
def a; end
|
32
33
|
}
|
33
34
|
app(b)
|
34
|
-
get
|
35
|
+
get :a
|
35
36
|
assert([before, around, after]).all? {|a| a.include?(:x)}
|
36
37
|
end
|
37
38
|
|
38
39
|
test 'explicitly inherited filters overrides filters inherited from superclass' do
|
39
40
|
before, around, after = [], [], []
|
40
41
|
a = mock_controller {
|
41
|
-
before(:
|
42
|
-
around(:
|
43
|
-
after(:
|
44
|
-
def get; end
|
42
|
+
before(:a) {before << :a}
|
43
|
+
around(:a) {|a| around << :a}
|
44
|
+
after(:a) {after << :a}
|
45
45
|
}
|
46
46
|
b = mock_controller {
|
47
|
-
before(:
|
48
|
-
around(:
|
49
|
-
after(:
|
47
|
+
before(:a) {before << :b}
|
48
|
+
around(:a) {|a| around << :b}
|
49
|
+
after(:a) {after << :b}
|
50
50
|
}
|
51
51
|
c = mock_controller(a) {
|
52
52
|
import :before, from: b
|
53
53
|
import :around, from: b
|
54
54
|
import :after, from: b
|
55
|
+
def a; end
|
55
56
|
}
|
56
57
|
app(c)
|
57
|
-
get
|
58
|
+
get :a
|
58
59
|
assert([before, around, after]).none? {|a| a.include?(:a)}
|
59
60
|
assert([before, around, after]).all? {|a| a.include?(:b)}
|
60
61
|
end
|
61
62
|
|
62
63
|
test 'explicitly inherited filters complements filters inherited from superclass' do
|
63
|
-
|
64
|
-
|
64
|
+
before_a, around_a, after_a = [], [], []
|
65
|
+
before_b, around_b, after_b = [], [], []
|
65
66
|
a = mock_controller {
|
66
|
-
before(:
|
67
|
-
around(:
|
68
|
-
after(:
|
67
|
+
before(:a) {before_a << :a}
|
68
|
+
around(:a) {|a| around_a << :a}
|
69
|
+
after(:a) {after_a << :a}
|
69
70
|
}
|
70
71
|
b = mock_controller {
|
71
|
-
before(:
|
72
|
-
around(:
|
73
|
-
after(:
|
72
|
+
before(:b) {before_b << :b}
|
73
|
+
around(:b) {|a| around_b << :b}
|
74
|
+
after(:b) {after_b << :b}
|
74
75
|
}
|
75
76
|
c = mock_controller(a) {
|
76
77
|
import :before, from: b
|
77
78
|
import :around, from: b
|
78
79
|
import :after, from: b
|
80
|
+
def a; end
|
81
|
+
def b; end
|
79
82
|
}
|
80
83
|
app(c)
|
81
|
-
get
|
82
|
-
assert([
|
83
|
-
|
84
|
-
assert([
|
84
|
+
get :a
|
85
|
+
assert([before_a, around_a, after_a]).all? {|a| a.include?(:a)}
|
86
|
+
get :b
|
87
|
+
assert([before_b, around_b, after_b]).all? {|a| a.include?(:b)}
|
85
88
|
end
|
86
89
|
|
87
|
-
|
90
|
+
test 'defined filters overrides filters inherited from superclass' do
|
88
91
|
before, around, after = [], [], []
|
89
92
|
a = mock_controller {
|
90
|
-
before(:
|
91
|
-
around(:
|
92
|
-
after(:
|
93
|
+
before(:a) {before << :a}
|
94
|
+
around(:a) {|a| around << :a}
|
95
|
+
after(:a) {after << :a}
|
93
96
|
}
|
94
97
|
b = mock_controller(a) {
|
95
|
-
before(:
|
96
|
-
after(:
|
98
|
+
before(:a) {before << :b}
|
99
|
+
after(:a) {after << :b}
|
100
|
+
def a; end
|
97
101
|
}
|
98
102
|
app(b)
|
99
|
-
get
|
103
|
+
get :a
|
100
104
|
assert([before, after]).all? {|a| a == [:b]}
|
101
105
|
assert(around) == [:a]
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
105
|
-
it 'defines filters for all
|
109
|
+
it 'defines filters for all methods if called without arguments' do
|
106
110
|
before, around, after = [], [], []
|
107
111
|
app mock_controller {
|
108
|
-
before
|
109
|
-
around
|
110
|
-
after
|
112
|
+
before {before << requested_method}
|
113
|
+
around {|a| around << requested_method}
|
114
|
+
after {after << requested_method}
|
115
|
+
def a; end
|
116
|
+
def b; end
|
117
|
+
def c; end
|
111
118
|
}
|
112
119
|
filters = [before, around, after]
|
113
120
|
|
114
|
-
get
|
115
|
-
assert(filters).all? {|a| a.include?(:
|
116
|
-
|
117
|
-
post
|
118
|
-
assert(filters).all? {|a| a.include?(:post)}
|
119
|
-
|
120
|
-
put
|
121
|
-
assert(filters).all? {|a| a.include?(:put)}
|
121
|
+
get :a
|
122
|
+
assert(filters).all? {|a| a.include?(:a)}
|
122
123
|
|
123
|
-
|
124
|
-
assert(filters).all? {|a| a.include?(:
|
124
|
+
get :b
|
125
|
+
assert(filters).all? {|a| a.include?(:b)}
|
125
126
|
|
126
|
-
|
127
|
-
assert(filters).all? {|a| a.include?(:
|
127
|
+
get :c
|
128
|
+
assert(filters).all? {|a| a.include?(:c)}
|
128
129
|
end
|
129
130
|
|
130
131
|
it 'defines filters only for given requested method(s)' do
|
131
132
|
before, around, after = [], [], []
|
132
133
|
app mock_controller {
|
133
|
-
before(:
|
134
|
-
around(:
|
135
|
-
after(:
|
136
|
-
def
|
134
|
+
before(:a) {before << requested_method}
|
135
|
+
around(:b, :c) {|a| around << requested_method}
|
136
|
+
after(:d) {after << requested_method}
|
137
|
+
def a; end
|
138
|
+
def b; end
|
139
|
+
def c; end
|
140
|
+
def d; end
|
137
141
|
}
|
138
|
-
get
|
139
|
-
assert(before).include?(:get)
|
140
|
-
assert([around, after]).none? {|a| a.include?(:get)}
|
141
142
|
|
142
|
-
|
143
|
-
assert(
|
144
|
-
assert([
|
143
|
+
get :a
|
144
|
+
assert(before).include?(:a)
|
145
|
+
assert([around, after]).none? {|a| a.include?(:a)}
|
145
146
|
|
146
|
-
|
147
|
-
assert(around).include?(:
|
148
|
-
assert([before, after]).none? {|a| a.include?(:
|
147
|
+
get :b
|
148
|
+
assert(around).include?(:b)
|
149
|
+
assert([before, after]).none? {|a| a.include?(:b)}
|
149
150
|
|
150
|
-
|
151
|
-
assert(
|
152
|
-
assert([before,
|
151
|
+
get :c
|
152
|
+
assert(around).include?(:c)
|
153
|
+
assert([before, after]).none? {|a| a.include?(:c)}
|
154
|
+
|
155
|
+
get :d
|
156
|
+
assert(after).include?(:d)
|
157
|
+
assert([before, around]).none? {|a| a.include?(:d)}
|
153
158
|
end
|
154
159
|
|
155
|
-
it 'creates a void filter if called without a block' do
|
160
|
+
it 'creates a void wildcard filter if called without a block' do
|
156
161
|
ctrl = mock_controller {
|
157
|
-
before
|
158
|
-
before
|
159
|
-
def
|
160
|
-
}.
|
162
|
+
before {raise 'this should be overridden'}
|
163
|
+
before
|
164
|
+
def index; end
|
165
|
+
}.new
|
161
166
|
app(ctrl)
|
162
|
-
expect(ctrl).to_receive(:
|
167
|
+
expect(ctrl).to_receive(:'__before_*__')
|
163
168
|
get
|
164
169
|
end
|
165
170
|
|
171
|
+
it 'creates a void named filter if called without a block' do
|
172
|
+
ctrl = mock_controller {
|
173
|
+
before(:index) {raise 'this should be overridden'}
|
174
|
+
before(:index)
|
175
|
+
def index; end
|
176
|
+
}.new
|
177
|
+
app(ctrl)
|
178
|
+
expect(ctrl).to_receive(:__before_index__)
|
179
|
+
get :index
|
180
|
+
end
|
181
|
+
|
166
182
|
it 'it calls wildcard filters before specialized ones' do
|
167
183
|
buffer = []
|
168
184
|
app mock_controller {
|
169
185
|
# specialized filter, called only on GET requests
|
170
|
-
before(:
|
186
|
+
before(:a) {buffer << requested_method}
|
171
187
|
# wildcard filter, called on any requests
|
172
188
|
before {buffer << :*}
|
189
|
+
def a; end
|
173
190
|
}
|
174
|
-
get
|
175
|
-
assert(buffer) == [:*, :
|
191
|
+
get :a
|
192
|
+
assert(buffer) == [:*, :a]
|
176
193
|
end
|
177
194
|
end
|
data/test/halt_test.rb
CHANGED
data/test/helpers_test.rb
CHANGED
@@ -6,7 +6,7 @@ spec :HelpersTest do
|
|
6
6
|
code += 2 if [204, 205, 304].include? code
|
7
7
|
block ||= proc { }
|
8
8
|
app mock_controller {
|
9
|
-
define_method :
|
9
|
+
define_method :index do
|
10
10
|
response.status = code
|
11
11
|
instance_eval(&block).inspect
|
12
12
|
end
|
@@ -116,7 +116,7 @@ spec :HelpersTest do
|
|
116
116
|
context 'body' do
|
117
117
|
it 'takes a block for deferred body generation' do
|
118
118
|
app mock_controller {
|
119
|
-
define_method(:
|
119
|
+
define_method(:index) { response.body = -> { 'Hello World' } }
|
120
120
|
}
|
121
121
|
|
122
122
|
get
|
@@ -125,7 +125,7 @@ spec :HelpersTest do
|
|
125
125
|
|
126
126
|
it 'takes a String, Array, or other object responding to #each' do
|
127
127
|
app mock_controller {
|
128
|
-
define_method(:
|
128
|
+
define_method(:index) { response.body = 'Hello World' }
|
129
129
|
}
|
130
130
|
|
131
131
|
get
|
@@ -136,7 +136,7 @@ spec :HelpersTest do
|
|
136
136
|
context 'headers' do
|
137
137
|
it 'sets headers on the response object when given a Hash' do
|
138
138
|
app mock_controller {
|
139
|
-
define_method(:
|
139
|
+
define_method(:index) {headers 'X-Foo' => 'bar', 'X-Baz' => 'bling'}
|
140
140
|
}
|
141
141
|
|
142
142
|
get
|
@@ -147,7 +147,7 @@ spec :HelpersTest do
|
|
147
147
|
|
148
148
|
it 'returns the response headers hash when no hash provided' do
|
149
149
|
app mock_controller {
|
150
|
-
define_method(:
|
150
|
+
define_method(:index) {headers['X-Foo'] = 'bar'}
|
151
151
|
}
|
152
152
|
|
153
153
|
get
|
@@ -159,7 +159,7 @@ spec :HelpersTest do
|
|
159
159
|
context 'back' do
|
160
160
|
it "makes redirecting back pretty" do
|
161
161
|
app mock_controller('/foo') {
|
162
|
-
def
|
162
|
+
def index; redirect back end
|
163
163
|
}
|
164
164
|
|
165
165
|
env['HTTP_REFERER'] = 'http://github.com'
|
data/test/middleware_test.rb
CHANGED
@@ -15,7 +15,7 @@ spec :Middleware do
|
|
15
15
|
use(ware) {buff << :y}
|
16
16
|
}
|
17
17
|
b = mock_controller(a) {
|
18
|
-
def
|
18
|
+
def index; end
|
19
19
|
}
|
20
20
|
app mock_app(b)
|
21
21
|
get
|
@@ -30,7 +30,7 @@ spec :Middleware do
|
|
30
30
|
b = mock_controller {
|
31
31
|
use(ware) { buff << 3 }
|
32
32
|
import :middleware, from: a
|
33
|
-
def
|
33
|
+
def index; end
|
34
34
|
}
|
35
35
|
app mock_app(b)
|
36
36
|
get
|
@@ -44,11 +44,11 @@ spec :Middleware do
|
|
44
44
|
}
|
45
45
|
b = mock_controller(a) {
|
46
46
|
use(ware) {buff << :z}
|
47
|
-
def
|
47
|
+
def index; end
|
48
48
|
}
|
49
49
|
c = mock_controller(a) {
|
50
50
|
import :middleware, from: b
|
51
|
-
def
|
51
|
+
def index; end
|
52
52
|
}
|
53
53
|
app mock_app(c)
|
54
54
|
get
|
data/test/redirect_test.rb
CHANGED
@@ -28,8 +28,7 @@ require 'setup'
|
|
28
28
|
spec :Redirect do
|
29
29
|
before do
|
30
30
|
app mock_controller {
|
31
|
-
define_method(:
|
32
|
-
define_method(:post) { redirect '/foo' }
|
31
|
+
define_method(:index) { redirect '/foo' }
|
33
32
|
}
|
34
33
|
env.clear
|
35
34
|
end
|
@@ -43,7 +42,7 @@ spec :Redirect do
|
|
43
42
|
|
44
43
|
it 'uses 301 for permanent redirects' do
|
45
44
|
app mock_controller {
|
46
|
-
define_method(:
|
45
|
+
define_method(:index) { permanent_redirect '/foo' }
|
47
46
|
}
|
48
47
|
|
49
48
|
get
|
@@ -54,7 +53,7 @@ spec :Redirect do
|
|
54
53
|
|
55
54
|
it 'redirects back to request.referer when passed back' do
|
56
55
|
app mock_controller(:try_redirect) {
|
57
|
-
define_method(:
|
56
|
+
define_method(:index) { redirect back }
|
58
57
|
}
|
59
58
|
|
60
59
|
env['HTTP_REFERER'] = '/foo'
|
@@ -102,7 +101,7 @@ spec :Redirect do
|
|
102
101
|
|
103
102
|
it 'accepts absolute URIs' do
|
104
103
|
app mock_controller {
|
105
|
-
define_method(:
|
104
|
+
define_method(:index) {redirect 'http://google.com'}
|
106
105
|
}
|
107
106
|
|
108
107
|
get
|
@@ -113,7 +112,7 @@ spec :Redirect do
|
|
113
112
|
|
114
113
|
it 'accepts absolute URIs with a different schema' do
|
115
114
|
app mock_controller {
|
116
|
-
define_method(:
|
115
|
+
define_method(:index) {redirect 'mailto:jsmith@example.com'}
|
117
116
|
}
|
118
117
|
|
119
118
|
get
|
@@ -124,7 +123,7 @@ spec :Redirect do
|
|
124
123
|
|
125
124
|
it 'accepts a URI object instead of a String' do
|
126
125
|
app mock_controller {
|
127
|
-
define_method(:
|
126
|
+
define_method(:index) {redirect URI.parse('http://sinatrarb.com')}
|
128
127
|
}
|
129
128
|
|
130
129
|
get
|
File without changes
|
File without changes
|
data/test/render/engine_test.rb
CHANGED
@@ -7,7 +7,7 @@ spec :engine do
|
|
7
7
|
}
|
8
8
|
b = mock_controller(a) {
|
9
9
|
}
|
10
|
-
assert(b.
|
10
|
+
assert(b.new.engine) == [:SlimTemplate, []]
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'overrides engine inherited from superclass' do
|
@@ -17,7 +17,7 @@ spec :engine do
|
|
17
17
|
b = mock_controller(a) {
|
18
18
|
engine :Turbo
|
19
19
|
}
|
20
|
-
assert(b.
|
20
|
+
assert(b.new.engine) == [:TurboTemplate, []]
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'can use include to override engine inherited from superclass' do
|
@@ -30,13 +30,13 @@ spec :engine do
|
|
30
30
|
c = mock_controller(a) {
|
31
31
|
import :engine, from: b
|
32
32
|
}
|
33
|
-
assert(c.
|
33
|
+
assert(c.new.engine) == [:TurboTemplate, []]
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'uses a block (that runs at instance level) to define engine' do
|
37
37
|
app mock_controller {
|
38
38
|
engine {@x = 'x'; :Slim}
|
39
|
-
def
|
39
|
+
def index; engine[0].to_s + @x end
|
40
40
|
}
|
41
41
|
get
|
42
42
|
assert(last_response.body) == 'SlimTemplatex'
|
@@ -59,7 +59,7 @@ spec :engine do
|
|
59
59
|
engine {
|
60
60
|
:ERB if env['IAMABOT']
|
61
61
|
}
|
62
|
-
def
|
62
|
+
def index; engine[0].to_s end
|
63
63
|
}
|
64
64
|
app b
|
65
65
|
get
|