rack-content_type_validator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,7 @@ module Rack
|
|
9
9
|
@methods = handle_methods(methods)
|
10
10
|
@path = path
|
11
11
|
@expected_params = expected_params
|
12
|
+
@expected_params[:mime_type] = [@expected_params[:mime_type]] if @expected_params[:mime_type].is_a?(String)
|
12
13
|
end
|
13
14
|
|
14
15
|
def call(env)
|
@@ -50,7 +51,7 @@ module Rack
|
|
50
51
|
return true unless expected_mime_type
|
51
52
|
|
52
53
|
mime_type = content_type ? content_type[/^([\w\/]+)\b/, 1] : nil
|
53
|
-
mime_type
|
54
|
+
expected_mime_type.include?(mime_type)
|
54
55
|
end
|
55
56
|
|
56
57
|
def valid_params?(expected_params, content_type)
|
@@ -47,6 +47,21 @@ class ContentTypeValidatorTest < Test::Unit::TestCase
|
|
47
47
|
|
48
48
|
assert_equal 200, status
|
49
49
|
end
|
50
|
+
|
51
|
+
def test_correct_content_type_scope
|
52
|
+
path = "/posts"
|
53
|
+
|
54
|
+
expected_params = {:mime_type => ["application/json", "application/xml"]}
|
55
|
+
middleware = build_middleware(:post, path, expected_params)
|
56
|
+
|
57
|
+
env = build_env("POST", path, 'application/json')
|
58
|
+
status, headers, body = middleware.call(env)
|
59
|
+
assert_equal 200, status
|
60
|
+
|
61
|
+
env = build_env("POST", path, 'application/xml')
|
62
|
+
status, headers, body = middleware.call(env)
|
63
|
+
assert_equal 200, status
|
64
|
+
end
|
50
65
|
|
51
66
|
def test_correct_content_type_and_incorrect_charset
|
52
67
|
path = "/comments"
|
@@ -114,8 +129,4 @@ class ContentTypeValidatorTest < Test::Unit::TestCase
|
|
114
129
|
assert_equal 415, status
|
115
130
|
end
|
116
131
|
|
117
|
-
def test_multi
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
132
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-content_type_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lucas Fais
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-01-
|
19
|
+
date: 2011-01-10 00:00:00 -02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|