Sha256: f5d34f888f2438a4b5fd049048c9d1090f2d61f339e6cae7d1a4395eda681b9c

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

#encoding: utf-8
require 'spec_helper'

describe Executrix::Api do
  let(:empty_connection) do
    Executrix::Connection.new(nil, nil, nil, nil)
  end

  let(:empty_batch) do
    Object.new
  end

  {
    upsert: 3,
    update: 2,
    insert: 2,
    delete: 2,
  }.each do |method_name, num_of_params|
    describe "##{method_name}" do
      it 'should delegate to #start_job' do
        Executrix::Connection
          .should_receive(:connect)
          .and_return(empty_connection)
        s = described_class.new(nil, nil)
        s.should_receive(:start_job)
          .with(method_name.to_s, *Array.new(num_of_params))
        s.send(method_name, *Array.new(num_of_params))
      end

      it 'should trigger correct workflow' do
        Executrix::Connection
          .should_receive(:connect)
          .and_return(empty_connection)
        s = described_class.new(nil, nil)
        empty_connection.should_receive(:create_job).ordered
        empty_connection.should_receive(:add_batch).ordered
        empty_connection.should_receive(:close_job).ordered
        res = s.send(method_name, *Array.new(num_of_params))
        expect(res).to be_a(Executrix::Batch)
      end
    end
  end

  describe '#query' do
    it 'should trigger correct workflow' do
      Executrix::Connection
          .should_receive(:connect)
          .and_return(empty_connection)
      Executrix::Batch
        .should_receive(:new)
        .and_return(empty_batch)

      s = described_class.new(nil, nil)
      sobject_input = 'sobject_stub'
      query_input = 'query_stub'
      empty_connection.should_receive(:create_job).ordered
      empty_connection.should_receive(:add_query).ordered
      empty_connection.should_receive(:close_job).ordered
      empty_batch.should_receive(:final_status).ordered
      s.query(sobject_input, query_input)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
executrix-1.1.3 spec/lib/executrix_spec.rb