Sha256: c140b01006853ce0dcc43fad571d7758e4c016dc3d0cdd76958a89d762ced627

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 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'

describe Lhm::ChunkInsert do
  before(:each) do
    @connection = stub(:connection)
    @origin = Lhm::Table.new('foo')
    @destination = Lhm::Table.new('bar')
  end

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

      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

6 entries across 6 versions & 1 rubygems

Version Path
lhm-shopify-3.5.0 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.4.2 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.4.1 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.4.0 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.3.6 spec/unit/chunk_insert_spec.rb
lhm-shopify-3.3.5 spec/unit/chunk_insert_spec.rb