Skip to content

Commit

Permalink
Fixed CI for Mongoid 9
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed May 30, 2024
1 parent 2b1238c commit 9eddf20
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 89 deletions.
12 changes: 6 additions & 6 deletions test/callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,43 @@ def test_bulk
Searchkick.callbacks(:bulk) do
store_names ["Product A", "Product B"]
end
Product.search_index.refresh
Product.searchkick_index.refresh
assert_search "product", ["Product A", "Product B"]
end

def test_queue
# TODO figure out which earlier test leaves records in index
Product.reindex

reindex_queue = Product.search_index.reindex_queue
reindex_queue = Product.searchkick_index.reindex_queue
reindex_queue.clear

Searchkick.callbacks(:queue) do
store_names ["Product A", "Product B"]
end
Product.search_index.refresh
Product.searchkick_index.refresh
assert_search "product", [], load: false, conversions: false
assert_equal 2, reindex_queue.length

perform_enqueued_jobs do
Searchkick::ProcessQueueJob.perform_now(class_name: "Product")
end
Product.search_index.refresh
Product.searchkick_index.refresh
assert_search "product", ["Product A", "Product B"], load: false
assert_equal 0, reindex_queue.length

Searchkick.callbacks(:queue) do
Product.where(name: "Product B").destroy_all
Product.create!(name: "Product C")
end
Product.search_index.refresh
Product.searchkick_index.refresh
assert_search "product", ["Product A", "Product B"], load: false
assert_equal 2, reindex_queue.length

perform_enqueued_jobs do
Searchkick::ProcessQueueJob.perform_now(class_name: "Product")
end
Product.search_index.refresh
Product.searchkick_index.refresh
assert_search "product", ["Product A", "Product C"], load: false
assert_equal 0, reindex_queue.length

Expand Down
8 changes: 4 additions & 4 deletions test/index_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ def setup
end

def test_default
object_id = Product.search_index.object_id
object_id = Product.searchkick_index.object_id
3.times do
assert_equal object_id, Product.search_index.object_id
assert_equal object_id, Product.searchkick_index.object_id
end
end

def test_max_size
starting_ids = object_ids(20)
assert_equal starting_ids, object_ids(20)
Product.search_index(name: "other")
Product.searchkick_index(name: "other")
refute_equal starting_ids, object_ids(20)
end

Expand All @@ -34,7 +34,7 @@ def test_thread_safe_max_size
private

def object_ids(count)
count.times.map { |i| Product.search_index(name: "index#{i}").object_id }
count.times.map { |i| Product.searchkick_index(name: "index#{i}").object_id }
end

def with_threads
Expand Down
24 changes: 12 additions & 12 deletions test/index_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_no_stem_exclusion
store_names ["animals", "anime"]
assert_search "animals", ["animals", "anime"], {misspellings: false}
assert_search "anime", ["animals", "anime"], {misspellings: false}
assert_equal ["anim"], Song.search_index.tokens("anime", analyzer: "searchkick_index")
assert_equal ["anim"], Song.search_index.tokens("anime", analyzer: "searchkick_search2")
assert_equal ["anim"], Song.searchkick_index.tokens("anime", analyzer: "searchkick_index")
assert_equal ["anim"], Song.searchkick_index.tokens("anime", analyzer: "searchkick_search2")
end
end

Expand All @@ -34,8 +34,8 @@ def test_stem_exclusion
store_names ["animals", "anime"]
assert_search "animals", ["animals"], {misspellings: false}
assert_search "anime", ["anime"], {misspellings: false}
assert_equal ["anime"], Song.search_index.tokens("anime", analyzer: "searchkick_index")
assert_equal ["anime"], Song.search_index.tokens("anime", analyzer: "searchkick_search2")
assert_equal ["anime"], Song.searchkick_index.tokens("anime", analyzer: "searchkick_index")
assert_equal ["anime"], Song.searchkick_index.tokens("anime", analyzer: "searchkick_search2")
end
end

Expand All @@ -44,8 +44,8 @@ def test_no_stemmer_override
store_names ["animals", "animations"]
assert_search "animals", ["animals", "animations"], {misspellings: false}
assert_search "animations", ["animals", "animations"], {misspellings: false}
assert_equal ["anim"], Song.search_index.tokens("animations", analyzer: "searchkick_index")
assert_equal ["anim"], Song.search_index.tokens("animations", analyzer: "searchkick_search2")
assert_equal ["anim"], Song.searchkick_index.tokens("animations", analyzer: "searchkick_index")
assert_equal ["anim"], Song.searchkick_index.tokens("animations", analyzer: "searchkick_search2")
end
end

Expand All @@ -54,8 +54,8 @@ def test_stemmer_override
store_names ["animals", "animations"]
assert_search "animals", ["animals"], {misspellings: false}
assert_search "animations", ["animations"], {misspellings: false}
assert_equal ["animat"], Song.search_index.tokens("animations", analyzer: "searchkick_index")
assert_equal ["animat"], Song.search_index.tokens("animations", analyzer: "searchkick_search2")
assert_equal ["animat"], Song.searchkick_index.tokens("animations", analyzer: "searchkick_index")
assert_equal ["animat"], Song.searchkick_index.tokens("animations", analyzer: "searchkick_search2")
end
end

Expand All @@ -68,25 +68,25 @@ def test_special_characters

def test_index_name
with_options({index_name: "songs_v2"}) do
assert_equal "songs_v2", Song.search_index.name
assert_equal "songs_v2", Song.searchkick_index.name
end
end

def test_index_name_callable
with_options({index_name: -> { "songs_v2" }}) do
assert_equal "songs_v2", Song.search_index.name
assert_equal "songs_v2", Song.searchkick_index.name
end
end

def test_index_prefix
with_options({index_prefix: "hello"}) do
assert_equal "hello_songs_test", Song.search_index.name
assert_equal "hello_songs_test", Song.searchkick_index.name
end
end

def test_index_prefix_callable
with_options({index_prefix: -> { "hello" }}) do
assert_equal "hello_songs_test", Song.search_index.name
assert_equal "hello_songs_test", Song.searchkick_index.name
end
end

Expand Down
26 changes: 13 additions & 13 deletions test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ def setup
end

def test_tokens
assert_equal ["dollar", "dollartre", "tree"], Product.search_index.tokens("Dollar Tree", analyzer: "searchkick_index")
assert_equal ["dollar", "dollartre", "tree"], Product.searchkick_index.tokens("Dollar Tree", analyzer: "searchkick_index")
end

def test_tokens_analyzer
assert_equal ["dollar", "tree"], Product.search_index.tokens("Dollar Tree", analyzer: "searchkick_search2")
assert_equal ["dollar", "tree"], Product.searchkick_index.tokens("Dollar Tree", analyzer: "searchkick_search2")
end

def test_total_docs
store_names ["Product A"]
assert_equal 1, Product.search_index.total_docs
assert_equal 1, Product.searchkick_index.total_docs
end

def test_clean_indices
Expand All @@ -31,9 +31,9 @@ def test_clean_indices
old_index.create
different_index.create

Product.search_index.clean_indices
Product.searchkick_index.clean_indices

assert Product.search_index.exists?
assert Product.searchkick_index.exists?
assert different_index.exists?
assert !old_index.exists?
end
Expand All @@ -43,33 +43,33 @@ def test_clean_indices_old_format
old_index = Searchkick::Index.new("products_test#{suffix}_20130801000000")
old_index.create

Product.search_index.clean_indices
Product.searchkick_index.clean_indices

assert !old_index.exists?
end

def test_retain
Product.reindex
assert_equal 1, Product.search_index.all_indices.size
assert_equal 1, Product.searchkick_index.all_indices.size
Product.reindex(retain: true)
assert_equal 2, Product.search_index.all_indices.size
assert_equal 2, Product.searchkick_index.all_indices.size
end

def test_mappings
store_names ["Dollar Tree"], Store
assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name)
mapping = Store.search_index.mapping
mapping = Store.searchkick_index.mapping
assert_kind_of Hash, mapping
assert_equal "text", mapping.values.first["mappings"]["properties"]["name"]["type"]
end

def test_settings
assert_kind_of Hash, Store.search_index.settings
assert_kind_of Hash, Store.searchkick_index.settings
end

def test_remove_blank_id
store_names ["Product A"]
Product.search_index.remove(Product.new)
Product.searchkick_index.remove(Product.new)
assert_search "product", ["Product A"]
ensure
Product.reindex
Expand All @@ -78,13 +78,13 @@ def test_remove_blank_id
# keep simple for now, but maybe return client response in future
def test_store_response
product = Searchkick.callbacks(false) { Product.create!(name: "Product A") }
assert_nil Product.search_index.store(product)
assert_nil Product.searchkick_index.store(product)
end

# keep simple for now, but maybe return client response in future
def test_bulk_index_response
product = Searchkick.callbacks(false) { Product.create!(name: "Product A") }
assert_nil Product.search_index.bulk_index([product])
assert_nil Product.searchkick_index.bulk_index([product])
end

# TODO move
Expand Down
4 changes: 2 additions & 2 deletions test/inheritance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_child_reindex
end

def test_child_index_name
assert_equal "animals_test#{ENV["TEST_ENV_NUMBER"]}", Dog.search_index.name
assert_equal "animals_test#{ENV["TEST_ENV_NUMBER"]}", Dog.searchkick_index.name
end

def test_child_search
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_index_name_model
def test_index_name_string
store_names ["Product A"]
error = assert_raises Searchkick::Error do
Searchkick.search("product", index_name: [Product.search_index.name]).map(&:name)
Searchkick.search("product", index_name: [Product.searchkick_index.name]).map(&:name)
end
assert_includes error.message, "Unknown model"
end
Expand Down
4 changes: 2 additions & 2 deletions test/match_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def test_stemming
end

def test_stemming_tokens
assert_equal ["milk"], Product.search_index.tokens("milks", analyzer: "searchkick_search")
assert_equal ["milk"], Product.search_index.tokens("milks", analyzer: "searchkick_search2")
assert_equal ["milk"], Product.searchkick_index.tokens("milks", analyzer: "searchkick_search")
assert_equal ["milk"], Product.searchkick_index.tokens("milks", analyzer: "searchkick_search2")
end

# fuzzy
Expand Down
10 changes: 5 additions & 5 deletions test/multi_indices_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ def test_basic

def test_index_name
store_names ["Product A"]
assert_equal ["Product A"], Product.search("product", index_name: Product.search_index.name).map(&:name)
assert_equal ["Product A"], Product.search("product", index_name: Product.searchkick_index.name).map(&:name)
assert_equal ["Product A"], Product.search("product", index_name: Product).map(&:name)

Speaker.search_index.refresh
assert_equal [], Product.search("product", index_name: Speaker.search_index.name, conversions: false).map(&:name)
Speaker.searchkick_index.refresh
assert_equal [], Product.search("product", index_name: Speaker.searchkick_index.name, conversions: false).map(&:name)
end

def test_models_and_index_name
store_names ["Product A"]
store_names ["Product B"], Speaker
assert_equal ["Product A"], Searchkick.search("product", models: [Product, Store], index_name: Product.search_index.name).map(&:name)
assert_equal ["Product A"], Searchkick.search("product", models: [Product, Store], index_name: Product.searchkick_index.name).map(&:name)
error = assert_raises(Searchkick::Error) do
Searchkick.search("product", models: [Product, Store], index_name: Speaker.search_index.name).map(&:name)
Searchkick.search("product", models: [Product, Store], index_name: Speaker.searchkick_index.name).map(&:name)
end
assert_includes error.message, "Unknown model"
# legacy
Expand Down
2 changes: 1 addition & 1 deletion test/notifications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class NotificationsTest < Minitest::Test
def test_search
Product.search_index.refresh
Product.searchkick_index.refresh

notifications = capture_notifications do
Product.search("product").to_a
Expand Down
2 changes: 1 addition & 1 deletion test/order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_multiple
end

def test_unmapped_type
Product.search_index.refresh
Product.searchkick_index.refresh
assert_order "product", [], order: {not_mapped: {unmapped_type: "long"}}
assert_order_relation [], Product.search("product").order(not_mapped: {unmapped_type: "long"})
end
Expand Down
4 changes: 2 additions & 2 deletions test/pagination_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def test_pit

pit_id =
if Searchkick.opensearch?
path = "#{CGI.escape(Product.search_index.name)}/_search/point_in_time"
path = "#{CGI.escape(Product.searchkick_index.name)}/_search/point_in_time"
Searchkick.client.transport.perform_request("POST", path, {keep_alive: "5s"}).body["pit_id"]
else
Searchkick.client.open_point_in_time(index: Product.search_index.name, keep_alive: "5s")["id"]
Searchkick.client.open_point_in_time(index: Product.searchkick_index.name, keep_alive: "5s")["id"]
end

store_names ["Product C", "Product F"]
Expand Down
8 changes: 4 additions & 4 deletions test/partial_reindex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_relation_inline
Searchkick.callbacks(false) do
product.save!
end
Product.search_index.refresh
Product.searchkick_index.refresh

# index not updated
assert_search "hi", ["Hi"], fields: [:name], load: false
Expand Down Expand Up @@ -43,7 +43,7 @@ def test_record_inline
Searchkick.callbacks(false) do
product.save!
end
Product.search_index.refresh
Product.searchkick_index.refresh

# index not updated
assert_search "hi", ["Hi"], fields: [:name], load: false
Expand All @@ -65,7 +65,7 @@ def test_relation_missing
store [{name: "Hi", color: "Blue"}]

product = Product.first
Product.search_index.remove(product)
Product.searchkick_index.remove(product)

error = assert_raises(Searchkick::ImportError) do
Product.reindex(:search_name)
Expand All @@ -77,7 +77,7 @@ def test_record_missing
store [{name: "Hi", color: "Blue"}]

product = Product.first
Product.search_index.remove(product)
Product.searchkick_index.remove(product)

error = assert_raises(Searchkick::ImportError) do
product.reindex(:search_name)
Expand Down
Loading

0 comments on commit 9eddf20

Please sign in to comment.