zendesk_api 1.3.9 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +31 -21
  5. data/lib/zendesk_api/collection.rb +7 -0
  6. data/lib/zendesk_api/version.rb +1 -1
  7. data/spec/core/association_spec.rb +40 -40
  8. data/spec/core/client_spec.rb +37 -37
  9. data/spec/core/collection_spec.rb +81 -70
  10. data/spec/core/configuration_spec.rb +4 -4
  11. data/spec/core/create_resource_spec.rb +2 -2
  12. data/spec/core/data_resource_spec.rb +28 -28
  13. data/spec/core/inflection_spec.rb +1 -1
  14. data/spec/core/lru_cache_spec.rb +8 -8
  15. data/spec/core/middleware/request/encode_json_spec.rb +8 -8
  16. data/spec/core/middleware/request/etag_cache_spec.rb +5 -5
  17. data/spec/core/middleware/request/retry_spec.rb +10 -8
  18. data/spec/core/middleware/request/upload_spec.rb +25 -25
  19. data/spec/core/middleware/response/callback_spec.rb +1 -1
  20. data/spec/core/middleware/response/deflate_spec.rb +1 -1
  21. data/spec/core/middleware/response/gzip_spec.rb +1 -1
  22. data/spec/core/middleware/response/parse_iso_dates_spec.rb +9 -9
  23. data/spec/core/middleware/response/parse_json_spec.rb +4 -4
  24. data/spec/core/middleware/response/raise_error_spec.rb +2 -2
  25. data/spec/core/read_resource_spec.rb +6 -6
  26. data/spec/core/resource_spec.rb +66 -66
  27. data/spec/core/search_spec.rb +3 -3
  28. data/spec/core/spec_helper.rb +5 -4
  29. data/spec/core/trackie_spec.rb +17 -17
  30. data/spec/live/app_installation_spec.rb +2 -2
  31. data/spec/live/app_spec.rb +1 -1
  32. data/spec/live/audit_spec.rb +2 -2
  33. data/spec/live/collection_spec.rb +8 -8
  34. data/spec/live/locale_spec.rb +1 -1
  35. data/spec/live/macro_spec.rb +4 -4
  36. data/spec/live/setting_spec.rb +1 -1
  37. data/spec/live/tag_spec.rb +7 -7
  38. data/spec/live/ticket_spec.rb +10 -10
  39. data/spec/live/topic_comment_spec.rb +2 -2
  40. data/spec/live/topic_spec.rb +2 -2
  41. data/spec/live/user_spec.rb +15 -15
  42. data/spec/macros/resource_macros.rb +17 -17
  43. metadata +2 -2
@@ -7,11 +7,11 @@ describe ZendeskAPI::Collection do
7
7
 
8
8
  context "initialization" do
9
9
  it "should set the resource class" do
10
- subject.instance_variable_get(:@resource_class).should == ZendeskAPI::TestResource
10
+ expect(subject.instance_variable_get(:@resource_class)).to eq(ZendeskAPI::TestResource)
11
11
  end
12
12
 
13
13
  it "should initially be empty" do
14
- subject.instance_variable_defined?(:@resources).should be_false
14
+ expect(subject.instance_variable_defined?(:@resources)).to be(false)
15
15
  end
16
16
  end
17
17
 
@@ -19,7 +19,7 @@ describe ZendeskAPI::Collection do
19
19
  subject { ZendeskAPI::Collection.new(client, ZendeskAPI::TestResource, :ids => [1, 2, 3, 4]) }
20
20
 
21
21
  it "should join array with commas" do
22
- subject.instance_variable_get(:@options)[:ids].should == "1,2,3,4"
22
+ expect(subject.instance_variable_get(:@options)[:ids]).to eq("1,2,3,4")
23
23
  end
24
24
  end
25
25
 
@@ -96,19 +96,19 @@ describe ZendeskAPI::Collection do
96
96
  end
97
97
 
98
98
  it "should pass association" do
99
- subject.last.association.should == association
99
+ expect(subject.last.association).to eq(association)
100
100
  end
101
101
 
102
102
  it "should #build a resource and add it" do
103
103
  resource = subject.build
104
- subject.should include(resource)
105
- resource.association.should == subject.association
104
+ expect(subject).to include(resource)
105
+ expect(resource.association).to eq(subject.association)
106
106
  end
107
107
 
108
108
  it "should #build! a resource and add it" do
109
109
  resource = subject.build!
110
- subject.should include(resource)
111
- resource.association.should == subject.association
110
+ expect(subject).to include(resource)
111
+ expect(resource.association).to eq(subject.association)
112
112
  end
113
113
  end
114
114
  end
@@ -127,7 +127,7 @@ describe ZendeskAPI::Collection do
127
127
  before(:each) { subject.page(nil) }
128
128
 
129
129
  it "should not empty the cache" do
130
- subject.instance_variable_get(:@resources).should_not be_empty
130
+ expect(subject.instance_variable_get(:@resources)).to_not be_empty
131
131
  end
132
132
  end
133
133
 
@@ -135,7 +135,7 @@ describe ZendeskAPI::Collection do
135
135
  before(:each) { subject.page(3) }
136
136
 
137
137
  it "should empty the cache" do
138
- subject.instance_variable_get(:@resources).should be_nil
138
+ expect(subject.instance_variable_get(:@resources)).to be_nil
139
139
  end
140
140
  end
141
141
  end
@@ -145,7 +145,7 @@ describe ZendeskAPI::Collection do
145
145
  before(:each) { subject.per_page(nil) }
146
146
 
147
147
  it "should not empty the cache" do
148
- subject.instance_variable_get(:@resources).should_not be_empty
148
+ expect(subject.instance_variable_get(:@resources)).to_not be_empty
149
149
  end
150
150
  end
151
151
 
@@ -153,7 +153,7 @@ describe ZendeskAPI::Collection do
153
153
  before(:each) { subject.per_page(20) }
154
154
 
155
155
  it "should empty the cache" do
156
- subject.instance_variable_get(:@resources).should be_nil
156
+ expect(subject.instance_variable_get(:@resources)).to be_nil
157
157
  end
158
158
  end
159
159
  end
@@ -161,11 +161,11 @@ describe ZendeskAPI::Collection do
161
161
 
162
162
  context "pagination with no options and no data" do
163
163
  it "should return an empty array on #next" do
164
- subject.next.should be_empty
164
+ expect(subject.next).to be_empty
165
165
  end
166
166
 
167
167
  it "should return an empty array on #prev" do
168
- subject.prev.should be_empty
168
+ expect(subject.prev).to be_empty
169
169
  end
170
170
  end
171
171
 
@@ -173,21 +173,21 @@ describe ZendeskAPI::Collection do
173
173
  before(:each) { subject.per_page(5).page(2) }
174
174
 
175
175
  it "should set per_page option" do
176
- subject.per_page(10).should == subject
177
- subject.instance_variable_get(:@options)["per_page"].should == 10
176
+ expect(subject.per_page(10)).to eq(subject)
177
+ expect(subject.instance_variable_get(:@options)["per_page"]).to eq(10)
178
178
  end
179
179
 
180
180
  it "should set page option" do
181
- subject.page(10).should == subject
182
- subject.instance_variable_get(:@options)["page"].should == 10
181
+ expect(subject.page(10)).to eq(subject)
182
+ expect(subject.instance_variable_get(:@options)["page"]).to eq(10)
183
183
  end
184
184
 
185
185
  it "should increate page option" do
186
- subject.next.should == 3
186
+ expect(subject.next).to eq(3)
187
187
  end
188
188
 
189
189
  it "should decreate page option" do
190
- subject.prev.should == 1
190
+ expect(subject.prev).to eq(1)
191
191
  end
192
192
  end
193
193
 
@@ -298,6 +298,17 @@ describe ZendeskAPI::Collection do
298
298
  [ZendeskAPI::TestResource.new(client, :id => 2), 2]
299
299
  )
300
300
  end
301
+
302
+ context "afterwards" do
303
+ before(:each) do
304
+ silence_logger { subject.all {|_|} }
305
+ end
306
+
307
+ it "should reset the collection" do
308
+ expect(subject.first_page?).to be(true)
309
+ expect(subject.fetch).to eq([ZendeskAPI::TestResource.new(client, :id => 1)])
310
+ end
311
+ end
301
312
  end
302
313
  end
303
314
 
@@ -315,7 +326,7 @@ describe ZendeskAPI::Collection do
315
326
  end
316
327
 
317
328
  it "should set the page to 1" do
318
- @page.should == 1
329
+ expect(@page).to eq(1)
319
330
  end
320
331
  end
321
332
 
@@ -331,7 +342,7 @@ describe ZendeskAPI::Collection do
331
342
  end
332
343
 
333
344
  it "should set the page to 2" do
334
- @page.should == 2
345
+ expect(@page).to eq(2)
335
346
  end
336
347
  end
337
348
 
@@ -343,14 +354,14 @@ describe ZendeskAPI::Collection do
343
354
  end
344
355
 
345
356
  it "should not set the page" do
346
- @page.should be_nil
357
+ expect(@page).to be_nil
347
358
  end
348
359
  end
349
360
  end
350
361
 
351
362
  it "does not fetch if associated is a new record" do
352
- ZendeskAPI::Category.new(client).forums.fetch.should == []
353
- ZendeskAPI::Category.new(client).forums.to_a.should == []
363
+ expect(ZendeskAPI::Category.new(client).forums.fetch).to eq([])
364
+ expect(ZendeskAPI::Category.new(client).forums.to_a).to eq([])
354
365
  end
355
366
 
356
367
  context "with client error" do
@@ -359,7 +370,7 @@ describe ZendeskAPI::Collection do
359
370
  end
360
371
 
361
372
  it "should properly be handled" do
362
- silence_logger { subject.fetch(true).should be_empty }
373
+ silence_logger { expect(subject.fetch(true)).to be_empty }
363
374
  end
364
375
  end
365
376
 
@@ -369,7 +380,7 @@ describe ZendeskAPI::Collection do
369
380
  end
370
381
 
371
382
  it "should properly be handled" do
372
- silence_logger { subject.fetch(true).should be_empty }
383
+ silence_logger { expect(subject.fetch(true)).to be_empty }
373
384
  end
374
385
  end
375
386
 
@@ -377,8 +388,8 @@ describe ZendeskAPI::Collection do
377
388
  subject { ZendeskAPI::Collection.new(client, ZendeskAPI::NilResource) }
378
389
 
379
390
  it "should not call connection" do
380
- client.connection.should_not_receive(:get)
381
- subject.fetch(true).should be_empty
391
+ expect(client.connection).to_not receive(:get)
392
+ expect(subject.fetch(true)).to be_empty
382
393
  end
383
394
  end
384
395
  end
@@ -394,16 +405,16 @@ describe ZendeskAPI::Collection do
394
405
  let(:object) { double('ZendeskAPI::TestResource', :changes => [:xxx], :changed? => true, :destroyed? => false) }
395
406
 
396
407
  it "should call create with those options" do
397
- ZendeskAPI::TestResource.should_receive(:new).
408
+ expect(ZendeskAPI::TestResource).to receive(:new).
398
409
  with(client, options.merge(:association => subject.association)).
399
410
  and_return(object)
400
411
 
401
412
  subject << options
402
413
 
403
- object.should_receive(:save)
414
+ expect(object).to receive(:save)
404
415
  subject.save
405
416
 
406
- subject.should include(object)
417
+ expect(subject).to include(object)
407
418
  end
408
419
  end
409
420
 
@@ -414,25 +425,25 @@ describe ZendeskAPI::Collection do
414
425
  end
415
426
 
416
427
  it "should save object" do
417
- object.should_receive(:save)
428
+ expect(object).to receive(:save)
418
429
  subject.save
419
430
  end
420
431
 
421
432
  it "should have object in collection" do
422
- subject.should include(object)
433
+ expect(subject).to include(object)
423
434
  end
424
435
  end
425
436
 
426
437
  context "with everything else" do
427
438
  it "should pass to new, since this is how attachment handles it" do
428
439
  attachment = double(:changes => [:xxx], :changed? => true, :destroyed? => false)
429
- ZendeskAPI::TestResource.should_receive(:new).
440
+ expect(ZendeskAPI::TestResource).to receive(:new).
430
441
  with(client, :id => "img.jpg", :association => instance_of(ZendeskAPI::Association)).
431
442
  and_return attachment
432
443
 
433
444
  subject << "img.jpg"
434
445
 
435
- attachment.should_receive :save
446
+ expect(attachment).to receive(:save)
436
447
  subject.save
437
448
  end
438
449
  end
@@ -445,14 +456,14 @@ describe ZendeskAPI::Collection do
445
456
  end
446
457
 
447
458
  it "should not save object" do
448
- object.should_receive(:destroyed?).and_return(true)
449
- object.should_not_receive(:save)
459
+ expect(object).to receive(:destroyed?).and_return(true)
460
+ expect(object).to_not receive(:save)
450
461
 
451
462
  subject.save
452
463
  end
453
464
 
454
465
  it "should have object in collection" do
455
- subject.should include(object)
466
+ expect(subject).to include(object)
456
467
  end
457
468
  end
458
469
  end
@@ -484,16 +495,16 @@ describe ZendeskAPI::Collection do
484
495
  current = subject.to_a.dup
485
496
  nxt = subject.next
486
497
 
487
- nxt.size.should == 1
488
- nxt.should_not == current
498
+ expect(nxt.size).to eq(1)
499
+ expect(nxt).to_not eq(current)
489
500
  end
490
501
 
491
502
  it "should find the prev page by calling fetch" do
492
503
  current = subject.to_a.dup
493
504
  prev = subject.prev
494
505
 
495
- prev.size.should == 1
496
- prev.should_not == current
506
+ expect(prev.size).to eq(1)
507
+ expect(prev).to_not eq(current)
497
508
  end
498
509
  end
499
510
 
@@ -501,22 +512,22 @@ describe ZendeskAPI::Collection do
501
512
  before(:each) { subject.per_page(1).page(2) }
502
513
 
503
514
  it "should increase page option and not call fetch" do
504
- subject.next.should == 3
515
+ expect(subject.next).to eq(3)
505
516
  end
506
517
 
507
518
  it "should decrease page option and not call fetch" do
508
- subject.prev.should == 1
519
+ expect(subject.prev).to eq(1)
509
520
  end
510
521
 
511
522
  context "with page == 1" do
512
523
  before do
513
524
  subject.page(1)
514
525
  subject.clear_cache
515
- subject.should_not_receive(:fetch)
526
+ expect(subject).to_not receive(:fetch)
516
527
  end
517
528
 
518
529
  it "should do nothing on #prev" do
519
- subject.prev.should == []
530
+ expect(subject.prev).to eq([])
520
531
  end
521
532
  end
522
533
  end
@@ -542,11 +553,11 @@ describe ZendeskAPI::Collection do
542
553
  end
543
554
 
544
555
  it "should side load nil_resources" do
545
- @resource.nil_resource.should_not be_nil
556
+ expect(@resource.nil_resource).to_not be_nil
546
557
  end
547
558
 
548
559
  it "should side load the correct nil_resource" do
549
- @resource.nil_resource.name.should == "hi"
560
+ expect(@resource.nil_resource.name).to eq("hi")
550
561
  end
551
562
  end
552
563
 
@@ -568,11 +579,11 @@ describe ZendeskAPI::Collection do
568
579
  before(:each) { @resource = subject.detect {|res| res.id == 1} }
569
580
 
570
581
  it "should side load nil_resources" do
571
- @resource.nil_resource.should_not be_nil
582
+ expect(@resource.nil_resource).to_not be_nil
572
583
  end
573
584
 
574
585
  it "should side load the correct nil_resource" do
575
- @resource.nil_resource.name.should == "hi"
586
+ expect(@resource.nil_resource.name).to eq("hi")
576
587
  end
577
588
  end
578
589
 
@@ -580,11 +591,11 @@ describe ZendeskAPI::Collection do
580
591
  before(:each) { @resource = subject.detect {|res| res.id == 2} }
581
592
 
582
593
  it "should side load nil_resources" do
583
- @resource.nil_resource.should_not be_nil
594
+ expect(@resource.nil_resource).to_not be_nil
584
595
  end
585
596
 
586
597
  it "should side load the correct nil_resource" do
587
- @resource.nil_resource.name.should == "bye"
598
+ expect(@resource.nil_resource.name).to eq("bye")
588
599
  end
589
600
  end
590
601
  end
@@ -604,11 +615,11 @@ describe ZendeskAPI::Collection do
604
615
  end
605
616
 
606
617
  it "should side load nil_resources" do
607
- @resource.nil_resources.should_not be_empty
618
+ expect(@resource.nil_resources).to_not be_empty
608
619
  end
609
620
 
610
621
  it "should side load the correct nil_resources" do
611
- @resource.nil_resources.map(&:name).should == %w{hi hello}
622
+ expect(@resource.nil_resources.map(&:name)).to eq(%w{hi hello})
612
623
  end
613
624
  end
614
625
 
@@ -626,11 +637,11 @@ describe ZendeskAPI::Collection do
626
637
  end
627
638
 
628
639
  it "should side load nil_resources" do
629
- @resource.nil_resources.should_not be_empty
640
+ expect(@resource.nil_resources).to_not be_empty
630
641
  end
631
642
 
632
643
  it "should side load the correct nil_resources" do
633
- @resource.nil_resources.map(&:id).should == [2, 4]
644
+ expect(@resource.nil_resources.map(&:id)).to eq([2, 4])
634
645
  end
635
646
  end
636
647
 
@@ -648,11 +659,11 @@ describe ZendeskAPI::Collection do
648
659
  end
649
660
 
650
661
  it "should side load nil_resources" do
651
- @resource.nil_resource.should_not be_nil
662
+ expect(@resource.nil_resource).to_not be_nil
652
663
  end
653
664
 
654
665
  it "should side load the correct nil_resources" do
655
- @resource.nil_resource.id.should == 2
666
+ expect(@resource.nil_resource.id).to eq(2)
656
667
  end
657
668
  end
658
669
 
@@ -671,11 +682,11 @@ describe ZendeskAPI::Collection do
671
682
  end
672
683
 
673
684
  it "should side load nil_resources" do
674
- @resource.nil_resource.should_not be_nil
685
+ expect(@resource.nil_resource).to_not be_nil
675
686
  end
676
687
 
677
688
  it "should side load the correct nil_resource" do
678
- @resource.nil_resource.name.should == 4
689
+ expect(@resource.nil_resource.name).to eq(4)
679
690
  end
680
691
  end
681
692
 
@@ -695,38 +706,38 @@ describe ZendeskAPI::Collection do
695
706
  end
696
707
 
697
708
  it "should side load nil_resources" do
698
- @resource.nil_resource.should_not be_nil
709
+ expect(@resource.nil_resource).to_not be_nil
699
710
  end
700
711
 
701
712
  it "should side load the correct nil_resource" do
702
- @resource.nil_resource.id.should == 4
713
+ expect(@resource.nil_resource.id).to eq(4)
703
714
  end
704
715
  end
705
716
  end
706
717
 
707
718
  context "method missing" do
708
- before(:each) { subject.stub(:fetch).and_return([1, 2, nil, 3]) }
719
+ before(:each) { allow(subject).to receive(:fetch).and_return([1, 2, nil, 3]) }
709
720
 
710
721
  context "with an class method on the resource class" do
711
722
  it "should pass methods to class if defined" do
712
- subject.test.should == "hi"
723
+ expect(subject.test).to eq("hi")
713
724
  end
714
725
  end
715
726
 
716
727
  it "should pass all methods not defined to resources" do
717
- subject.compact.should == [1, 2, 3]
728
+ expect(subject.compact).to eq([1, 2, 3])
718
729
  end
719
730
 
720
731
  it "should take a block" do
721
- subject.map {|i| i.to_i + 1}.should == [2, 3, 1, 4]
732
+ expect(subject.map {|i| i.to_i + 1}).to eq([2, 3, 1, 4])
722
733
  end
723
734
 
724
735
  it "should create a new collection if it isn't an array method" do
725
- subject.recent.should be_instance_of(ZendeskAPI::Collection)
736
+ expect(subject.recent).to be_instance_of(ZendeskAPI::Collection)
726
737
  end
727
738
 
728
739
  it "should pass the correct query_path to the new collection" do
729
- subject.recent.instance_variable_get(:@collection_path).last.should == :recent
740
+ expect(subject.recent.instance_variable_get(:@collection_path).last).to eq(:recent)
730
741
  end
731
742
  end
732
743
 
@@ -738,7 +749,7 @@ describe ZendeskAPI::Collection do
738
749
  end
739
750
 
740
751
  it "should not blow up" do
741
- subject.to_a.should == []
752
+ expect(subject.to_a).to eq([])
742
753
  end
743
754
  end
744
755