Sha256: 2ba9f6148d87f466b9ee0915a17b3b3dd0d0f0a7dc04c84ec9dfb6b04345c276

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe WialonApi::Api do
  def create_connection
    @result = { 'response' => { 'key' => 'value' } }

    @connection = Faraday.new do |builder|
      builder.response :mashify
      builder.response :oj, preserve_raw: true
      builder.adapter :test do |stub|
        stub.post('/wialon/ajax.html') do
          [200, {}, Oj.dump(@result)]
        end
      end
    end
    allow(subject).to receive(:connection).and_return(@connection)
  end

  describe '.call' do
    before(:each) do
      WialonApi.reset
      create_connection
    end

    it 'sends a sid if it was passed with parameter' do
      expect(subject).to receive(:connection).with(url: WialonApi.wialon_host, sid: 'sid')
      subject.call('core/search_items', { params: :value }, 'sid')
    end
  end

  describe '.connection' do
    it 'uses the :url parameter and WialonApi.faraday_options' do
      faraday_options = double('Faraday options')
      allow(WialonApi).to receive(:faraday_options).and_return(faraday_options)
      url = double('URL')

      expect(Faraday).to receive(:new).with(url, faraday_options)
      subject.connection(url: url)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wialon_api-0.0.3 spec/wialon_api/api_spec.rb
wialon_api-0.0.2 spec/wialon_api/api_spec.rb
wialon_api-0.0.1 spec/wialon_api/api_spec.rb