rocketio 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/authorization_test.rb
CHANGED
@@ -6,13 +6,15 @@ spec :AuthorizationTest do
|
|
6
6
|
a = mock_controller {
|
7
7
|
token_auth {|t| t == 'x'}
|
8
8
|
}
|
9
|
-
b = mock_controller(a)
|
9
|
+
b = mock_controller(a) {
|
10
|
+
def index; end
|
11
|
+
}
|
10
12
|
app(b)
|
11
13
|
get
|
12
14
|
assert(last_response.status) == 401
|
13
15
|
token_authorize 'x'
|
14
16
|
get
|
15
|
-
assert(last_response.status) ==
|
17
|
+
assert(last_response.status) == 200
|
16
18
|
end
|
17
19
|
|
18
20
|
it 'directly overrides token auth inherited from superclass' do
|
@@ -21,16 +23,17 @@ spec :AuthorizationTest do
|
|
21
23
|
}
|
22
24
|
b = mock_controller(a) {
|
23
25
|
token_auth {|t| t == 'y'}
|
26
|
+
def index; end
|
24
27
|
}
|
25
28
|
app(b)
|
26
29
|
get
|
27
30
|
assert(last_response.status) == 401
|
28
31
|
token_authorize 'y'
|
29
32
|
get
|
30
|
-
assert(last_response.status) ==
|
33
|
+
assert(last_response.status) == 200
|
31
34
|
end
|
32
35
|
|
33
|
-
it 'uses `
|
36
|
+
it 'uses `import` to override token auth inherited from superclass' do
|
34
37
|
a = mock_controller {
|
35
38
|
token_auth {|t| t == 'x'}
|
36
39
|
}
|
@@ -39,53 +42,61 @@ spec :AuthorizationTest do
|
|
39
42
|
}
|
40
43
|
c = mock_controller(a) {
|
41
44
|
import :token_auth, from: b
|
45
|
+
def index; end
|
42
46
|
}
|
43
47
|
app(c)
|
44
48
|
get
|
45
49
|
assert(last_response.status) == 401
|
46
50
|
token_authorize 'y'
|
47
51
|
get
|
48
|
-
assert(last_response.status) ==
|
52
|
+
assert(last_response.status) == 200
|
49
53
|
end
|
50
54
|
|
51
|
-
it 'inherits token auth procedures via `
|
55
|
+
it 'inherits token auth procedures via `import`' do
|
52
56
|
a = mock_controller {
|
53
57
|
token_auth {|t| t == 'x'}
|
54
58
|
}
|
55
59
|
b = mock_controller {
|
56
60
|
import :token_auth, from: a
|
61
|
+
def index; end
|
57
62
|
}
|
58
63
|
app(b)
|
59
64
|
get
|
60
65
|
assert(last_response.status) == 401
|
61
66
|
token_authorize 'x'
|
62
67
|
get
|
63
|
-
assert(last_response.status) ==
|
68
|
+
assert(last_response.status) == 200
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
67
|
-
context 'protect all request
|
72
|
+
context 'protect all methods on any request method' do
|
68
73
|
before do
|
69
74
|
app mock_controller {
|
70
|
-
token_auth {|t| t == '
|
71
|
-
|
75
|
+
token_auth {|t| t == 'x'}
|
76
|
+
def index; end
|
72
77
|
}
|
73
78
|
end
|
74
79
|
|
75
80
|
it 'return "401 Unauthorized" if token missing' do
|
76
|
-
|
77
|
-
|
81
|
+
RocketIO::REQUEST_METHODS.each_value do |rqm|
|
82
|
+
send(rqm)
|
83
|
+
assert(last_response.status) == 401
|
84
|
+
end
|
78
85
|
end
|
79
86
|
|
80
87
|
it 'return "401 Unauthorized" if token is wrong' do
|
81
|
-
|
82
|
-
|
88
|
+
RocketIO::REQUEST_METHODS.each_value do |rqm|
|
89
|
+
send(rqm)
|
90
|
+
assert(last_response.status) == 401
|
91
|
+
end
|
83
92
|
end
|
84
93
|
|
85
94
|
it 'return "200 Ok" when correct token provided' do
|
86
|
-
token_auth '
|
87
|
-
|
88
|
-
|
95
|
+
token_auth 'x'
|
96
|
+
RocketIO::REQUEST_METHODS.each_value do |rqm|
|
97
|
+
send(rqm)
|
98
|
+
assert(last_response.status) == 200
|
99
|
+
end
|
89
100
|
end
|
90
101
|
end
|
91
102
|
end
|
data/test/cache_control_test.rb
CHANGED
@@ -28,13 +28,13 @@ require 'setup'
|
|
28
28
|
spec 'cache_control' do
|
29
29
|
before do
|
30
30
|
a = mock_controller('/foo') {
|
31
|
-
def
|
31
|
+
def index
|
32
32
|
cache_control :public, :no_cache, :max_age => 60.0
|
33
33
|
'Hello World'
|
34
34
|
end
|
35
35
|
}
|
36
36
|
b = mock_controller('/bar') {
|
37
|
-
def
|
37
|
+
def index
|
38
38
|
cache_control :public, :no_cache
|
39
39
|
'Hello World'
|
40
40
|
end
|
@@ -56,19 +56,19 @@ end
|
|
56
56
|
spec 'expires' do
|
57
57
|
before do
|
58
58
|
foo = mock_controller('/foo') {
|
59
|
-
def
|
59
|
+
def index
|
60
60
|
expires 60, :public, :no_cache
|
61
61
|
'Hello World'
|
62
62
|
end
|
63
63
|
}
|
64
64
|
bar = mock_controller('/bar') {
|
65
|
-
def
|
65
|
+
def index; expires Time.now end
|
66
66
|
}
|
67
67
|
baz = mock_controller('/baz') {
|
68
|
-
def
|
68
|
+
def index; expires Time.at(0) end
|
69
69
|
}
|
70
70
|
blah = mock_controller('/blah') {
|
71
|
-
def
|
71
|
+
def index
|
72
72
|
obj = Object.new
|
73
73
|
def obj.method_missing(*a, &b) 60.send(*a, &b) end
|
74
74
|
def obj.is_a?(thing) 60.is_a?(thing) end
|
@@ -77,7 +77,7 @@ spec 'expires' do
|
|
77
77
|
end
|
78
78
|
}
|
79
79
|
boom = mock_controller('/boom') {
|
80
|
-
def
|
80
|
+
def index; expires '9999' end
|
81
81
|
}
|
82
82
|
app mock_app(foo, bar, baz, blah, boom)
|
83
83
|
end
|
@@ -115,7 +115,7 @@ end
|
|
115
115
|
spec 'last_modified' do
|
116
116
|
it 'ignores nil' do
|
117
117
|
app mock_controller {
|
118
|
-
def
|
118
|
+
def index; last_modified nil; ''; end
|
119
119
|
}
|
120
120
|
|
121
121
|
get
|
@@ -124,7 +124,7 @@ spec 'last_modified' do
|
|
124
124
|
|
125
125
|
it 'does not change a status other than 200' do
|
126
126
|
app mock_controller {
|
127
|
-
def
|
127
|
+
def index
|
128
128
|
response.status = 299
|
129
129
|
last_modified Time.at(0)
|
130
130
|
'ok'
|
@@ -147,12 +147,12 @@ spec 'last_modified' do
|
|
147
147
|
context "with #{last_modified_time.class.name}" do
|
148
148
|
before do
|
149
149
|
app mock_controller {
|
150
|
-
define_method :
|
150
|
+
define_method :index do
|
151
151
|
last_modified(last_modified_time)
|
152
152
|
'Boo!'
|
153
153
|
end
|
154
154
|
}
|
155
|
-
@last_modified_time = mock_controller.
|
155
|
+
@last_modified_time = mock_controller.new.time_for(last_modified_time)
|
156
156
|
end
|
157
157
|
|
158
158
|
context "when there's no If-Modified-Since header" do
|
@@ -199,7 +199,7 @@ spec 'last_modified' do
|
|
199
199
|
|
200
200
|
it 'does not rely on string comparison' do
|
201
201
|
app mock_controller {
|
202
|
-
def
|
202
|
+
def index
|
203
203
|
last_modified "Mon, 18 Oct 2010 20:57:11 GMT"
|
204
204
|
"foo"
|
205
205
|
end
|
data/test/content_type_test.rb
CHANGED
@@ -29,7 +29,7 @@ spec :ContentType do
|
|
29
29
|
|
30
30
|
it 'sets the Content-Type header' do
|
31
31
|
app mock_controller {
|
32
|
-
|
32
|
+
def index
|
33
33
|
content_type 'text/plain'
|
34
34
|
'Hello World'
|
35
35
|
end
|
@@ -42,7 +42,7 @@ spec :ContentType do
|
|
42
42
|
|
43
43
|
it 'takes media type parameters (like charset=)' do
|
44
44
|
app mock_controller {
|
45
|
-
|
45
|
+
def index
|
46
46
|
content_type 'text/html', charset: 'latin1'
|
47
47
|
"<h1>Hello, World</h1>"
|
48
48
|
end
|
@@ -56,7 +56,7 @@ spec :ContentType do
|
|
56
56
|
|
57
57
|
it 'updates charset for default content type' do
|
58
58
|
app mock_controller {
|
59
|
-
def
|
59
|
+
def index
|
60
60
|
charset('latin1')
|
61
61
|
"<h1>Hello, World</h1>"
|
62
62
|
end
|
@@ -70,7 +70,7 @@ spec :ContentType do
|
|
70
70
|
|
71
71
|
it 'updates charset without alter actual mimetype nor params' do
|
72
72
|
app mock_controller {
|
73
|
-
def
|
73
|
+
def index
|
74
74
|
content_type('.json', level: 1)
|
75
75
|
charset('utf-8')
|
76
76
|
'ok'
|
@@ -85,7 +85,7 @@ spec :ContentType do
|
|
85
85
|
it "looks up symbols in Rack's mime types dictionary" do
|
86
86
|
Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
|
87
87
|
app mock_controller('/foo.xml') {
|
88
|
-
|
88
|
+
def index
|
89
89
|
content_type :foo
|
90
90
|
"I AM FOO"
|
91
91
|
end
|
@@ -99,7 +99,7 @@ spec :ContentType do
|
|
99
99
|
|
100
100
|
it 'fails when no mime type is registered for the argument provided' do
|
101
101
|
app mock_controller {
|
102
|
-
def
|
102
|
+
def index
|
103
103
|
content_type :bizzle
|
104
104
|
"I AM FOO"
|
105
105
|
end
|
@@ -110,7 +110,7 @@ spec :ContentType do
|
|
110
110
|
|
111
111
|
it 'handles already present params' do
|
112
112
|
app mock_controller {
|
113
|
-
def
|
113
|
+
def index
|
114
114
|
content_type 'foo/bar;level=1', :charset => 'utf-8'
|
115
115
|
'ok'
|
116
116
|
end
|
data/test/cookies_test.rb
CHANGED
@@ -3,7 +3,7 @@ require 'setup'
|
|
3
3
|
spec :Cookies do
|
4
4
|
it 'reads cookies' do
|
5
5
|
app mock_controller {
|
6
|
-
def
|
6
|
+
def index; cookies[:x] end
|
7
7
|
}
|
8
8
|
cookies['x'] = 'y'
|
9
9
|
get
|
@@ -12,7 +12,7 @@ spec :Cookies do
|
|
12
12
|
|
13
13
|
it 'sets cookies' do
|
14
14
|
app mock_controller {
|
15
|
-
def
|
15
|
+
def index; cookies[:x] = 'y' end
|
16
16
|
}
|
17
17
|
get
|
18
18
|
assert(cookies['x']) == 'y'
|
@@ -20,7 +20,7 @@ spec :Cookies do
|
|
20
20
|
|
21
21
|
it 'deletes cookies' do
|
22
22
|
app mock_controller {
|
23
|
-
def
|
23
|
+
def index; cookies.delete(:x) end
|
24
24
|
}
|
25
25
|
cookies['x'] = 'y'
|
26
26
|
assert(cookies['x']) == 'y'
|
@@ -31,7 +31,7 @@ spec :Cookies do
|
|
31
31
|
it 'accepts a Hash with various options' do
|
32
32
|
expires = Time.now
|
33
33
|
app mock_controller {
|
34
|
-
define_method :
|
34
|
+
define_method :index do
|
35
35
|
cookies[:x] = {
|
36
36
|
value: 'y',
|
37
37
|
path: '/',
|
data/test/error_handlers_test.rb
CHANGED
@@ -2,6 +2,7 @@ require 'setup'
|
|
2
2
|
|
3
3
|
spec :ErrorHandlers do
|
4
4
|
context '501: Not Implemented' do
|
5
|
+
|
5
6
|
it 'uses default handler' do
|
6
7
|
app mock_controller
|
7
8
|
get
|
@@ -23,7 +24,7 @@ spec :ErrorHandlers do
|
|
23
24
|
it 'can be triggered manually' do
|
24
25
|
called = false
|
25
26
|
app mock_controller {
|
26
|
-
define_method(:
|
27
|
+
define_method(:index) {called = true; error(501)}
|
27
28
|
}
|
28
29
|
get
|
29
30
|
assert(called) == true
|
@@ -32,18 +33,19 @@ spec :ErrorHandlers do
|
|
32
33
|
end
|
33
34
|
|
34
35
|
context 'Parameters Error' do
|
36
|
+
|
35
37
|
it 'uses default handler' do
|
36
38
|
app mock_app(mock_controller {
|
37
|
-
def
|
39
|
+
def index; end
|
38
40
|
})
|
39
41
|
get :x
|
40
42
|
assert(last_response.status) == 409
|
41
|
-
assert(last_response.body) =~ /wrong
|
43
|
+
assert(last_response.body) =~ /wrong arguments/i
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'uses custom handler' do
|
45
47
|
app mock_app(mock_controller {
|
46
|
-
def
|
48
|
+
def index; end
|
47
49
|
error 409 do
|
48
50
|
'noway'
|
49
51
|
end
|
@@ -56,7 +58,7 @@ spec :ErrorHandlers do
|
|
56
58
|
it 'can be triggered manually' do
|
57
59
|
called = false
|
58
60
|
app mock_app(mock_controller {
|
59
|
-
define_method(:
|
61
|
+
define_method(:index) {called = true; error(409)}
|
60
62
|
})
|
61
63
|
get
|
62
64
|
assert(called) == true
|
@@ -65,16 +67,17 @@ spec :ErrorHandlers do
|
|
65
67
|
end
|
66
68
|
|
67
69
|
context '500: Fatal Error' do
|
70
|
+
|
68
71
|
it 'raises when no handler defined' do
|
69
72
|
app mock_controller {
|
70
|
-
def
|
73
|
+
def index; raise end
|
71
74
|
}
|
72
75
|
assert {get}.raise RuntimeError
|
73
76
|
end
|
74
77
|
|
75
78
|
it 'uses custom handler' do
|
76
79
|
app mock_controller {
|
77
|
-
def
|
80
|
+
def index; raise('badboy') end
|
78
81
|
error 500 do |e|
|
79
82
|
e.message
|
80
83
|
end
|
@@ -87,7 +90,7 @@ spec :ErrorHandlers do
|
|
87
90
|
it 'can be triggered manually' do
|
88
91
|
called = false
|
89
92
|
app mock_controller {
|
90
|
-
define_method(:
|
93
|
+
define_method(:index) {called = true; error(500, 'badgirl')}
|
91
94
|
}
|
92
95
|
get
|
93
96
|
assert(called) == true
|
@@ -97,10 +100,9 @@ spec :ErrorHandlers do
|
|
97
100
|
end
|
98
101
|
|
99
102
|
context '404: Not Found' do
|
103
|
+
|
100
104
|
it 'uses default handler' do
|
101
|
-
app mock_app(mock_controller(:x)
|
102
|
-
def get; end
|
103
|
-
})
|
105
|
+
app mock_app(mock_controller(:x))
|
104
106
|
get '/y'
|
105
107
|
assert(last_response.status) == 404
|
106
108
|
assert(last_response.body) =~ /404/
|
@@ -109,7 +111,7 @@ spec :ErrorHandlers do
|
|
109
111
|
it 'can be triggered manually and use custom handler' do
|
110
112
|
called = false
|
111
113
|
app mock_controller {
|
112
|
-
define_method(:
|
114
|
+
define_method(:index) {called = true; error(404)}
|
113
115
|
error 404 do
|
114
116
|
'trymore'
|
115
117
|
end
|
data/test/etag_test.rb
CHANGED
@@ -28,9 +28,9 @@ require 'setup'
|
|
28
28
|
spec :etag do
|
29
29
|
|
30
30
|
def run_with *args, &block
|
31
|
-
|
31
|
+
method = args.shift || :index
|
32
32
|
app mock_controller {
|
33
|
-
define_method
|
33
|
+
define_method method do
|
34
34
|
instance_exec(&block) if block
|
35
35
|
args.shift || 'ok'
|
36
36
|
end
|
@@ -191,7 +191,7 @@ spec :etag do
|
|
191
191
|
|
192
192
|
context "idempotent requests" do
|
193
193
|
it 'returns 200 for normal requests' do
|
194
|
-
run_with
|
194
|
+
run_with {etag 'foo'}
|
195
195
|
|
196
196
|
put
|
197
197
|
assert(last_response).is_ok_with_body('ok')
|
@@ -199,7 +199,7 @@ spec :etag do
|
|
199
199
|
|
200
200
|
context "If-None-Match" do
|
201
201
|
it 'returns 412 when If-None-Match is *' do
|
202
|
-
run_with
|
202
|
+
run_with {etag 'foo'}
|
203
203
|
|
204
204
|
env['HTTP_IF_NONE_MATCH'] = '*'
|
205
205
|
put
|
@@ -207,7 +207,7 @@ spec :etag do
|
|
207
207
|
end
|
208
208
|
|
209
209
|
it 'returns 200 when If-None-Match is * for new resources' do
|
210
|
-
run_with
|
210
|
+
run_with {etag 'foo', :new_resource => true}
|
211
211
|
|
212
212
|
env['HTTP_IF_NONE_MATCH'] = '*'
|
213
213
|
put
|
@@ -215,7 +215,7 @@ spec :etag do
|
|
215
215
|
end
|
216
216
|
|
217
217
|
it 'returns 412 when If-None-Match is * for existing resources' do
|
218
|
-
run_with
|
218
|
+
run_with {etag 'foo', :new_resource => false}
|
219
219
|
|
220
220
|
env['HTTP_IF_NONE_MATCH'] = '*'
|
221
221
|
put
|
@@ -223,7 +223,7 @@ spec :etag do
|
|
223
223
|
end
|
224
224
|
|
225
225
|
it 'returns 412 when If-None-Match is the etag' do
|
226
|
-
run_with
|
226
|
+
run_with {etag 'foo'}
|
227
227
|
|
228
228
|
env['HTTP_IF_NONE_MATCH'] = '"foo"'
|
229
229
|
put
|
@@ -231,7 +231,7 @@ spec :etag do
|
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'returns 412 when If-None-Match includes the etag' do
|
234
|
-
run_with
|
234
|
+
run_with {etag 'foo'}
|
235
235
|
|
236
236
|
env['HTTP_IF_NONE_MATCH'] = '"bar", "foo"'
|
237
237
|
put
|
@@ -239,7 +239,7 @@ spec :etag do
|
|
239
239
|
end
|
240
240
|
|
241
241
|
it 'returns 200 when If-None-Match does not include the etag' do
|
242
|
-
run_with
|
242
|
+
run_with {etag 'foo'}
|
243
243
|
|
244
244
|
env['HTTP_IF_NONE_MATCH'] = '"bar"'
|
245
245
|
put
|
@@ -247,7 +247,7 @@ spec :etag do
|
|
247
247
|
end
|
248
248
|
|
249
249
|
it 'ignores If-Modified-Since if If-None-Match does not match' do
|
250
|
-
run_with
|
250
|
+
run_with {
|
251
251
|
etag 'foo'
|
252
252
|
last_modified Time.at(0)
|
253
253
|
}
|
@@ -260,7 +260,7 @@ spec :etag do
|
|
260
260
|
|
261
261
|
context "If-Match" do
|
262
262
|
it 'returns 200 when If-Match is the etag' do
|
263
|
-
run_with
|
263
|
+
run_with {etag 'foo'}
|
264
264
|
|
265
265
|
env['HTTP_IF_MATCH'] = '"foo"'
|
266
266
|
put
|
@@ -268,7 +268,7 @@ spec :etag do
|
|
268
268
|
end
|
269
269
|
|
270
270
|
it 'returns 200 when If-Match includes the etag' do
|
271
|
-
run_with
|
271
|
+
run_with {etag 'foo'}
|
272
272
|
|
273
273
|
env['HTTP_IF_MATCH'] = '"foo", "bar"'
|
274
274
|
put
|
@@ -276,7 +276,7 @@ spec :etag do
|
|
276
276
|
end
|
277
277
|
|
278
278
|
it 'returns 200 when If-Match is *' do
|
279
|
-
run_with
|
279
|
+
run_with {etag 'foo'}
|
280
280
|
|
281
281
|
env['HTTP_IF_MATCH'] = '*'
|
282
282
|
put
|
@@ -284,7 +284,7 @@ spec :etag do
|
|
284
284
|
end
|
285
285
|
|
286
286
|
it 'returns 412 when If-Match is * for new resources' do
|
287
|
-
run_with
|
287
|
+
run_with {etag 'foo', :new_resource => true}
|
288
288
|
|
289
289
|
env['HTTP_IF_MATCH'] = '*'
|
290
290
|
put
|
@@ -292,7 +292,7 @@ spec :etag do
|
|
292
292
|
end
|
293
293
|
|
294
294
|
it 'returns 200 when If-Match is * for existing resources' do
|
295
|
-
run_with
|
295
|
+
run_with {etag 'foo', :new_resource => false}
|
296
296
|
|
297
297
|
env['HTTP_IF_MATCH'] = '*'
|
298
298
|
put
|
@@ -300,7 +300,7 @@ spec :etag do
|
|
300
300
|
end
|
301
301
|
|
302
302
|
it 'returns 412 when If-Match does not include the etag' do
|
303
|
-
run_with
|
303
|
+
run_with {etag 'foo'}
|
304
304
|
|
305
305
|
env['HTTP_IF_MATCH'] = '"bar"'
|
306
306
|
put
|
@@ -311,7 +311,7 @@ spec :etag do
|
|
311
311
|
|
312
312
|
context "post requests" do
|
313
313
|
it 'returns 200 for normal requests' do
|
314
|
-
run_with
|
314
|
+
run_with {etag 'foo'}
|
315
315
|
|
316
316
|
post
|
317
317
|
assert(last_response).is_ok_with_body('ok')
|
@@ -319,7 +319,7 @@ spec :etag do
|
|
319
319
|
|
320
320
|
context "If-None-Match" do
|
321
321
|
it 'returns 200 when If-None-Match is *' do
|
322
|
-
run_with
|
322
|
+
run_with {etag 'foo'}
|
323
323
|
|
324
324
|
env['HTTP_IF_NONE_MATCH'] = '*'
|
325
325
|
post
|
@@ -327,7 +327,7 @@ spec :etag do
|
|
327
327
|
end
|
328
328
|
|
329
329
|
it 'returns 200 when If-None-Match is * for new resources' do
|
330
|
-
run_with
|
330
|
+
run_with {etag 'foo', :new_resource => true}
|
331
331
|
|
332
332
|
env['HTTP_IF_NONE_MATCH'] = '*'
|
333
333
|
post
|
@@ -335,7 +335,7 @@ spec :etag do
|
|
335
335
|
end
|
336
336
|
|
337
337
|
it 'returns 412 when If-None-Match is * for existing resources' do
|
338
|
-
run_with
|
338
|
+
run_with {etag 'foo', :new_resource => false}
|
339
339
|
|
340
340
|
env['HTTP_IF_NONE_MATCH'] = '*'
|
341
341
|
post
|
@@ -343,7 +343,7 @@ spec :etag do
|
|
343
343
|
end
|
344
344
|
|
345
345
|
it 'returns 412 when If-None-Match is the etag' do
|
346
|
-
run_with
|
346
|
+
run_with {etag 'foo'}
|
347
347
|
|
348
348
|
env['HTTP_IF_NONE_MATCH'] = '"foo"'
|
349
349
|
post
|
@@ -351,7 +351,7 @@ spec :etag do
|
|
351
351
|
end
|
352
352
|
|
353
353
|
it 'returns 412 when If-None-Match includes the etag' do
|
354
|
-
run_with
|
354
|
+
run_with {etag 'foo'}
|
355
355
|
|
356
356
|
env['HTTP_IF_NONE_MATCH'] = '"bar", "foo"'
|
357
357
|
post
|
@@ -359,7 +359,7 @@ spec :etag do
|
|
359
359
|
end
|
360
360
|
|
361
361
|
it 'returns 200 when If-None-Match does not include the etag' do
|
362
|
-
run_with
|
362
|
+
run_with {etag 'foo'}
|
363
363
|
|
364
364
|
env['HTTP_IF_NONE_MATCH'] = '"bar"'
|
365
365
|
post
|
@@ -367,7 +367,7 @@ spec :etag do
|
|
367
367
|
end
|
368
368
|
|
369
369
|
it 'ignores If-Modified-Since if If-None-Match does not match' do
|
370
|
-
run_with
|
370
|
+
run_with {
|
371
371
|
etag 'foo'
|
372
372
|
last_modified Time.at(0)
|
373
373
|
}
|
@@ -380,7 +380,7 @@ spec :etag do
|
|
380
380
|
|
381
381
|
context "If-Match" do
|
382
382
|
it 'returns 200 when If-Match is the etag' do
|
383
|
-
run_with
|
383
|
+
run_with {etag 'foo'}
|
384
384
|
|
385
385
|
env['HTTP_IF_MATCH'] = '"foo"'
|
386
386
|
post
|
@@ -388,7 +388,7 @@ spec :etag do
|
|
388
388
|
end
|
389
389
|
|
390
390
|
it 'returns 200 when If-Match includes the etag' do
|
391
|
-
run_with
|
391
|
+
run_with {etag 'foo'}
|
392
392
|
|
393
393
|
env['HTTP_IF_MATCH'] = '"foo", "bar"'
|
394
394
|
post
|
@@ -396,7 +396,7 @@ spec :etag do
|
|
396
396
|
end
|
397
397
|
|
398
398
|
it 'returns 412 when If-Match is *' do
|
399
|
-
run_with
|
399
|
+
run_with {etag 'foo'}
|
400
400
|
|
401
401
|
env['HTTP_IF_MATCH'] = '*'
|
402
402
|
post
|
@@ -404,7 +404,7 @@ spec :etag do
|
|
404
404
|
end
|
405
405
|
|
406
406
|
it 'returns 412 when If-Match is * for new resources' do
|
407
|
-
run_with
|
407
|
+
run_with {etag 'foo', :new_resource => true}
|
408
408
|
|
409
409
|
env['HTTP_IF_MATCH'] = '*'
|
410
410
|
post
|
@@ -412,7 +412,7 @@ spec :etag do
|
|
412
412
|
end
|
413
413
|
|
414
414
|
it 'returns 200 when If-Match is * for existing resources' do
|
415
|
-
run_with
|
415
|
+
run_with {etag 'foo', :new_resource => false}
|
416
416
|
|
417
417
|
env['HTTP_IF_MATCH'] = '*'
|
418
418
|
post
|
@@ -420,7 +420,7 @@ spec :etag do
|
|
420
420
|
end
|
421
421
|
|
422
422
|
it 'returns 412 when If-Match does not include the etag' do
|
423
|
-
run_with
|
423
|
+
run_with {etag 'foo'}
|
424
424
|
|
425
425
|
env['HTTP_IF_MATCH'] = '"bar"'
|
426
426
|
post
|
@@ -430,14 +430,14 @@ spec :etag do
|
|
430
430
|
end
|
431
431
|
|
432
432
|
it 'uses a weak etag with the :weak option' do
|
433
|
-
run_with(:
|
433
|
+
run_with(:index, "that's weak, dude.") {etag 'FOO', :weak}
|
434
434
|
|
435
435
|
get
|
436
436
|
assert(last_response['ETag']) == 'W/"FOO"'
|
437
437
|
end
|
438
438
|
|
439
439
|
it 'raises an ArgumentError for an invalid strength' do
|
440
|
-
run_with(:
|
440
|
+
run_with(:index, "that's weak, dude.") {etag 'FOO', :w00t}
|
441
441
|
assert {get}.raise ArgumentError, /:strong or :weak expected/
|
442
442
|
end
|
443
443
|
end
|