Sha256: 072d1eeb61a3e4299ec656cb15b40561fa18b8a7f8a46747616ee2358e716509

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require_relative "test_helper"

class MultiSearchTest < Minitest::Test
  def test_basic
    store_names ["Product A"]
    store_names ["Store A"], Store
    products = Product.search("*", execute: false)
    stores = Store.search("*", execute: false)
    Searchkick.multi_search([products, stores])
    assert_equal ["Product A"], products.map(&:name)
    assert_equal ["Store A"], stores.map(&:name)
  end

  def test_error
    store_names ["Product A"]
    products = Product.search("*", execute: false)
    stores = Store.search("*", order: [:bad_field], execute: false)
    Searchkick.multi_search([products, stores])
    assert !products.error
    assert stores.error
  end

  def test_misspellings_below_unmet
    store_names ["abc", "abd", "aee"]
    products = Product.search("abc", misspellings: {below: 2}, execute: false)
    Searchkick.multi_search([products])
    assert_equal ["abc"], products.map(&:name)
  end

  def test_misspellings_below_unmet_retry
    store_names ["abc", "abd", "aee"]
    products = Product.search("abc", misspellings: {below: 2}, execute: false)
    Searchkick.multi_search([products], retry_misspellings: true)
    assert_equal ["abc", "abd"], products.map(&:name)
  end

  def test_error
    products = Product.search("*", order: {bad_column: :asc}, execute: false)
    Searchkick.multi_search([products])
    assert products.error
    error = assert_raises(Searchkick::Error) { products.results }
    assert_equal error.message, "Query error - use the error method to view it"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
searchkick-2.5.0 test/multi_search_test.rb