Sha256: 71e3c189c77140c11742e9b6b2a61893c59073e5301dafeb298dfae2844d77fc

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

require "spec_helper"

describe Intercom::BaseCollectionProxy do
  let(:client) { Intercom::Client.new(token: 'token') }

  it "stops iterating if no starting after value" do
    client.expects(:get).with("/contacts", {}). returns(page_of_contacts(false))
    emails = []
    client.contacts.all.each { |contact| emails << contact.email }
    _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
  end

  it "keeps iterating if starting after value" do
    client.expects(:get).with("/contacts", {}).returns(page_of_contacts(true))
    client.expects(:get).with('/contacts', { starting_after: "EnCrYpTeDsTrInG" }).returns(page_of_contacts(false))
    emails = []
    client.contacts.all.each { |contact| emails << contact.email }
  end

  it "supports indexed array access" do
    client.expects(:get).with("/contacts", {}).returns(page_of_contacts(false))
    _(client.contacts.all[0].email).must_equal "test1@example.com"
  end

  it "supports map" do
    client.expects(:get).with("/contacts", {}).returns(page_of_contacts(false))
    emails = client.contacts.all.map { |contact| contact.email }
    _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
intercom-4.1.2 spec/unit/intercom/base_collection_proxy_spec.rb
intercom-4.1.1 spec/unit/intercom/base_collection_proxy_spec.rb
intercom-4.1.0 spec/unit/intercom/base_collection_proxy_spec.rb
intercom-4.0.1 spec/unit/intercom/base_collection_proxy_spec.rb
intercom-4.0.0 spec/unit/intercom/base_collection_proxy_spec.rb