sinatra-rest-helpers 0.3.0 → 0.4.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.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/sinatra/rest_helpers.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'rack'
|
2
2
|
|
3
3
|
module Sinatra
|
4
|
+
#
|
5
|
+
# Include it with:
|
6
|
+
# class App < Sinatra::Base
|
7
|
+
# helpers Sinatra::RestHelpers
|
8
|
+
# end
|
9
|
+
#
|
4
10
|
module RestHelpers
|
5
11
|
INFINITY = 1/0.0
|
6
12
|
# e.g.:
|
@@ -18,7 +24,8 @@ module Sinatra
|
|
18
24
|
end.compact.map do |f|
|
19
25
|
generate_type_hash.call(f)
|
20
26
|
end
|
21
|
-
|
27
|
+
# request.accept is an Array
|
28
|
+
accepted_formats = request.accept.map do |f|
|
22
29
|
generate_type_hash.call(f)
|
23
30
|
end
|
24
31
|
selected_format = supported_formats.detect{ |supported_format|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-rest-helpers}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
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-10-
|
12
|
+
s.date = %q{2009-10-21}
|
13
13
|
s.description = %q{A set of helpers for sinatra apps that expose REST resources.}
|
14
14
|
s.email = %q{cyril.rohr@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"lib/sinatra/rest_helpers.rb",
|
27
27
|
"sinatra-rest-helpers.gemspec",
|
28
|
-
"spec/
|
28
|
+
"spec/sinatra_rest_helpers_spec.rb",
|
29
29
|
"spec/spec_helper.rb"
|
30
30
|
]
|
31
31
|
s.homepage = %q{http://github.com/cryx/sinatra-rest-helpers}
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.rubygems_version = %q{1.3.5}
|
35
35
|
s.summary = %q{Adds useful helpers for REST applications developed with Sinatra.}
|
36
36
|
s.test_files = [
|
37
|
-
"spec/
|
37
|
+
"spec/sinatra_rest_helpers_spec.rb",
|
38
38
|
"spec/spec_helper.rb"
|
39
39
|
]
|
40
40
|
|
@@ -25,13 +25,13 @@ describe "SinatraRestHelpers" do
|
|
25
25
|
Rack::Mime::MIME_TYPES.clear
|
26
26
|
end
|
27
27
|
it "should throw a 406 if the client requested only unsupported formats" do
|
28
|
-
request = mock("request", :accept => "application/json")
|
28
|
+
request = mock("request", :accept => ["application/json"])
|
29
29
|
app = App.new(request)
|
30
30
|
app.should_receive(:halt).with(406, "")
|
31
31
|
app.test_provides!(:json)
|
32
32
|
end
|
33
33
|
it "should not throw a 406 if the client requested a supported format" do
|
34
|
-
request = mock("request", :accept => "application/json")
|
34
|
+
request = mock("request", :accept => ["application/json"])
|
35
35
|
mime :json, "application/json"
|
36
36
|
app = App.new(request)
|
37
37
|
app.should_not_receive(:halt)
|
@@ -39,51 +39,54 @@ describe "SinatraRestHelpers" do
|
|
39
39
|
app.response.headers['Content-Type'].should == "application/json"
|
40
40
|
end
|
41
41
|
it "should be case insensitive" do
|
42
|
-
request = mock("request", :accept => "application/json")
|
42
|
+
request = mock("request", :accept => ["application/json"])
|
43
43
|
app = App.new(request)
|
44
44
|
app.should_not_receive(:halt)
|
45
45
|
app.test_provides!("application/JSON")
|
46
46
|
app.response.headers['Content-Type'].should == "application/JSON"
|
47
47
|
end
|
48
48
|
it "should not accept a request with a type level lower than what is supported" do
|
49
|
-
request = mock("request", :accept => "application/json;level=1")
|
49
|
+
request = mock("request", :accept => ["application/json;level=1"])
|
50
50
|
app = App.new(request)
|
51
51
|
app.should_receive(:halt).with(406, "application/json;level=3, application/json;level=2")
|
52
52
|
app.test_provides!("application/json;level=3", "application/json;level=2")
|
53
53
|
end
|
54
54
|
it "should accept a request having a supported mime type, but with no level" do
|
55
|
-
request = mock("request", :accept => "application/json")
|
55
|
+
request = mock("request", :accept => ["application/json"])
|
56
56
|
app = App.new(request)
|
57
57
|
app.should_not_receive(:halt)
|
58
58
|
app.test_provides!("application/json;level=2")
|
59
59
|
app.response.headers['Content-Type'].should == "application/json;level=2"
|
60
60
|
end
|
61
61
|
it "should select the first type matching the criteria" do
|
62
|
-
request = mock("request", :accept => "application/json;level=2, application/xml, application/vnd.fr.grid5000.api.Cluster+json;level=2")
|
62
|
+
request = mock("request", :accept => ["application/json;level=2", "application/xml", "application/vnd.fr.grid5000.api.Cluster+json;level=2"])
|
63
63
|
app = App.new(request)
|
64
64
|
app.should_not_receive(:halt)
|
65
65
|
app.test_provides!("application/json;level=3", "application/vnd.fr.grid5000.api.Cluster+json;level=2")
|
66
66
|
app.response.headers['Content-Type'].should == "application/vnd.fr.grid5000.api.Cluster+json;level=2"
|
67
67
|
end
|
68
68
|
it "should accept requests with a level, even if the developer didn't explicitely defined one" do
|
69
|
-
request = mock("request", :accept => "application/json;level=1")
|
69
|
+
request = mock("request", :accept => ["application/json;level=1"])
|
70
70
|
app = App.new(request)
|
71
71
|
app.should_not_receive(:halt)
|
72
72
|
app.test_provides!("application/json")
|
73
73
|
app.response.headers['Content-Type'].should == "application/json"
|
74
74
|
end
|
75
75
|
it "should correctly deal with widlcard characters [client-side, I]" do
|
76
|
-
request = mock("request", :accept => "application/vnd.fr.grid5000.api.*+json")
|
76
|
+
request = mock("request", :accept => ["application/vnd.fr.grid5000.api.*+json"])
|
77
77
|
app = App.new(request)
|
78
78
|
app.should_not_receive(:halt)
|
79
79
|
app.test_provides!("application/vnd.fr.grid5000.api.Cluster+json;level=1")
|
80
80
|
app.response.headers['Content-Type'].should == "application/vnd.fr.grid5000.api.Cluster+json;level=1"
|
81
81
|
end
|
82
82
|
it "should correctly deal with widlcard characters [client-side, II]" do
|
83
|
-
request = mock("request", :accept => "application/*")
|
83
|
+
request = mock("request", :accept => ["application/*"])
|
84
84
|
app = App.new(request)
|
85
85
|
app.should_not_receive(:halt)
|
86
86
|
app.test_provides!("application/vnd.fr.grid5000.api.Cluster+json;level=1")
|
87
87
|
app.response.headers['Content-Type'].should == "application/vnd.fr.grid5000.api.Cluster+json;level=1"
|
88
88
|
end
|
89
|
+
it "should description" do
|
90
|
+
|
91
|
+
end
|
89
92
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rest-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
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-10-
|
12
|
+
date: 2009-10-21 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -31,7 +31,7 @@ files:
|
|
31
31
|
- VERSION
|
32
32
|
- lib/sinatra/rest_helpers.rb
|
33
33
|
- sinatra-rest-helpers.gemspec
|
34
|
-
- spec/
|
34
|
+
- spec/sinatra_rest_helpers_spec.rb
|
35
35
|
- spec/spec_helper.rb
|
36
36
|
has_rdoc: true
|
37
37
|
homepage: http://github.com/cryx/sinatra-rest-helpers
|
@@ -62,5 +62,5 @@ signing_key:
|
|
62
62
|
specification_version: 3
|
63
63
|
summary: Adds useful helpers for REST applications developed with Sinatra.
|
64
64
|
test_files:
|
65
|
-
- spec/
|
65
|
+
- spec/sinatra_rest_helpers_spec.rb
|
66
66
|
- spec/spec_helper.rb
|