sinatra-rest-helpers 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sinatra/rest_helpers.rb +3 -2
- data/sinatra-rest-helpers.gemspec +1 -1
- data/spec/sinatra_rest_helpers_spec.rb +7 -4
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/sinatra/rest_helpers.rb
CHANGED
@@ -38,8 +38,9 @@ module Sinatra
|
|
38
38
|
if selected_format.nil?
|
39
39
|
halt 406, supported_formats.map{|f|
|
40
40
|
output = f["type"]
|
41
|
-
output
|
42
|
-
|
41
|
+
output.concat(";level=#{f["level"]}") if f.has_key?("level")
|
42
|
+
output
|
43
|
+
}.join(",")
|
43
44
|
else
|
44
45
|
response.headers['Content-Type'] = "#{selected_format["type"]}#{selected_format["level"].nil? ? "" : ";level=#{selected_format["level"]}"}"
|
45
46
|
end
|
@@ -31,10 +31,13 @@ describe "SinatraRestHelpers" do
|
|
31
31
|
end
|
32
32
|
describe ":provides" do
|
33
33
|
it "should throw a 406 if the client requested only unsupported formats" do
|
34
|
-
|
34
|
+
mime :json, 'application/json'
|
35
|
+
mime :xml, 'application/xml'
|
36
|
+
mime :object_json, 'application/vnd.com.example.Object+json;level=1'
|
37
|
+
request = mock("request", :accept => ["text/plain"])
|
35
38
|
app = App.new(request)
|
36
|
-
app.should_receive(:halt).with(406, "")
|
37
|
-
app.test_provides!(:json)
|
39
|
+
app.should_receive(:halt).with(406, "application/json,application/xml,application/vnd.com.example.Object+json;level=1")
|
40
|
+
app.test_provides!(:json, :xml, :object_json)
|
38
41
|
end
|
39
42
|
it "should not throw a 406 if the client requested a supported format" do
|
40
43
|
request = mock("request", :accept => ["application/json"])
|
@@ -54,7 +57,7 @@ describe "SinatraRestHelpers" do
|
|
54
57
|
it "should not accept a request with a type level lower than what is supported" do
|
55
58
|
request = mock("request", :accept => ["application/json;level=1"])
|
56
59
|
app = App.new(request)
|
57
|
-
app.should_receive(:halt).with(406, "application/json;level=3,
|
60
|
+
app.should_receive(:halt).with(406, "application/json;level=3,application/json;level=2")
|
58
61
|
app.test_provides!("application/json;level=3", "application/json;level=2")
|
59
62
|
end
|
60
63
|
it "should accept a request having a supported mime type, but with no level" do
|