braque 0.1.1 → 0.1.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/braque/collection.rb +4 -1
- data/lib/braque/version.rb +1 -1
- data/spec/braque/model_spec.rb +92 -13
- data/spec/spec_helper.rb +1 -1
- 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: 7e576d0ca74ea35d912a52c67e9971a7740a0dfa
|
|
4
|
+
data.tar.gz: 5d52452de3a6ed8611a2b127ed002d5ebee8c3e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60fbbb04472b235c26ceb02490013f7b68b046478e461889a5ccaac88728aa5b51671c022dc4fcb3f74827f8f7cb85f3b37c5f0af4239f5ce53ad8bf5c14abcd
|
|
7
|
+
data.tar.gz: 0076fe9afecb8bded09adf25806d9afc920be19de40b2de2bcad5d33e3e8e13765676f793b01f96c681751e6ee1dacbb5fe96f0310d9cd0b2fabf7afbddb14f3
|
data/lib/braque/collection.rb
CHANGED
|
@@ -13,7 +13,10 @@ module Braque
|
|
|
13
13
|
response.each do |item|
|
|
14
14
|
retrieved_items << klass.new(item)
|
|
15
15
|
end
|
|
16
|
-
@retrieved_items
|
|
16
|
+
@retrieved_items = retrieved_items
|
|
17
|
+
@next_link = next_link
|
|
18
|
+
@previous_link = previous_link
|
|
19
|
+
@total_count = total_count
|
|
17
20
|
super retrieved_items
|
|
18
21
|
end
|
|
19
22
|
end
|
data/lib/braque/version.rb
CHANGED
data/spec/braque/model_spec.rb
CHANGED
|
@@ -70,6 +70,21 @@ RSpec.describe Braque::Model, type: :model do
|
|
|
70
70
|
expect(breeze.title).to eq collection_response['_embedded']['breezes'].first['title']
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
|
+
context 'with an errored response' do
|
|
74
|
+
before(:each) do
|
|
75
|
+
root_request
|
|
76
|
+
@collection_request = WebMock.stub_request(:get, "#{Breeze.api_root}/breezes")
|
|
77
|
+
.with(headers: { 'Http-Authorization' => Breeze.api_token })
|
|
78
|
+
.to_return(status: 500)
|
|
79
|
+
end
|
|
80
|
+
it 'returns a Faraday::ClientError error' do
|
|
81
|
+
expect do
|
|
82
|
+
Breeze.list
|
|
83
|
+
end.to raise_error(Faraday::ClientError, 'the server responded with status 500')
|
|
84
|
+
expect(root_request).to have_been_requested
|
|
85
|
+
expect(@collection_request).to have_been_requested
|
|
86
|
+
end
|
|
87
|
+
end
|
|
73
88
|
context 'with array params' do
|
|
74
89
|
before(:each) do
|
|
75
90
|
root_request
|
|
@@ -108,6 +123,21 @@ RSpec.describe Braque::Model, type: :model do
|
|
|
108
123
|
expect(@breeze.title).to eq resource_response['title']
|
|
109
124
|
end
|
|
110
125
|
end
|
|
126
|
+
context 'with an errored response' do
|
|
127
|
+
before(:each) do
|
|
128
|
+
root_request
|
|
129
|
+
@resource_request = WebMock.stub_request(:get, "#{Breeze.api_root}/breezes/1")
|
|
130
|
+
.with(headers: { 'Http-Authorization' => Breeze.api_token })
|
|
131
|
+
.to_return(status: 500)
|
|
132
|
+
end
|
|
133
|
+
it 'returns a Faraday::ClientError error' do
|
|
134
|
+
expect do
|
|
135
|
+
@breeze = Breeze.find id: 1
|
|
136
|
+
end.to raise_error(Faraday::ClientError, 'the server responded with status 500')
|
|
137
|
+
expect(root_request).to have_been_requested
|
|
138
|
+
expect(@resource_request).to have_been_requested
|
|
139
|
+
end
|
|
140
|
+
end
|
|
111
141
|
context 'when overriding resource_find_options' do
|
|
112
142
|
before(:each) do
|
|
113
143
|
class Breeze
|
|
@@ -140,27 +170,44 @@ RSpec.describe Braque::Model, type: :model do
|
|
|
140
170
|
end
|
|
141
171
|
|
|
142
172
|
context '.create' do
|
|
173
|
+
context 'with a successful response' do
|
|
174
|
+
before(:each) do
|
|
175
|
+
root_request
|
|
176
|
+
@create_request = WebMock.stub_request(:post, "#{Breeze.api_root}/breezes")
|
|
177
|
+
.with(headers: { 'Http-Authorization' => Breeze.api_token })
|
|
178
|
+
.to_return(status: 201, body: resource_response)
|
|
179
|
+
@params = { title: 'What a nice breeze.' }
|
|
180
|
+
@breeze = Breeze.create(@params)
|
|
181
|
+
end
|
|
182
|
+
it 'performs the API root request' do
|
|
183
|
+
expect(root_request).to have_been_requested
|
|
184
|
+
end
|
|
185
|
+
it 'performs the create request' do
|
|
186
|
+
expect(@create_request).to have_been_requested
|
|
187
|
+
end
|
|
188
|
+
it 'returns an item with the correct class' do
|
|
189
|
+
expect(@breeze).to be_a_kind_of Breeze
|
|
190
|
+
end
|
|
191
|
+
it 'returns an item with the correct attributes' do
|
|
192
|
+
expect(@breeze.id).to eq resource_response['id']
|
|
193
|
+
expect(@breeze.title).to eq resource_response['title']
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
context 'with an errored response' do
|
|
143
198
|
before(:each) do
|
|
144
199
|
root_request
|
|
145
200
|
@create_request = WebMock.stub_request(:post, "#{Breeze.api_root}/breezes")
|
|
146
201
|
.with(headers: { 'Http-Authorization' => Breeze.api_token })
|
|
147
|
-
.to_return(status:
|
|
148
|
-
@params = { title: 'What a nice breeze.' }
|
|
149
|
-
@breeze = Breeze.create(@params)
|
|
202
|
+
.to_return(status: 500)
|
|
150
203
|
end
|
|
151
|
-
it '
|
|
204
|
+
it 'returns a Faraday::ClientError error' do
|
|
205
|
+
expect do
|
|
206
|
+
Breeze.create {}
|
|
207
|
+
end.to raise_error(Faraday::ClientError, 'the server responded with status 500')
|
|
152
208
|
expect(root_request).to have_been_requested
|
|
153
|
-
end
|
|
154
|
-
it 'performs the create request' do
|
|
155
209
|
expect(@create_request).to have_been_requested
|
|
156
210
|
end
|
|
157
|
-
it 'returns an item with the correct class' do
|
|
158
|
-
expect(@breeze).to be_a_kind_of Breeze
|
|
159
|
-
end
|
|
160
|
-
it 'returns an item with the correct attributes' do
|
|
161
|
-
expect(@breeze.id).to eq resource_response['id']
|
|
162
|
-
expect(@breeze.title).to eq resource_response['title']
|
|
163
|
-
end
|
|
164
211
|
end
|
|
165
212
|
end
|
|
166
213
|
context 'instance methods' do
|
|
@@ -193,6 +240,22 @@ RSpec.describe Braque::Model, type: :model do
|
|
|
193
240
|
end
|
|
194
241
|
end
|
|
195
242
|
|
|
243
|
+
context 'with an errored response' do
|
|
244
|
+
before(:each) do
|
|
245
|
+
root_request
|
|
246
|
+
@save_request = WebMock.stub_request(:patch, "#{Breeze.api_root}/breezes/1")
|
|
247
|
+
.with(headers: { 'Http-Authorization' => Breeze.api_token })
|
|
248
|
+
.to_return(status: 500)
|
|
249
|
+
end
|
|
250
|
+
it 'returns a Faraday::ClientError error' do
|
|
251
|
+
expect do
|
|
252
|
+
Breeze.new(id: 1).save(@params)
|
|
253
|
+
end.to raise_error(Faraday::ClientError, 'the server responded with status 500')
|
|
254
|
+
expect(root_request).to have_been_requested
|
|
255
|
+
expect(@save_request).to have_been_requested
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
196
259
|
context 'when overriding resource_find_options' do
|
|
197
260
|
before(:each) do
|
|
198
261
|
class Breeze
|
|
@@ -245,6 +308,22 @@ RSpec.describe Braque::Model, type: :model do
|
|
|
245
308
|
end
|
|
246
309
|
end
|
|
247
310
|
|
|
311
|
+
context 'with an errored response' do
|
|
312
|
+
before(:each) do
|
|
313
|
+
root_request
|
|
314
|
+
@destroy_request = WebMock.stub_request(:delete, "#{Breeze.api_root}/breezes/1")
|
|
315
|
+
.with(headers: { 'Http-Authorization' => Breeze.api_token })
|
|
316
|
+
.to_return(status: 500)
|
|
317
|
+
end
|
|
318
|
+
it 'returns a Faraday::ClientError error' do
|
|
319
|
+
expect do
|
|
320
|
+
Breeze.new(id: 1).destroy
|
|
321
|
+
end.to raise_error(Faraday::ClientError, 'the server responded with status 500')
|
|
322
|
+
expect(root_request).to have_been_requested
|
|
323
|
+
expect(@destroy_request).to have_been_requested
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
248
327
|
context 'when overriding resource_find_options' do
|
|
249
328
|
before(:each) do
|
|
250
329
|
class Breeze
|
data/spec/spec_helper.rb
CHANGED
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.1.
|
|
4
|
+
version: 0.1.2
|
|
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-08-
|
|
11
|
+
date: 2015-08-15 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.
|
|
101
|
+
rubygems_version: 2.4.3
|
|
102
102
|
signing_key:
|
|
103
103
|
specification_version: 4
|
|
104
104
|
summary: Braque provides a simple interface for interacting with Hypermedia API services
|