Sha256: dccda1e9dbd28839cf52d0e59999246f4d3b98ac57f9cb793ebe2bfb51447fc3

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

require_relative '../../../test_helper'

module Troo
  module API
    describe Client do
      let(:described_class) { Client }
      let(:parameters) do
        {
          verb:          :get,
          endpoint:      endpoint,
          interpolation: { external_id: '1' },
          model:         Remote::Board,
          query:         {}
        }
      end
      let(:endpoint) { :board_by_id }
      let(:response) { Response.new }
      let(:parsed_response) { '' }
      let(:allow_remote) { true }

      before do
        API::Request.stubs(:make).returns(response)
        Yajl::Parser.stubs(:parse).returns(parsed_response)
      end

      describe '#perform' do
        subject { described_class.perform(parameters) }

        context 'when all required parameters are provided' do
          context 'and the API request returns a collection' do
            let(:parsed_response) do
              [{ name: 'Board 1' }, { name: 'Board 2' }]
            end

            it 'builds the remote model' do
              subject.size.must_equal(2)
            end
          end

          context 'and the API request returns an instance' do
            let(:parsed_response) { { name: 'Board 1' } }

            it 'builds the remote model' do
              subject.size.must_equal(1)
            end
          end
        end

        context 'when remote connections are not allowed' do
          let(:allow_remote) { false }

          it { subject.must_equal [] }
        end

        context 'when remote connections are allowed' do
          context 'when a required parameter is missing' do
            let(:endpoint) {}

            it { subject.must_equal [] }
          end

          context 'when the response is an error' do
            let(:response) { ErrorResponse.new }

            it { subject.must_equal [] }
          end

          context 'when the response is empty' do
            it { subject.must_equal [] }
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
troo-0.0.10 test/lib/troo/api/client_test.rb
troo-0.0.9 test/lib/troo/api/client_test.rb