sinatra-rest-base 1.0.1 → 1.0.2
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 +4 -4
- data/lib/rest_base/application.rb +6 -1
- data/lib/rest_base/version.rb +1 -1
- data/spec/fixtures/test_application.rb +16 -0
- data/spec/lib/rest_base/application_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e4c051e044943fb538e806a31e6330b75b89fc8
|
4
|
+
data.tar.gz: a6af540e82d2a48a635e4d45c882efd9c33053fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 838b719f9a9f5d39a07d160249e2207cbe6156f72b5ac03a6a254c197e135e52e2cf207b6b232185fc141e25776ecc90fd876f274f8a3f4468118d47fee4bb3e
|
7
|
+
data.tar.gz: e511cf7ac1853a6cc368be5ec05226976f72561ea59933be66a1701c0deccbaf832d3d84e16772a2a9257917eebb89d2c66eea9ce55411f24543a27959ba1277
|
@@ -24,6 +24,12 @@ module RestBase
|
|
24
24
|
has_version?("version=#{value}")
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
set(:method) do |method|
|
29
|
+
condition do
|
30
|
+
request.request_method.downcase.to_sym == method.to_s.downcase.to_sym
|
31
|
+
end
|
32
|
+
end
|
27
33
|
|
28
34
|
before do
|
29
35
|
status 200
|
@@ -37,7 +43,6 @@ module RestBase
|
|
37
43
|
after do
|
38
44
|
response.body = nil if response.body.is_a?(Array) && response.body.length == 1 && response.body[0].empty?
|
39
45
|
response.body = create_response()
|
40
|
-
|
41
46
|
response.headers['Content-Type'] += ";version=#{@request_version}"
|
42
47
|
end
|
43
48
|
end
|
data/lib/rest_base/version.rb
CHANGED
@@ -6,6 +6,22 @@ module RestBase
|
|
6
6
|
set :authentication, RestBase::Authentication::BasicAuthentication.new(['key1', 'key2'])
|
7
7
|
enable :header_versioning
|
8
8
|
end
|
9
|
+
|
10
|
+
before '/method_filter', :method => :get do
|
11
|
+
@method_response = []
|
12
|
+
@method_response << "Hit Before Filter"
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/method_filter' do
|
16
|
+
@method_response << "Response Filtered"
|
17
|
+
@method_response
|
18
|
+
end
|
19
|
+
|
20
|
+
put '/method_filter' do
|
21
|
+
@method_response = []
|
22
|
+
@method_response << "Response Filtered"
|
23
|
+
@method_response
|
24
|
+
end
|
9
25
|
end
|
10
26
|
end
|
11
27
|
end
|
@@ -38,6 +38,20 @@ describe RestBase::Application do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
describe :method do
|
42
|
+
it "should go through the before filter" do
|
43
|
+
get '/method_filter', {}, @headers
|
44
|
+
|
45
|
+
expect(last_response.body).to eq({:result => ["Hit Before Filter", "Response Filtered"]}.to_json)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not go through the before filter" do
|
49
|
+
put '/method_filter', {}, @headers
|
50
|
+
|
51
|
+
expect(last_response.body).to eq({:result => ["Response Filtered"]}.to_json)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
41
55
|
describe :authorization do
|
42
56
|
it "should try to authorize" do
|
43
57
|
get '/', {}, @headers
|