Sha256: 3d0c9fec99e3fc51d35a69a6d75df2a1d559e10245c8a9dc36737a2e6855ba7f

Contents?: true

Size: 1.86 KB

Versions: 11

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'
require 'contextio/connect_token_collection'

describe ContextIO::ConnectTokenCollection do
  let(:api) { double('API', url_for: 'url from api') }

  subject { ContextIO::ConnectTokenCollection.new(api) }

  describe "#create" do
    before do
      api.stub(:request).with(:post, anything, anything).and_return({ token: '1234' })
    end

    it "posts to the api" do
      api.should_receive(:request).with(
        :post,
        'url from api',
        hash_including(callback_url: 'http://callback.com')
      )

      subject.create('http://callback.com')
    end

    it "doesn't make any more API calls than it needs to" do
      api.should_not_receive(:request).with(:get, anything, anything)

      subject.create('http://callback.com')
    end

    it "returns a ConnectToken" do
      expect(subject.create('http://callback.com')).to be_a(ContextIO::ConnectToken)
    end

    it "takes an optional service level" do
      api.should_receive(:request).with(
        anything,
        anything,
        hash_including(service_level: 'PRO')
      )

      subject.create('http://callback.com', service_level: 'PRO')
    end

    it "takes an optional email" do
      api.should_receive(:request).with(
        anything,
        anything,
        hash_including(email: 'person@email.com')
      )

      subject.create('http://callback.com', email: 'person@email.com')
    end

    it "takes an optional first name" do
      api.should_receive(:request).with(
        anything,
        anything,
        hash_including(first_name: 'Bruno')
      )

      subject.create('http://callback.com', first_name: 'Bruno')
    end

    it "takes an optional last name" do
      api.should_receive(:request).with(
        anything,
        anything,
        hash_including(last_name: 'Morency')
      )

      subject.create('http://callback.com', last_name: 'Morency')
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
contextio-1.5.0 spec/unit/contextio/connect_token_collection_spec.rb
contextio-1.4.0 spec/unit/contextio/connect_token_collection_spec.rb
contextio-1.3.0 spec/unit/contextio/connect_token_collection_spec.rb
contextio-1.2.4 spec/unit/contextio/connect_token_collection_spec.rb
contextio-1.2.3 spec/contextio/connect_token_collection_spec.rb
contextio-1.2.2 spec/contextio/connect_token_collection_spec.rb
contextio-1.2.1 spec/contextio/connect_token_collection_spec.rb
contextio-1.2.0 spec/contextio/connect_token_collection_spec.rb
contextio-1.1.0 spec/contextio/connect_token_collection_spec.rb
contextio-1.0.1 spec/contextio/connect_token_collection_spec.rb
contextio-1.0.0 spec/contextio/connect_token_collection_spec.rb