Sha256: 80742fd1d843ded834692b733d3784726e3fb1711702e6ba63f007a33025380f

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require File.expand_path("../../test_helper", __FILE__)

class SearchFlip::BulkTest < SearchFlip::TestCase
  def test_bulk
    product1, product2 = create_list(:product, 2)

    assert_difference "ProductIndex.total_entries", 2 do
      ProductIndex.bulk do |bulk|
        bulk.create product1.id, ProductIndex.serialize(product1)
        bulk.create product2.id, ProductIndex.serialize(product1)
      end
    end

    assert_difference "ProductIndex.total_entries", -2 do
      ProductIndex.bulk do |bulk|
        bulk.delete product1.id
        bulk.delete product2.id
      end
    end
  end

  def test_bulk_with_options
    product1, product2 = create_list(:product, 2)

    ProductIndex.import [product1, product2]

    assert_raises "SearchFlip::Bulk::Error" do
      ProductIndex.bulk do |bulk|
        bulk.create product1.id, ProductIndex.serialize(product1)
        bulk.create product2.id, ProductIndex.serialize(product1)
      end
    end

    ProductIndex.bulk(ignore_errors: [409]) do |bulk|
      bulk.create product1.id, ProductIndex.serialize(product1)
      bulk.create product2.id, ProductIndex.serialize(product1)
    end
  end

  def test_bulk_with_item_options
    product = create(:product)

    ProductIndex.bulk do |bulk|
      bulk.index product.id, ProductIndex.serialize(product), version: 1, version_type: "external_gt"
    end

    assert_raises "SearchFlip::Bulk::Error" do
      ProductIndex.bulk do |bulk|
        bulk.index product.id, ProductIndex.serialize(product), version: 1, version_type: "external_gt"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
search_flip-1.1.0 test/search_flip/bulk_test.rb
search_flip-1.0.0 test/search_flip/bulk_test.rb