braque 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/braque/model.rb +7 -3
- data/lib/braque/version.rb +1 -1
- data/spec/braque/model_spec.rb +96 -64
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d74d0cde5c073286613ad279b4221f967934c72
|
4
|
+
data.tar.gz: a296e958733e8c9036709d63085dc0950b113ec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2b799f95dbd2f03e2e01e4cd8d2ee0f7332edadc5988b512e01e352f6819a0f6ebb05cda6fb214f8638894df84d98b16f2b951c4e4ad20f040a80fc5788187
|
7
|
+
data.tar.gz: 2accbbe9c093abff560a73b6c596eb9890910b90cda5c1b2f84f75e7246cc3d9c4257b52d1cb9b047e5e1609ed5f2d321c5029ecaf48e631b94fe9c2f250ed18
|
data/lib/braque/model.rb
CHANGED
@@ -90,9 +90,13 @@ module Braque
|
|
90
90
|
new response
|
91
91
|
end
|
92
92
|
|
93
|
-
def create(
|
94
|
-
response = client.method(collection_method_name)
|
95
|
-
.
|
93
|
+
def create(resource_params = {}, options = {})
|
94
|
+
response = client.method(collection_method_name)
|
95
|
+
.call
|
96
|
+
._post(
|
97
|
+
{ "#{instance_method_name}" => resource_params }
|
98
|
+
.merge(options)
|
99
|
+
)
|
96
100
|
new response
|
97
101
|
end
|
98
102
|
|
data/lib/braque/version.rb
CHANGED
data/spec/braque/model_spec.rb
CHANGED
@@ -21,15 +21,15 @@ RSpec.describe Braque::Model, type: :model do
|
|
21
21
|
|
22
22
|
let(:root_request) do
|
23
23
|
WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/")
|
24
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
25
|
-
|
24
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
25
|
+
'Accept' => Breeze.config[:accept_header] })
|
26
26
|
.to_return(status: 200, body: root_response)
|
27
27
|
end
|
28
28
|
|
29
29
|
let(:root_request_with_token_resource_path) do
|
30
30
|
WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/")
|
31
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
32
|
-
|
31
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
32
|
+
'Accept' => Breeze.config[:accept_header] })
|
33
33
|
.to_return(status: 200, body: root_response_with_token_resource_path)
|
34
34
|
end
|
35
35
|
|
@@ -48,11 +48,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
48
48
|
|
49
49
|
context '.list' do
|
50
50
|
context 'with results' do
|
51
|
-
before
|
51
|
+
before do
|
52
52
|
root_request
|
53
53
|
@collection_request = WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/breezes")
|
54
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
55
|
-
|
54
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
55
|
+
'Accept' => Breeze.config[:accept_header] })
|
56
56
|
.to_return(status: 200, body: collection_response)
|
57
57
|
@breezes = Breeze.list
|
58
58
|
end
|
@@ -81,11 +81,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
context 'with an errored response' do
|
84
|
-
before
|
84
|
+
before do
|
85
85
|
root_request
|
86
86
|
@collection_request = WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/breezes")
|
87
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
88
|
-
|
87
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
88
|
+
'Accept' => Breeze.config[:accept_header] })
|
89
89
|
.to_return(status: 500)
|
90
90
|
end
|
91
91
|
it 'returns a Faraday::ClientError error' do
|
@@ -97,11 +97,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
context 'with array params' do
|
100
|
-
before
|
100
|
+
before do
|
101
101
|
root_request
|
102
102
|
@collection_request = WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/breezes")
|
103
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
104
|
-
|
103
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
104
|
+
'Accept' => Breeze.config[:accept_header] })
|
105
105
|
.with(query: 'ids%5B0%5D=1&ids%5B1%5D=2')
|
106
106
|
.to_return(status: 200, body: collection_response)
|
107
107
|
@breezes = Breeze.list('ids[]' => [1, 2])
|
@@ -114,11 +114,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
114
114
|
|
115
115
|
context '.find' do
|
116
116
|
context 'under normal conditions' do
|
117
|
-
before
|
117
|
+
before do
|
118
118
|
root_request
|
119
119
|
@resource_request = WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/breezes/1")
|
120
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
121
|
-
|
120
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
121
|
+
'Accept' => Breeze.config[:accept_header] })
|
122
122
|
.to_return(status: 200, body: resource_response)
|
123
123
|
@breeze = Breeze.find(id: 1)
|
124
124
|
end
|
@@ -137,11 +137,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
context 'with an errored response' do
|
140
|
-
before
|
140
|
+
before do
|
141
141
|
root_request
|
142
142
|
@resource_request = WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/breezes/1")
|
143
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
144
|
-
|
143
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
144
|
+
'Accept' => Breeze.config[:accept_header] })
|
145
145
|
.to_return(status: 500)
|
146
146
|
end
|
147
147
|
it 'returns a Faraday::ClientError error' do
|
@@ -152,8 +152,9 @@ RSpec.describe Braque::Model, type: :model do
|
|
152
152
|
expect(@resource_request).to have_been_requested
|
153
153
|
end
|
154
154
|
end
|
155
|
+
|
155
156
|
context 'when overriding resource_find_options' do
|
156
|
-
before
|
157
|
+
before do
|
157
158
|
class Breeze
|
158
159
|
def resource_find_options
|
159
160
|
{ id: id, token: token }
|
@@ -162,8 +163,8 @@ RSpec.describe Braque::Model, type: :model do
|
|
162
163
|
|
163
164
|
root_request_with_token_resource_path
|
164
165
|
@resource_request = WebMock.stub_request(:get, "#{Breeze.config[:api_root_url]}/breezes/1?token=123")
|
165
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
166
|
-
|
166
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
167
|
+
'Accept' => Breeze.config[:accept_header] })
|
167
168
|
.to_return(status: 200, body: resource_response)
|
168
169
|
@breeze = Breeze.find(id: 1, token: 123)
|
169
170
|
end
|
@@ -186,37 +187,68 @@ RSpec.describe Braque::Model, type: :model do
|
|
186
187
|
|
187
188
|
context '.create' do
|
188
189
|
context 'with a successful response' do
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
190
|
+
context 'without additional options' do
|
191
|
+
before do
|
192
|
+
root_request
|
193
|
+
@create_request = WebMock.stub_request(:post, "#{Breeze.config[:api_root_url]}/breezes")
|
194
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
195
|
+
'Accept' => Breeze.config[:accept_header] })
|
196
|
+
.to_return(status: 201, body: resource_response)
|
197
|
+
@params = { title: 'What a nice breeze.' }
|
198
|
+
@breeze = Breeze.create(@params)
|
199
|
+
end
|
200
|
+
it 'performs the API root request' do
|
201
|
+
expect(root_request).to have_been_requested
|
202
|
+
end
|
203
|
+
it 'performs the create request' do
|
204
|
+
expect(@create_request).to have_been_requested
|
205
|
+
end
|
206
|
+
it 'returns an item with the correct class' do
|
207
|
+
expect(@breeze).to be_a_kind_of Breeze
|
208
|
+
end
|
209
|
+
it 'returns an item with the correct attributes' do
|
210
|
+
expect(@breeze.id).to eq resource_response['id']
|
211
|
+
expect(@breeze.title).to eq resource_response['title']
|
212
|
+
end
|
206
213
|
end
|
207
|
-
|
208
|
-
|
209
|
-
|
214
|
+
context 'with additional options' do
|
215
|
+
before do
|
216
|
+
root_request
|
217
|
+
@params = { title: 'What a nice breeze.' }
|
218
|
+
@subdomain = 'breezey'
|
219
|
+
@create_request = WebMock.stub_request(:post, "#{Breeze.config[:api_root_url]}/breezes")
|
220
|
+
.with(headers: {
|
221
|
+
'Http-Authorization' => Breeze.config[:http_authorization_header],
|
222
|
+
'Accept' => Breeze.config[:accept_header]
|
223
|
+
})
|
224
|
+
.with(body: '{"breeze":{"title":"What a nice breeze."},"subdomain":"breezey"}')
|
225
|
+
.to_return(status: 201, body: resource_response)
|
226
|
+
@breeze = Breeze.create(@params, subdomain: @subdomain)
|
227
|
+
end
|
228
|
+
it 'performs the API root request' do
|
229
|
+
expect(root_request).to have_been_requested
|
230
|
+
end
|
231
|
+
it 'performs the create request' do
|
232
|
+
expect(@create_request).to have_been_requested
|
233
|
+
end
|
234
|
+
it 'returns an item with the correct class' do
|
235
|
+
expect(@breeze).to be_a_kind_of Breeze
|
236
|
+
end
|
237
|
+
it 'returns an item with the correct attributes' do
|
238
|
+
expect(@breeze.id).to eq resource_response['id']
|
239
|
+
expect(@breeze.title).to eq resource_response['title']
|
240
|
+
end
|
210
241
|
end
|
211
242
|
end
|
212
243
|
end
|
213
244
|
context 'with an errored response' do
|
214
|
-
before
|
245
|
+
before do
|
215
246
|
root_request
|
216
247
|
@create_request = WebMock.stub_request(:post, "#{Breeze.config[:api_root_url]}/breezes")
|
217
|
-
.with(headers: {
|
218
|
-
|
219
|
-
|
248
|
+
.with(headers: {
|
249
|
+
'Http-Authorization' => Breeze.config[:http_authorization_header],
|
250
|
+
'Accept' => Breeze.config[:accept_header]
|
251
|
+
}).to_return(status: 500)
|
220
252
|
end
|
221
253
|
it 'returns a Faraday::ClientError error' do
|
222
254
|
expect do
|
@@ -234,11 +266,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
234
266
|
|
235
267
|
context '#save' do
|
236
268
|
context 'under normal conditions' do
|
237
|
-
before
|
269
|
+
before do
|
238
270
|
root_request
|
239
271
|
@save_request = WebMock.stub_request(:patch, "#{Breeze.config[:api_root_url]}/breezes/1")
|
240
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
241
|
-
|
272
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
273
|
+
'Accept' => Breeze.config[:accept_header] })
|
242
274
|
.to_return(status: 200, body: resource_response)
|
243
275
|
@params = { title: 'What a nice breeze.' }
|
244
276
|
@breeze = Breeze.new(id: 1).save(@params)
|
@@ -259,11 +291,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
259
291
|
end
|
260
292
|
|
261
293
|
context 'with an errored response' do
|
262
|
-
before
|
294
|
+
before do
|
263
295
|
root_request
|
264
296
|
@save_request = WebMock.stub_request(:patch, "#{Breeze.config[:api_root_url]}/breezes/1")
|
265
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
266
|
-
|
297
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
298
|
+
'Accept' => Breeze.config[:accept_header] })
|
267
299
|
.to_return(status: 500)
|
268
300
|
end
|
269
301
|
it 'returns a Faraday::ClientError error' do
|
@@ -276,7 +308,7 @@ RSpec.describe Braque::Model, type: :model do
|
|
276
308
|
end
|
277
309
|
|
278
310
|
context 'when overriding resource_find_options' do
|
279
|
-
before
|
311
|
+
before do
|
280
312
|
class Breeze
|
281
313
|
def resource_find_options
|
282
314
|
{ id: id, token: token }
|
@@ -285,8 +317,8 @@ RSpec.describe Braque::Model, type: :model do
|
|
285
317
|
|
286
318
|
root_request_with_token_resource_path
|
287
319
|
@save_request = WebMock.stub_request(:patch, "#{Breeze.config[:api_root_url]}/breezes/1?token=123")
|
288
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
289
|
-
|
320
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
321
|
+
'Accept' => Breeze.config[:accept_header] })
|
290
322
|
.to_return(status: 200, body: resource_response)
|
291
323
|
@params = { title: 'What a nice breeze.' }
|
292
324
|
@breeze = Breeze.new(id: 1, token: 123).save(@params)
|
@@ -313,11 +345,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
313
345
|
|
314
346
|
context '#destroy' do
|
315
347
|
context 'under normal conditions' do
|
316
|
-
before
|
348
|
+
before do
|
317
349
|
root_request
|
318
350
|
@destroy_request = WebMock.stub_request(:delete, "#{Breeze.config[:api_root_url]}/breezes/1")
|
319
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
320
|
-
|
351
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
352
|
+
'Accept' => Breeze.config[:accept_header] })
|
321
353
|
.to_return(status: 200)
|
322
354
|
@breeze = Breeze.new(id: 1).destroy
|
323
355
|
end
|
@@ -330,11 +362,11 @@ RSpec.describe Braque::Model, type: :model do
|
|
330
362
|
end
|
331
363
|
|
332
364
|
context 'with an errored response' do
|
333
|
-
before
|
365
|
+
before do
|
334
366
|
root_request
|
335
367
|
@destroy_request = WebMock.stub_request(:delete, "#{Breeze.config[:api_root_url]}/breezes/1")
|
336
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
337
|
-
|
368
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
369
|
+
'Accept' => Breeze.config[:accept_header] })
|
338
370
|
.to_return(status: 500)
|
339
371
|
end
|
340
372
|
it 'returns a Faraday::ClientError error' do
|
@@ -347,7 +379,7 @@ RSpec.describe Braque::Model, type: :model do
|
|
347
379
|
end
|
348
380
|
|
349
381
|
context 'when overriding resource_find_options' do
|
350
|
-
before
|
382
|
+
before do
|
351
383
|
class Breeze
|
352
384
|
def resource_find_options
|
353
385
|
{ id: id, token: token }
|
@@ -356,8 +388,8 @@ RSpec.describe Braque::Model, type: :model do
|
|
356
388
|
|
357
389
|
root_request_with_token_resource_path
|
358
390
|
@destroy_request = WebMock.stub_request(:delete, "#{Breeze.config[:api_root_url]}/breezes/1?token=123")
|
359
|
-
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header]
|
360
|
-
|
391
|
+
.with(headers: { 'Http-Authorization' => Breeze.config[:http_authorization_header],
|
392
|
+
'Accept' => Breeze.config[:accept_header] })
|
361
393
|
.to_return(status: 200)
|
362
394
|
@breeze = Breeze.new(id: 1, token: 123).destroy
|
363
395
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Fareed
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hyperclient
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.4.
|
101
|
+
rubygems_version: 2.4.5.1
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Braque provides a simple interface for interacting with Hypermedia API services
|