Sha256: 606da322829688586d6ad64095da70057b8470e6acc896b3b4d27b0fe744ca54

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'
require 'contextio/account'

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

  subject { ContextIO::Account.new(api, id: '1234') }

  describe ".new" do
    context "with an id passed in" do
      it "doesn't raise an error" do
        expect { ContextIO::Account.new(api, id: '1234') }.to_not raise_error
      end
    end

    context "with neither an id nor a resource_url passed in" do
      it "raises an ArgumentError" do
        expect { ContextIO::Account.new(api, foo: 'bar') }.to raise_error(ArgumentError)
      end
    end
  end

  describe "#update" do
    before do
      allow(api).to receive(:request).and_return({'success' => true})
    end

    subject { ContextIO::Account.new(api, id: '1234', first_name: 'old first name') }

    it "posts to the api" do
      expect(api).to receive(:request).with(
        :post,
        'url from api',
        first_name: 'new first name'
      )

      subject.update(first_name: 'new first name')
    end

    it "updates the object" do
      subject.update(first_name: 'new first name')

      expect(subject.first_name).to eq('new first name')
    end

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

      subject.update(first_name: 'new first name')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contextio-1.7.2 spec/unit/contextio/account_spec.rb
contextio-1.7.1 spec/unit/contextio/account_spec.rb
contextio-1.7.0 spec/unit/contextio/account_spec.rb
contextio-1.6.0 spec/unit/contextio/account_spec.rb