Sha256: f08afa971eccb4a8f7125b23547fee6dce148fc30b8ff3a0ebc0eee64b080301

Contents?: true

Size: 1.51 KB

Versions: 16

Compression:

Stored size: 1.51 KB

Contents

# Copyright (c) 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
# Schmidt

require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'

require 'lhm/chunk_insert'
require 'lhm/connection'

describe Lhm::ChunkInsert do
  before(:each) do
    ar_connection = mock()
    ar_connection.stubs(:execute).returns([["dummy"]])
    @connection = Lhm::Connection.new(connection: ar_connection, options: {reconnect_with_consistent_host: false})
    @origin = Lhm::Table.new('foo')
    @destination = Lhm::Table.new('bar')
  end

  describe "#sql" do
    describe "when migration has no conditions" do
      before do
        @migration = Lhm::Migration.new(@origin, @destination)
      end

      it "uses a simple where clause" do
        assert_equal(
          Lhm::ChunkInsert.new(@migration, @connection, 1, 2).sql,
          "insert ignore into `bar` () select  from `foo` where `foo`.`id` between 1 and 2"
        )
      end
    end

    describe "when migration has a WHERE condition" do
      before do
        @migration = Lhm::Migration.new(
          @origin,
          @destination,
          "where foo.created_at > '2013-07-10' or foo.baz = 'quux'"
        )
      end

      it "combines the clause with the chunking WHERE condition" do
        assert_equal(
          Lhm::ChunkInsert.new(@migration, @connection, 1, 2).sql,
          "insert ignore into `bar` () select  from `foo` where (foo.created_at > '2013-07-10' or foo.baz = 'quux') and `foo`.`id` between 1 and 2"
        )
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lhm-shopify-4.4.2 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.4.1 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.4.0 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.3.0 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.2.3 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.2.2 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.2.1 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.2.0 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.1.1 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.1.0 spec/unit/chunk_insert_spec.rb
lhm-shopify-4.0.0 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.5.5 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.5.4 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.5.3 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.5.2 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.5.1 spec/unit/chunk_insert_spec.rb