sinatra-rest-addons 0.1.2 → 0.1.3
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.
- data/VERSION +1 -1
- data/lib/sinatra/rest/routes.rb +6 -4
- data/sinatra-rest-addons.gemspec +2 -2
- data/test/test_routes.rb +12 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/sinatra/rest/routes.rb
CHANGED
@@ -36,12 +36,14 @@ module Sinatra
|
|
36
36
|
accepted_formats = request.accept.map do |f|
|
37
37
|
generate_type_hash.call(f)
|
38
38
|
end
|
39
|
-
selected_format =
|
40
|
-
|
39
|
+
selected_format = nil
|
40
|
+
accepted_formats.each{ |accepted_format|
|
41
|
+
selected_format = supported_formats.detect{ |supported_format|
|
41
42
|
Regexp.new(Regexp.escape(accepted_format["type"]).gsub("\\*", ".*?"), Regexp::IGNORECASE) =~ supported_format["type"] &&
|
42
43
|
(accepted_format["level"] || INFINITY).to_f >= (supported_format["level"] || 0).to_f
|
43
|
-
}
|
44
|
-
|
44
|
+
}
|
45
|
+
break unless selected_format.nil?
|
46
|
+
}
|
45
47
|
if selected_format.nil?
|
46
48
|
content_type :txt
|
47
49
|
halt 406, supported_formats.map{|f|
|
data/sinatra-rest-addons.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-rest-addons}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril Rohr"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-16}
|
13
13
|
s.description = %q{A set of helpers and extensions for sinatra apps that expose REST resources.}
|
14
14
|
s.email = %q{cyril.rohr@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_routes.rb
CHANGED
@@ -20,7 +20,6 @@ class RoutesTest < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
context "route option :provides" do
|
23
|
-
|
24
23
|
|
25
24
|
test "should return 406 and the list of supported types, if the server does not support the types accepted by the client [simple matching]" do
|
26
25
|
mock_app {
|
@@ -58,6 +57,18 @@ class RoutesTest < Test::Unit::TestCase
|
|
58
57
|
assert_equal 'application/*', last_response.body
|
59
58
|
assert_equal 'application/xml', last_response.headers['Content-Type']
|
60
59
|
end
|
60
|
+
test "should respect the order in which the accepted formats are declared when looking for the format to select" do
|
61
|
+
mock_app {
|
62
|
+
register Sinatra::REST::Routes
|
63
|
+
get '/', :provides => ["application/json", "application/xml", "application/vnd.x.y.z+xml"] do
|
64
|
+
request.env['HTTP_ACCEPT']
|
65
|
+
end
|
66
|
+
}
|
67
|
+
get '/', {}, { 'HTTP_ACCEPT' => 'application/xml, */*' }
|
68
|
+
assert_equal 200, last_response.status
|
69
|
+
assert_equal 'application/xml, */*', last_response.body
|
70
|
+
assert_equal 'application/xml', last_response.headers['Content-Type']
|
71
|
+
end
|
61
72
|
test "should be successful if the accepted type does not require a specific level" do
|
62
73
|
mock_app {
|
63
74
|
register Sinatra::REST::Routes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rest-addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Rohr
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-16 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|