restful_resource 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/restful_resource/base.rb +5 -3
- data/lib/restful_resource/version.rb +1 -1
- data/spec/restful_resource/base_spec.rb +3 -4
- data/spec/spec_helper.rb +3 -3
- 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: cc4d1bbfdde924c3b2091f258b2ae0291fa95137
|
4
|
+
data.tar.gz: 2fed2298a294dabe54584bf05aa49f9c4ed51e3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 834ce402bc491c69f8def4d3cba41adfa5e837a3e83265ac1b2520f3f0133624753521f3f4f2008551ea783c62d731c341d81a8799e88f40b9df11c1b5c68031
|
7
|
+
data.tar.gz: f322f3af95316c4b5e470ffa0115015f7bc4495aba2c71fe83716db8a55adfa4d6336104073386ca0d83b98ed1d76fc933338c9347f2f1b2c7eb16826bcbc7be
|
@@ -38,7 +38,9 @@ module RestfulResource
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.put(id, data: {}, **params)
|
41
|
-
|
41
|
+
url = member_url(id, params)
|
42
|
+
|
43
|
+
response = http.put(url, data: data)
|
42
44
|
self.new(parse_json(response.body))
|
43
45
|
end
|
44
46
|
|
@@ -71,7 +73,7 @@ module RestfulResource
|
|
71
73
|
|
72
74
|
private
|
73
75
|
def self.merge_url_paths(uri, *paths)
|
74
|
-
uri.merge(paths.compact.join('/')).to_s
|
76
|
+
uri.merge(paths.compact.join('/')).to_s
|
75
77
|
end
|
76
78
|
|
77
79
|
def self.member_url(id, params)
|
@@ -80,7 +82,7 @@ module RestfulResource
|
|
80
82
|
end
|
81
83
|
|
82
84
|
def self.collection_url(params)
|
83
|
-
url = merge_url_paths(superclass.base_url, @resource_path, @action_prefix)
|
85
|
+
url = merge_url_paths(superclass.base_url, @resource_path, @action_prefix)
|
84
86
|
replace_parameters(url, params)
|
85
87
|
end
|
86
88
|
|
@@ -139,18 +139,18 @@ describe RestfulResource::Base do
|
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'should put data with no params passed' do
|
142
|
-
data = {make_slug: 'Audi'}
|
142
|
+
data = {make_slug: 'Audi'}
|
143
143
|
|
144
144
|
expected_response = RestfulResource::Response.new(body: {name: 'Audi'}.to_json, status: 200)
|
145
145
|
expect_put('http://api.carwow.co.uk/makes/1', expected_response, data: data)
|
146
146
|
|
147
|
-
object = Make.put(1, data:
|
147
|
+
object = Make.put(1, data: {make_slug: 'Audi'})
|
148
148
|
|
149
149
|
expect(object.name).to eq 'Audi'
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'should put data with params passed' do
|
153
|
-
data = {make_slug: 'Audi'}
|
153
|
+
data = {make_slug: 'Audi'}
|
154
154
|
|
155
155
|
expected_response = RestfulResource::Response.new(body: {name: 'Audi'}.to_json, status: 200)
|
156
156
|
expect_put('http://api.carwow.co.uk/makes/1?make_slug=Volkswagen', expected_response, data: data)
|
@@ -183,4 +183,3 @@ describe RestfulResource::Base do
|
|
183
183
|
headers: { links: '<http://api.carwow.co.uk/makes/Volkswagen/models.json?page=6>;rel="last",<http://api.carwow.co.uk/makes/Volkswagen/models.json?page=2>;rel="next"'})
|
184
184
|
end
|
185
185
|
end
|
186
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'fixtures'
|
|
4
4
|
|
5
5
|
RSpec.configure do |config|
|
6
6
|
config.color = true
|
7
|
-
config.formatter = :progress
|
7
|
+
config.formatter = :progress
|
8
8
|
end
|
9
9
|
|
10
10
|
|
@@ -13,11 +13,11 @@ def expect_get(url, response)
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def expect_put(url, response, data: {})
|
16
|
-
expect(@mock_http).to receive(:put).with(url, data).and_return(response)
|
16
|
+
expect(@mock_http).to receive(:put).with(url, data: data).and_return(response)
|
17
17
|
end
|
18
18
|
|
19
19
|
def expect_put_with_unprocessable_entity(url, response, data: {})
|
20
20
|
rest_client_response = OpenStruct.new({body: response.body, headers: response.headers, code: response.status})
|
21
21
|
exception = RestfulResource::HttpClient::UnprocessableEntity.new(rest_client_response)
|
22
|
-
expect(@mock_http).to receive(:put).with(url, data).and_raise(exception)
|
22
|
+
expect(@mock_http).to receive(:put).with(url, data: data).and_raise(exception)
|
23
23
|
end
|