Sha256: c521887a4d475947d56ae3070c2ca4fb9cdea66b31694329fa01beb4459dee58

Contents?: true

Size: 1.39 KB

Versions: 12

Compression:

Stored size: 1.39 KB

Contents

require "spec_helper"

describe Intercom::ClientCollectionProxy do
  let (:client) { Intercom::Client.new(app_id: 'app_id',  api_key: 'api_key') }

  it "stops iterating if no next link" do
    client.expects(:get).with("/users", {}).returns(page_of_users(false))
    emails = []
    client.users.all.each { |user| emails << user.email }
    emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
  end

  it "keeps iterating if next link" do
    client.expects(:get).with("/users", {}).returns(page_of_users(true))
    client.expects(:get).with('https://api.intercom.io/users?per_page=50&page=2', {}).returns(page_of_users(false))
    emails = []
    client.users.all.each { |user| emails << user.email }
  end

  it "supports indexed array access" do
    client.expects(:get).with("/users", {}).returns(page_of_users(false))
    client.users.all[0].email.must_equal 'user1@example.com'
  end

  it "supports map" do
    client.expects(:get).with("/users", {}).returns(page_of_users(false))
    emails = client.users.all.map { |user| user.email }
    emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
  end

  it "supports querying" do
    client.expects(:get).with("/users", {:tag_name => 'Taggart J'}).returns(page_of_users(false))
    client.users.find_all(:tag_name => 'Taggart J').map(&:email).must_equal %W(user1@example.com user2@example.com user3@example.com)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
intercom-3.5.1 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.4.0 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.3.0 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.2.0 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.1.0 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.0.6 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.0.5 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.0.4 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.0.3 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.0.2 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.0.0 spec/unit/intercom/client_collection_proxy_spec.rb
intercom-3.0.0b1 spec/unit/intercom/client_collection_proxy_spec.rb