desk_api 0.5.8 → 0.6.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/README.md +274 -120
  4. data/lib/desk_api.rb +2 -2
  5. data/lib/desk_api/client.rb +6 -1
  6. data/lib/desk_api/configuration.rb +34 -26
  7. data/lib/desk_api/request/encode_json.rb +11 -0
  8. data/lib/desk_api/request/oauth.rb +20 -0
  9. data/lib/desk_api/request/retry.rb +37 -42
  10. data/lib/desk_api/resource.rb +86 -22
  11. data/lib/desk_api/response/parse_dates.rb +28 -0
  12. data/lib/desk_api/response/parse_json.rb +9 -0
  13. data/lib/desk_api/response/raise_error.rb +11 -16
  14. data/lib/desk_api/version.rb +1 -1
  15. data/spec/cassettes/DeskApi_Resource/_all/iterates_over_each_resource_on_each_page.yml +1953 -0
  16. data/spec/cassettes/DeskApi_Resource/_each_page/iterates_over_each_page.yml +1953 -0
  17. data/spec/cassettes/DeskApi_Resource/_each_page/raises_NoMethodError_is_called_on_non-page_resources.yml +207 -0
  18. data/spec/cassettes/DeskApi_Resource/_each_page/uses_a_default_per_page_of_1000.yml +1953 -0
  19. data/spec/cassettes/DeskApi_Resource/_load/loads_the_resource_if_not_already_loaded.yml +205 -0
  20. data/spec/cassettes/DeskApi_Resource/_loaded_/returns_true_if_the_resource_is_loaded.yml +205 -0
  21. data/spec/cassettes/DeskApi_Resource/_next_/changes__definition_to_next_page.yml +407 -0
  22. data/spec/cassettes/DeskApi_Resource/_next_/returns_nil_on_the_last_page.yml +315 -0
  23. data/spec/cassettes/DeskApi_Resource/_request/sends_request_through_a_client_and_returns_Faraday_Response.yml +207 -0
  24. data/spec/cassettes/DeskApi_Resource/_reset_/sets__links__embedded__changed_and__loaded_to_default_values.yml +253 -0
  25. data/spec/cassettes/DeskApi_Resource/_to_hash/converts_embedded_resources_to_hashes.yml +251 -0
  26. data/spec/cassettes/DeskApi_Resource/_to_hash/returns_a_hash_for_a_desk_resource.yml +66 -0
  27. data/spec/cassettes/DeskApi_Resource/_update/can_handle_action_params.yml +427 -0
  28. data/spec/desk_api/client_spec.rb +23 -17
  29. data/spec/desk_api/configuration_spec.rb +49 -41
  30. data/spec/desk_api/default_spec.rb +3 -3
  31. data/spec/desk_api/error_spec.rb +9 -7
  32. data/spec/desk_api/rate_limit_spec.rb +1 -1
  33. data/spec/desk_api/request/encode_json_spec.rb +33 -0
  34. data/spec/desk_api/request/oauth_spec.rb +31 -0
  35. data/spec/desk_api/request/retry_spec.rb +4 -4
  36. data/spec/desk_api/resource_spec.rb +247 -71
  37. data/spec/desk_api/response/parse_dates_spec.rb +34 -0
  38. data/spec/desk_api/response/parse_json_spec.rb +34 -0
  39. data/spec/desk_api/response/raise_error_spec.rb +31 -0
  40. data/spec/desk_api_spec.rb +6 -6
  41. data/spec/spec_helper.rb +2 -2
  42. data/spec/stubs/article.json +51 -0
  43. data/spec/stubs/to_hash_embed.json +1 -0
  44. metadata +78 -28
  45. data/.coveralls.yml +0 -1
  46. data/.gitignore +0 -23
  47. data/.rspec +0 -1
  48. data/.travis.yml +0 -4
  49. data/.yardopts +0 -3
  50. data/Gemfile +0 -10
  51. data/Guardfile +0 -5
  52. data/Rakefile +0 -32
  53. data/desk_api.gemspec +0 -32
@@ -7,43 +7,43 @@ describe DeskApi::Resource do
7
7
 
8
8
  context '#initialize' do
9
9
  it 'stores the client' do
10
- subject.articles.instance_variable_get(:@_client).should eq(subject)
10
+ expect(subject.articles.instance_variable_get(:@_client)).to eq(subject)
11
11
  end
12
12
 
13
13
  it 'is not loaded initially' do
14
- subject.articles.instance_variable_get(:@_loaded).should be_false
14
+ expect(subject.articles.instance_variable_get(:@_loaded)).to be_false
15
15
  end
16
16
 
17
17
  it 'sets up the link to self' do
18
- subject.articles.href.should_not be_nil
18
+ expect(subject.articles.href).not_to be_nil
19
19
  end
20
20
 
21
21
  context 'additional options' do
22
22
  it 'allows for sorting options' do
23
23
  cases = subject.cases(sort_field: :updated_at, sort_direction: :asc)
24
- cases.href.should eq('/api/v2/cases?sort_direction=asc&sort_field=updated_at')
24
+ expect(cases.href).to eq('/api/v2/cases?sort_direction=asc&sort_field=updated_at')
25
25
  end
26
26
 
27
27
  it 'allows to specify arbitrary params' do
28
- subject.cases(company_id: 1).href.should eq('/api/v2/cases?company_id=1')
29
- subject.cases(customer_id: 1).href.should eq('/api/v2/cases?customer_id=1')
30
- subject.cases(filter_id: 1).href.should eq('/api/v2/cases?filter_id=1')
28
+ expect(subject.cases(company_id: 1).href).to eq('/api/v2/cases?company_id=1')
29
+ expect(subject.cases(customer_id: 1).href).to eq('/api/v2/cases?customer_id=1')
30
+ expect(subject.cases(filter_id: 1).href).to eq('/api/v2/cases?filter_id=1')
31
31
  end
32
32
 
33
33
  it 'allows to specify embeddables' do
34
- subject.cases(embed: :customer).href.should eq('/api/v2/cases?embed=customer')
35
- subject.cases(embed: [:customer, :assigned_user]).href.should eq('/api/v2/cases?embed=customer%2Cassigned_user')
34
+ expect(subject.cases(embed: :customer).href).to eq('/api/v2/cases?embed=customer')
35
+ expect(subject.cases(embed: [:customer, :assigned_user]).href).to eq('/api/v2/cases?embed=customer%2Cassigned_user')
36
36
  end
37
37
 
38
38
  it 'does not automatically load the resource' do
39
- subject.cases(company_id: 1).instance_variable_get(:@_loaded).should be_false
39
+ expect(subject.cases(company_id: 1).instance_variable_get(:@_loaded)).to be_false
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
44
  context '#exec!', :vcr do
45
45
  it 'loads the current resource' do
46
- subject.articles.send(:exec!).instance_variable_get(:@_loaded).should be_true
46
+ expect(subject.articles.send(:exec!).instance_variable_get(:@_loaded)).to be_true
47
47
  end
48
48
 
49
49
  it 'can be forced to reload' do
@@ -62,7 +62,7 @@ describe DeskApi::Resource do
62
62
  end
63
63
 
64
64
  it 'raises an error if method does not exist' do
65
- lambda { subject.articles.some_other_method }.should raise_error(NoMethodError)
65
+ expect(lambda { subject.articles.some_other_method }).to raise_error(NoMethodError)
66
66
  end
67
67
  end
68
68
 
@@ -81,23 +81,23 @@ describe DeskApi::Resource do
81
81
  end
82
82
 
83
83
  it 'returns true if method found in definition' do
84
- @company.respond_to?(:name).should be_true
84
+ expect(@company.respond_to?(:name)).to be_true
85
85
  end
86
86
 
87
87
  it 'returns false if method does not exist' do
88
- @company.respond_to?(:no_method_here).should be_false
88
+ expect(@company.respond_to?(:no_method_here)).to be_false
89
89
  end
90
90
  end
91
91
 
92
92
  context '#by_url', :vcr do
93
93
  it 'finds resources by url' do
94
- subject.articles.by_url('/api/v2/articles/1295677').should be_an_instance_of(DeskApi::Resource)
94
+ expect(subject.articles.by_url('/api/v2/articles/1295677')).to be_an_instance_of(DeskApi::Resource)
95
95
  end
96
96
  end
97
97
 
98
98
  context '#get_self' do
99
99
  it 'returns the hash for self' do
100
- subject.articles.get_self.should eq({
100
+ expect(subject.articles.get_self).to eq({
101
101
  "href" => "/api/v2/articles"
102
102
  })
103
103
  end
@@ -105,7 +105,7 @@ describe DeskApi::Resource do
105
105
 
106
106
  context '#href' do
107
107
  it 'returns the href for self' do
108
- subject.articles.href.should eq('/api/v2/articles')
108
+ expect(subject.articles.href).to eq('/api/v2/articles')
109
109
  end
110
110
 
111
111
  it 'sets the href' do
@@ -113,9 +113,9 @@ describe DeskApi::Resource do
113
113
  '_links'=>{'self'=>{'href'=>'/api/v2/cases'}}
114
114
  }, true)
115
115
 
116
- res.href.should eq('/api/v2/cases')
116
+ expect(res.href).to eq('/api/v2/cases')
117
117
  res.href = '/api/v2/articles'
118
- res.href.should eq('/api/v2/articles')
118
+ expect(res.href).to eq('/api/v2/articles')
119
119
  end
120
120
  end
121
121
 
@@ -124,25 +124,27 @@ describe DeskApi::Resource do
124
124
  res = DeskApi::Resource.new(subject, {
125
125
  '_links'=>{'self'=>{'href'=>'/api/v2/cases','class'=>'page'}}
126
126
  }, true)
127
- res.resource_type.should eq('page')
127
+ expect(res.resource_type).to eq('page')
128
128
  end
129
129
  end
130
130
 
131
131
  context '#search' do
132
132
  it 'allows searching on search enabled resources', :vcr do
133
- subject.articles.search(text: 'Lorem Ipsum').total_entries.should eq(0)
133
+ expect(subject.articles.search(text: 'Lorem Ipsum').total_entries).to eq(0)
134
134
  end
135
135
  end
136
136
 
137
137
  context '#create' do
138
138
  it 'creates a new topic', :vcr do
139
- topic = subject.topics.create({
140
- name: 'My new topic'
141
- }).name.should eq('My new topic')
139
+ expect(
140
+ topic = subject.topics.create({
141
+ name: 'My new topic'
142
+ }).name
143
+ ).to eq('My new topic')
142
144
  end
143
145
 
144
146
  it 'throws an error creating a user', :vcr do
145
- lambda { subject.users.create(name: 'Some User') }.should raise_error(DeskApi::Error::MethodNotAllowed)
147
+ expect(lambda { subject.users.create(name: 'Some User') }).to raise_error(DeskApi::Error::MethodNotAllowed)
146
148
  end
147
149
  end
148
150
 
@@ -155,20 +157,20 @@ describe DeskApi::Resource do
155
157
  name: 'Updated topic name'
156
158
  })
157
159
 
158
- topic.name.should eq('Updated topic name')
159
- topic.description.should eq('Some new description')
160
+ expect(topic.name).to eq('Updated topic name')
161
+ expect(topic.description).to eq('Some new description')
160
162
  end
161
163
 
162
164
  it 'throws an error updating a user', :vcr do
163
165
  user = subject.users.entries.first
164
- lambda { user.update(name: 'Some User') }.should raise_error(DeskApi::Error::MethodNotAllowed)
166
+ expect(lambda { user.update(name: 'Some User') }).to raise_error(DeskApi::Error::MethodNotAllowed)
165
167
  end
166
168
 
167
169
  it 'can update without a hash', :vcr do
168
170
  topic = subject.topics.entries.first
169
171
  topic.description = 'Another description update.'
170
172
  topic.update
171
- subject.topics.entries.first.description.should eq('Another description update.')
173
+ expect(subject.topics.entries.first.description).to eq('Another description update.')
172
174
  end
173
175
 
174
176
  it 'can handle update action params', :vcr do
@@ -181,14 +183,34 @@ describe DeskApi::Resource do
181
183
  phone_numbers_update_action: 'append'
182
184
  })
183
185
 
184
- customer.reload!.phone_numbers.size.should eq(num_count + 1)
186
+ expect(customer.reload!.phone_numbers.size).to eq(num_count + 1)
185
187
 
186
188
  customer.update({
187
189
  phone_numbers: [phone],
188
190
  phone_numbers_update_action: 'append'
189
191
  })
190
192
 
191
- customer.reload!.phone_numbers.size.should eq(num_count + 2)
193
+ expect(customer.reload!.phone_numbers.size).to eq(num_count + 2)
194
+ end
195
+
196
+ it 'can handle action params', :vcr do
197
+ ticket = subject.cases.entries.first
198
+ num_count = ticket.to_hash['labels'].count
199
+ labels = ['client_spam', 'client_test']
200
+
201
+ ticket.update({
202
+ labels: labels,
203
+ label_action: 'append'
204
+ })
205
+
206
+ expect(ticket.labels.reload!.total_entries).to eq(num_count + 2)
207
+
208
+ ticket.update({
209
+ labels: labels,
210
+ label_action: 'replace'
211
+ })
212
+
213
+ expect(ticket.labels.reload!.total_entries).to eq(2)
192
214
  end
193
215
 
194
216
  it 'can replace instead of append', :vcr do
@@ -206,35 +228,37 @@ describe DeskApi::Resource do
206
228
  phone_numbers_update_action: 'replace'
207
229
  })
208
230
 
209
- customer.reload!.phone_numbers.size.should eq(1)
210
- num_count.should_not eq(customer.phone_numbers.size)
231
+ expect(customer.reload!.phone_numbers.size).to eq(1)
232
+ expect(num_count).not_to eq(customer.phone_numbers.size)
211
233
  end
212
234
  end
213
235
 
214
236
  context '#delete' do
215
237
  it 'deletes a resource', :vcr do
216
- subject.articles.create({
217
- subject: 'My subject',
218
- body: 'Some text for this new article',
219
- _links: {
220
- topic: subject.topics.entries.first.get_self
221
- }
222
- }).delete.should be_true
238
+ expect {
239
+ subject.articles.create({
240
+ subject: 'My subject',
241
+ body: 'Some text for this new article',
242
+ _links: {
243
+ topic: subject.topics.entries.first.get_self
244
+ }
245
+ }).delete
246
+ }.to be_true
223
247
  end
224
248
 
225
249
  it 'throws an error deleting a non deletalbe resource', :vcr do
226
250
  user = subject.users.entries.first
227
- lambda { user.delete }.should raise_error(DeskApi::Error::MethodNotAllowed)
251
+ expect(lambda { user.delete }).to raise_error(DeskApi::Error::MethodNotAllowed)
228
252
  end
229
253
  end
230
254
 
231
255
  describe 'embeddable' do
232
256
  it 'allows to declare embedds' do
233
- lambda { subject.cases.embed(:assigned_user) }.should_not raise_error
257
+ expect(lambda { subject.cases.embed(:assigned_user) }).not_to raise_error
234
258
  end
235
259
 
236
260
  it 'changes the url' do
237
- subject.cases.embed(:assigned_user).href.should eq('/api/v2/cases?embed=assigned_user')
261
+ expect(subject.cases.embed(:assigned_user).href).to eq('/api/v2/cases?embed=assigned_user')
238
262
  end
239
263
 
240
264
  context 'if you use embed' do
@@ -244,13 +268,9 @@ describe DeskApi::Resource do
244
268
  @stubs ||= Faraday::Adapter::Test::Stubs.new
245
269
  @client ||= DeskApi::Client.new(DeskApi::CONFIG).tap do |client|
246
270
  client.middleware = Proc.new do |builder|
247
- if Gem::Version.new(FaradayMiddleware::VERSION) >= Gem::Version.new('0.9.0')
248
- builder.response :dates
249
- builder.response :json, content_type: /application\/json/
250
- else
251
- builder.use FaradayMiddleware::ParseDates
252
- builder.use FaradayMiddleware::ParseJson, content_type: /application\/json/
253
- end
271
+ builder.response :desk_parse_dates
272
+ builder.response :desk_parse_json
273
+
254
274
  builder.adapter :test, @stubs
255
275
  end
256
276
  end
@@ -272,9 +292,9 @@ describe DeskApi::Resource do
272
292
  end
273
293
 
274
294
  first_case = @client.cases.embed(:assigned_user).entries.first
275
- first_case.assigned_user.name.should eq('Thomas Stachl')
276
- first_case.assigned_user.instance_variable_get(:@_loaded).should be_true
277
- times_called.should eq(1)
295
+ expect(first_case.assigned_user.name).to eq('Thomas Stachl')
296
+ expect(first_case.assigned_user.instance_variable_get(:@_loaded)).to be_true
297
+ expect(times_called).to eq(1)
278
298
  end
279
299
 
280
300
  it 'can be used in finder' do
@@ -287,9 +307,9 @@ describe DeskApi::Resource do
287
307
  end
288
308
 
289
309
  customer = @client.cases.find(3011, embed: :customer).customer
290
- customer.first_name.should eq('Thomas')
310
+ expect(customer.first_name).to eq('Thomas')
291
311
  customer = @client.cases.find(3011, embed: [:customer]).customer
292
- customer.first_name.should eq('Thomas')
312
+ expect(customer.first_name).to eq('Thomas')
293
313
  end
294
314
  end
295
315
  end
@@ -302,12 +322,12 @@ describe DeskApi::Resource do
302
322
  end
303
323
 
304
324
  it 'allows to get query params from the current resource' do
305
- @page.send(:query_params_include?, 'page').should eq('2')
306
- @page.send(:query_params_include?, 'per_page').should eq('50')
325
+ expect(@page.send(:query_params_include?, 'page')).to eq('2')
326
+ expect(@page.send(:query_params_include?, 'per_page')).to eq('50')
307
327
  end
308
328
 
309
329
  it 'returns nil if param not found' do
310
- @page.send(:query_params_include?, 'blup').should be_nil
330
+ expect(@page.send(:query_params_include?, 'blup')).to be_nil
311
331
  end
312
332
  end
313
333
 
@@ -320,67 +340,223 @@ describe DeskApi::Resource do
320
340
 
321
341
  it 'sets query params on the current url' do
322
342
  @page.send(:query_params=, { page: 5, per_page: 50 })
323
- @page.instance_variable_get(:@_definition)['_links']['self']['href'].should eq('/api/v2/cases?page=5&per_page=50')
343
+ expect(@page.instance_variable_get(:@_definition)['_links']['self']['href']).to eq('/api/v2/cases?page=5&per_page=50')
324
344
  end
325
345
  end
326
346
 
327
347
  context '#get_linked_resource' do
328
348
  it 'returns linked resources', :vcr do
329
- subject.cases.entries.first.customer.should be_an_instance_of(DeskApi::Resource)
349
+ expect(subject.cases.entries.first.customer).to be_an_instance_of(DeskApi::Resource)
330
350
  end
331
351
 
332
352
  it 'returns nil if link is nil', :vcr do
333
- subject.articles.next.should be_nil
353
+ expect(subject.articles.next).to be_nil
334
354
  end
335
355
 
336
356
  it 'saves the linked resource instead of the url', :vcr do
337
357
  first_case = subject.cases.entries.first
338
- first_case.customer.should be_an_instance_of(DeskApi::Resource)
339
- first_case.instance_variable_get(:@_definition)['_links']['customer'].should be_an_instance_of(DeskApi::Resource)
358
+ expect(first_case.customer).to be_an_instance_of(DeskApi::Resource)
359
+ expect(first_case.instance_variable_get(:@_links)['customer']).to be_an_instance_of(DeskApi::Resource)
340
360
  end
341
361
  end
342
362
 
343
363
  context '#page' do
344
364
  it 'returns the current page and loads if page not defined', :vcr do
345
- subject.articles.page.should eq(1)
365
+ expect(subject.articles.page).to eq(1)
346
366
  end
347
367
 
348
368
  it 'sets the page' do
349
- subject.cases.page(5).page.should eq(5)
369
+ expect(subject.cases.page(5).page).to eq(5)
350
370
  end
351
371
 
352
372
  it 'sets the resource to not loaded', :vcr do
353
373
  cases = subject.cases.send(:exec!)
354
- cases.page(5).instance_variable_get(:@_loaded).should be_false
374
+ expect(cases.page(5).instance_variable_get(:@_loaded)).to be_false
355
375
  end
356
376
 
357
377
  it 'keeps the resource as loaded', :vcr do
358
378
  cases = subject.cases.send(:exec!)
359
- cases.page(1).instance_variable_get(:@_loaded).should be_true
379
+ expect(cases.page(1).instance_variable_get(:@_loaded)).to be_true
360
380
  end
361
381
  end
362
382
 
363
383
  context '#find' do
364
384
  it 'loads the requested resource', :vcr do
365
- subject.cases.find(3065).subject.should eq('Testing the Tank again')
385
+ expect(subject.cases.find(3065).subject).to eq('Testing the Tank again')
366
386
  end
367
387
 
368
388
  it 'has an alias by_id', :vcr do
369
- subject.cases.find(3065).subject.should eq('Testing the Tank again')
389
+ expect(subject.cases.find(3065).subject).to eq('Testing the Tank again')
390
+ end
391
+ end
392
+
393
+ context '#to_hash' do
394
+ it 'returns a hash for a desk resource', :vcr do
395
+ expect(subject.topics.entries.first.to_hash).to eq({
396
+ "name" => "Updated topic name",
397
+ "description" => "Another description update.",
398
+ "position" => 1,
399
+ "allow_questions" => true,
400
+ "in_support_center" => true,
401
+ "created_at" => Time.parse("2013-04-22T23:46:42Z"),
402
+ "updated_at" => Time.parse("2014-03-06T17:59:33Z"),
403
+ "_links" => {
404
+ "self" => {
405
+ "href" => "/api/v2/topics/498301",
406
+ "class" => "topic"
407
+ },
408
+ "articles" => {
409
+ "href" => "/api/v2/topics/498301/articles",
410
+ "class" => "article"
411
+ },
412
+ "translations" => {
413
+ "href" => "/api/v2/topics/498301/translations",
414
+ "class" => "topic_translation"
415
+ }
416
+ }
417
+ })
418
+ end
419
+
420
+ it 'converts embedded resources to hashes', :vcr do
421
+ path = File.join(
422
+ RSpec.configuration.root_path,
423
+ 'stubs',
424
+ 'to_hash_embed.json'
425
+ )
426
+
427
+ expect(subject.cases(embed: :customer).to_hash.to_json).to eq(
428
+ File.open(path).read
429
+ )
430
+ end
431
+ end
432
+
433
+ context '#next!' do
434
+ it 'changes @_definition to next page', :vcr do
435
+ page = subject.cases.first
436
+ next_page = page.next
437
+ expect(
438
+ page.
439
+ next!.
440
+ instance_variables.
441
+ count { |v| page.instance_variable_get(v) != next_page.instance_variable_get(v) }
442
+ ).to eq(0)
443
+ end
444
+
445
+ it 'returns nil on the last page', :vcr do
446
+ expect(subject.cases.last.next!).to eq(nil)
370
447
  end
448
+
371
449
  end
372
450
 
451
+ context '#each_page' do
452
+ it 'iterates over each page', :vcr do
453
+ subject.cases.each_page do |page, page_number|
454
+ expect(page).to be_an_instance_of(DeskApi::Resource)
455
+ expect(page.resource_type).to eq('page')
456
+ expect(page_number).to be_an_instance_of(Fixnum)
457
+ end
458
+ end
459
+
460
+ it 'uses a default per_page of 1000', :vcr do
461
+ subject.cases.each_page do |page, page_number|
462
+ expect((page.query_params['per_page'].to_i % 10)).to eq(0)
463
+ end
464
+ end
465
+
466
+ it 'uses per_page from query_params if present' do
467
+ subject.cases.per_page(25) do |page, page_number|
468
+ expect(page.query_params['per_page']).to eq(25)
469
+ end
470
+ end
471
+
472
+ it 'raises ArgumentError if no block is given' do
473
+ expect { subject.cases.each_page }.to raise_error(ArgumentError)
474
+ end
475
+
476
+ it 'raises NoMethodError is called on non-page resources', :vcr do
477
+ expect { subject.cases.entries.first.each_page { |x| x } }.to raise_error(NoMethodError)
478
+ end
479
+ end
480
+
481
+ context '#all' do
482
+ it 'iterates over each resource on each page', :vcr do
483
+ subject.cases.all do |resource, page_num|
484
+ expect(resource).to be_an_instance_of(DeskApi::Resource)
485
+ expect(resource.resource_type).to eq('case')
486
+ expect(page_num).to be_an_instance_of(Fixnum)
487
+ end
488
+ end
489
+
490
+ it 'raises an argument error if no block is given' do
491
+ expect { subject.cases.all }.to raise_error(ArgumentError)
492
+ end
493
+ end
494
+
495
+ context '#reset!' do
496
+ it 'sets @_links, @_embedded, @_changed, and @_loaded to default values', :vcr do
497
+ ticket = subject.cases.embed(:customer).entries.first
498
+
499
+ ticket.customer
500
+ ticket.message
501
+ ticket.send(:reset!)
502
+
503
+ expect(ticket.instance_variable_get(:@_links)).to eq({})
504
+ expect(ticket.instance_variable_get(:@_embedded)).to eq({})
505
+ expect(ticket.instance_variable_get(:@_changed)).to eq({})
506
+ expect(ticket.instance_variable_get(:@_loaded)).to eq(false)
507
+ end
508
+ end
509
+
510
+ context '#load' do
511
+ it 'loads the resource if not already loaded', :vcr do
512
+ tickets = subject.cases
513
+ expect(tickets.instance_variable_get(:@_loaded)).to eq(false)
514
+ tickets.send(:load)
515
+ expect(tickets.instance_variable_get(:@_loaded)).to eq(true)
516
+ end
517
+ end
518
+
519
+ context '#loaded?' do
520
+ it 'returns true if the resource is loaded', :vcr do
521
+ tickets = subject.cases
522
+ expect(tickets.send(:loaded?)).to eq(false)
523
+ tickets.send(:load!)
524
+ expect(tickets.send(:loaded?)).to eq(true)
525
+ end
526
+ end
527
+
528
+ context '#new_resource' do
529
+ it 'returns a new desk resource from a hash definition' do
530
+ expect(
531
+ subject.
532
+ cases.
533
+ send(:new_resource, DeskApi::Resource.build_self_link('/api/v2/customers'))
534
+ ).to be_an_instance_of(DeskApi::Resource)
535
+ end
536
+ end
537
+
538
+ context '#request' do
539
+ it 'sends request through a client and returns Faraday::Response', :vcr do
540
+ expect(
541
+ subject.cases.send(
542
+ :request,
543
+ :get,
544
+ '/api/v2/cases'
545
+ )
546
+ ).to be_an_instance_of(Faraday::Response)
547
+ end
548
+ end
373
549
  describe 'prioritize links and embeds' do
374
550
  before do
375
551
  @company = subject.customers.entries.first.company
376
552
  end
377
553
 
378
554
  it 'returns a desk resource', :vcr do
379
- @company.should be_an_instance_of(DeskApi::Resource)
555
+ expect(@company).to be_an_instance_of(DeskApi::Resource)
380
556
  end
381
557
 
382
558
  it 'loads the resource and returns the name', :vcr do
383
- @company.name.should eq('Desk.com')
559
+ expect(@company.name).to eq('Desk.com')
384
560
  end
385
561
  end
386
562
  end