|
4 | 4 | let(:client) { Intercom::Client.new(token: 'token') } |
5 | 5 |
|
6 | 6 | it "stops iterating if no starting after value" do |
7 | | - client.expects(:get).with("/contacts", {}). returns(page_of_contacts(false)) |
| 7 | + client.expects(:get).with("/contacts", {}).returns(page_of_contacts(false)) |
8 | 8 | emails = [] |
9 | 9 | client.contacts.all.each { |contact| emails << contact.email } |
10 | 10 | _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com] |
|
15 | 15 | client.expects(:get).with('/contacts', { starting_after: "EnCrYpTeDsTrInG" }).returns(page_of_contacts(false)) |
16 | 16 | emails = [] |
17 | 17 | client.contacts.all.each { |contact| emails << contact.email } |
| 18 | + _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com test1@example.com test2@example.com test3@example.com] |
18 | 19 | end |
19 | 20 |
|
20 | 21 | it "supports indexed array access" do |
|
27 | 28 | emails = client.contacts.all.map { |contact| contact.email } |
28 | 29 | _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com] |
29 | 30 | end |
| 31 | + |
| 32 | + it "keeps entire collection iterable after first iteration" do |
| 33 | + contacts = client.contacts.all |
| 34 | + emails_iter1 = [] |
| 35 | + emails_iter2 = [] |
| 36 | + expects_pagination = proc do |
| 37 | + client.expects(:get).with("/contacts", {}).returns(page_of_contacts(true)) |
| 38 | + client.expects(:get).with("/contacts", { starting_after: "EnCrYpTeDsTrInG" }).returns(page_of_contacts(false)) |
| 39 | + end |
| 40 | + |
| 41 | + expects_pagination.call |
| 42 | + contacts.each { |contact| emails_iter1 << contact.email } |
| 43 | + expects_pagination.call |
| 44 | + contacts.each { |contact| emails_iter2 << contact.email } |
| 45 | + _(emails_iter1).must_equal emails_iter2 |
| 46 | + end |
30 | 47 | end |
0 commit comments