sinatra-rest-base 1.0.3 → 1.0.4
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24af1cf8be8da4b7423bf9e76473d2848e365f65
|
4
|
+
data.tar.gz: aba24043540d4645d0af30268dda2b57df333af9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e50403fb3aceec1bac42a754e9c7a313634c5c81ced7ce9c7d4a1cdbebc47dbb55b58da2221a47bbfea91ebb4e573a30d3399bd9b38fa4bfd02eea72018b2f
|
7
|
+
data.tar.gz: 2bd4bb2135d2deaa0ba284529235d3e7e330b833bd27e7c01f52d361b9e5cffcbb4dde9bd8f3e9cccd5a7db586a3cf577e8adf2200a646e610127e0a9a429c95
|
@@ -26,14 +26,18 @@ module RestBase
|
|
26
26
|
def set_request_body
|
27
27
|
read_body = request.body.read
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
begin
|
30
|
+
if read_body.empty?
|
31
|
+
@request_body = {}
|
32
|
+
elsif request.media_type.downcase == 'text/xml'
|
33
|
+
@request_body = Hash.from_xml(read_body)
|
34
|
+
@request_body = Hash[@request_body.map{ |k, v| [k.to_sym, v] }]
|
35
|
+
@request_body = @request_body[:request]
|
36
|
+
else
|
37
|
+
@request_body = JSON.parse(read_body, :symbolize_names => true)
|
38
|
+
end
|
39
|
+
rescue
|
40
|
+
raise StandardError.new("Invalid Request Body")
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
data/lib/rest_base/version.rb
CHANGED
@@ -181,6 +181,16 @@ describe RestBase::Application do
|
|
181
181
|
|
182
182
|
expect(last_response.body).to eq(@expected_hash.to_json)
|
183
183
|
end
|
184
|
+
|
185
|
+
it "should fail with bad json" do
|
186
|
+
post '/', "}", @headers
|
187
|
+
|
188
|
+
@expected_hash.delete(:result)
|
189
|
+
@expected_hash[:errors] = ["Invalid Request Body"]
|
190
|
+
|
191
|
+
expect(last_response.status).to eq(500)
|
192
|
+
expect(last_response.body).to eq(@expected_hash.to_json)
|
193
|
+
end
|
184
194
|
end
|
185
195
|
|
186
196
|
describe :xml do
|
@@ -222,5 +232,18 @@ describe RestBase::Application do
|
|
222
232
|
|
223
233
|
expect(last_response.body).to eq(@expected_hash.to_xml(:root => :response))
|
224
234
|
end
|
235
|
+
|
236
|
+
it "should fail on bad xml" do
|
237
|
+
@headers['CONTENT_TYPE'] = 'text/xml'
|
238
|
+
@headers['HTTP_ACCEPT'] = 'text/xml'
|
239
|
+
|
240
|
+
@expected_hash.delete(:result)
|
241
|
+
@expected_hash[:errors] = ["Invalid Request Body"]
|
242
|
+
|
243
|
+
post '/', "<BadXML>", @headers
|
244
|
+
|
245
|
+
expect(last_response.status).to eq(500)
|
246
|
+
expect(last_response.body).to eq(@expected_hash.to_xml(:root => :response))
|
247
|
+
end
|
225
248
|
end
|
226
249
|
end
|
@@ -33,7 +33,16 @@ describe RestBase::Application do
|
|
33
33
|
it "should provide endpoint not found error" do
|
34
34
|
@expected_body[:errors] << "Endpoint not found"
|
35
35
|
|
36
|
-
get '/
|
36
|
+
get '/idontexist', {}, @headers
|
37
|
+
|
38
|
+
expect(last_response.status).to eq(404)
|
39
|
+
expect(last_response.body).to eq(@expected_body.to_json)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should provide error 404" do
|
43
|
+
@expected_body[:errors] << "Endpoint not found"
|
44
|
+
|
45
|
+
get '/notfound', {}, @headers
|
37
46
|
|
38
47
|
expect(last_response.status).to eq(404)
|
39
48
|
expect(last_response.body).to eq(@expected_body.to_json)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rest-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bmills
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|