restfulness 0.2.6 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/lib/restfulness/resource.rb +1 -1
- data/lib/restfulness/response.rb +2 -2
- data/lib/restfulness/version.rb +1 -1
- data/spec/unit/resource_spec.rb +2 -2
- data/spec/unit/response_spec.rb +4 -3
- data/spec/unit/router_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c75c4e41bde16b35b2e5ea93df0958073b8d114
|
4
|
+
data.tar.gz: 4d72d5c989d8d4cc1fdabdeb92475a07ee0e354a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78f392d57d5d9c64fc446def406f99fe12fdad295ad415bf15a9f3d7c789def2b304face6fc1e1a60f7db8dc256002aa6bce2a936e46f69b07abdfef1046183
|
7
|
+
data.tar.gz: 198200ae4575a6f756a75b142c4d07683cd1f4105cf8cd317603c018491c3d5644c5add334fbdcbeb4251b529bf6b4d648c1eb44e4256a04e1904b05c9365516
|
data/README.md
CHANGED
@@ -246,7 +246,7 @@ Resources also have support for simple set of built-in callbacks. These have sim
|
|
246
246
|
|
247
247
|
The supported callbacks are:
|
248
248
|
|
249
|
-
* `exists?` - True by default, not called in create actions like POST.
|
249
|
+
* `exists?` - True by default, not called in create actions like POST or PUT.
|
250
250
|
* `authorized?` - True by default, is the current user valid?
|
251
251
|
* `allowed?` - True by default, does the current have access to the resource?
|
252
252
|
* `last_modified` - The date of last update on the model, only called for GET and HEAD requests. Validated against the `If-Modified-Since` header.
|
@@ -331,8 +331,8 @@ request.path[0] # 'project
|
|
331
331
|
request.path.to_s # '/project/123456/task/234567'
|
332
332
|
request.path # ['project', '123456', 'task', '234567']
|
333
333
|
request.path[:id] # '234567'
|
334
|
-
|
335
|
-
|
334
|
+
request.path[:project_id] # '123456'
|
335
|
+
request.path[2] # 'task'
|
336
336
|
|
337
337
|
# The request query
|
338
338
|
request.query # {:page => 1} - Hash with indifferent access
|
@@ -618,6 +618,11 @@ Restfulness is still a work in progress but at Cabify we are using it in product
|
|
618
618
|
|
619
619
|
## History
|
620
620
|
|
621
|
+
### 0.3.0 - May 13, 2014
|
622
|
+
|
623
|
+
* Possible breaking change: `put` requests no longer check for existing resource via `exists?` callback. (@samlown)
|
624
|
+
* Avoid Rack Lint errors by not providing Content-Type or Length in empty responses. (@samlown)
|
625
|
+
|
621
626
|
### 0.2.6 - March 7, 2014
|
622
627
|
|
623
628
|
* Support scope block when adding a resource to router. (@samlown)
|
data/lib/restfulness/resource.rb
CHANGED
@@ -60,7 +60,7 @@ module Restfulness
|
|
60
60
|
forbidden! unless allowed?
|
61
61
|
|
62
62
|
# The following callbacks only make sense for certain methods
|
63
|
-
if [:head, :get, :
|
63
|
+
if [:head, :get, :patch, :delete].include?(request.action)
|
64
64
|
resource_not_found! unless exists?
|
65
65
|
|
66
66
|
if [:get, :head].include?(request.action)
|
data/lib/restfulness/response.rb
CHANGED
@@ -70,10 +70,10 @@ module Restfulness
|
|
70
70
|
def payload=(body)
|
71
71
|
if body.nil? || body.is_a?(String)
|
72
72
|
@payload = body.to_s
|
73
|
-
update_content_headers(:text)
|
73
|
+
update_content_headers(:text) unless @payload.empty?
|
74
74
|
else
|
75
75
|
@payload = MultiJson.encode(body)
|
76
|
-
update_content_headers(:json)
|
76
|
+
update_content_headers(:json) unless @payload.empty?
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
data/lib/restfulness/version.rb
CHANGED
data/spec/unit/resource_spec.rb
CHANGED
@@ -142,7 +142,7 @@ describe Restfulness::Resource do
|
|
142
142
|
}.to raise_error(Restfulness::HTTPException, "Method Not Allowed")
|
143
143
|
end
|
144
144
|
|
145
|
-
[:head, :get, :
|
145
|
+
[:head, :get, :patch, :delete].each do |action|
|
146
146
|
it "should raise error when not exists for #{action.to_s.upcase}" do
|
147
147
|
request.action = action
|
148
148
|
obj.stub(:exists?).and_return(false)
|
@@ -152,7 +152,7 @@ describe Restfulness::Resource do
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
[:post].each do |action|
|
155
|
+
[:put, :post].each do |action|
|
156
156
|
it "should not check exists? for #{action.to_s.upcase}" do
|
157
157
|
obj.request.action = action
|
158
158
|
obj.should_not_receive(:exists?)
|
data/spec/unit/response_spec.rb
CHANGED
@@ -40,8 +40,8 @@ describe Restfulness::Response do
|
|
40
40
|
obj.run
|
41
41
|
obj.status.should eql(404)
|
42
42
|
obj.payload.should be_empty
|
43
|
-
obj.headers['Content-Type'].should
|
44
|
-
obj.headers['Content-Length'].should
|
43
|
+
obj.headers['Content-Type'].should be_nil
|
44
|
+
obj.headers['Content-Length'].should be_nil
|
45
45
|
end
|
46
46
|
end
|
47
47
|
context "with route" do
|
@@ -75,7 +75,8 @@ describe Restfulness::Response do
|
|
75
75
|
route.stub(:build_resource).and_return(resource)
|
76
76
|
obj.run
|
77
77
|
obj.status.should eql(204)
|
78
|
-
obj.headers['Content-Type'].should
|
78
|
+
obj.headers['Content-Type'].should be_nil
|
79
|
+
obj.headers['Content-Length'].should be_nil
|
79
80
|
end
|
80
81
|
|
81
82
|
it "should set string content type if payload is a string" do
|
data/spec/unit/router_spec.rb
CHANGED
@@ -48,10 +48,10 @@ describe Restfulness::Router do
|
|
48
48
|
add 'examples', SecondRouterResource
|
49
49
|
end
|
50
50
|
route = obj.routes.first
|
51
|
-
route.resource.should eql(
|
51
|
+
route.resource.should eql(SecondRouterResource)
|
52
52
|
route.path.should eql(['project', 'examples'])
|
53
53
|
route = obj.routes.last
|
54
|
-
route.resource.should eql(
|
54
|
+
route.resource.should eql(RouterResource)
|
55
55
|
route.path.should eql(['project'])
|
56
56
|
end
|
57
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restfulness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Lown
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|