diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e70bcb1..7757142 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-03-08 11:51:39 UTC using RuboCop version 1.27.0. +# on 2025-03-14 19:22:00 UTC using RuboCop version 1.27.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -30,13 +30,6 @@ Layout/EmptyLinesAroundModuleBody: Exclude: - 'lib/meilisearch-rails.rb' -# Offense count: 2 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/FirstArrayElementIndentation: - EnforcedStyle: consistent - # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. @@ -146,7 +139,7 @@ RSpec/ContextWording: - 'spec/options_spec.rb' - 'spec/system/tech_shop_spec.rb' -# Offense count: 57 +# Offense count: 61 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 16 @@ -174,7 +167,7 @@ RSpec/MultipleDescribes: Exclude: - 'spec/search_spec.rb' -# Offense count: 2 +# Offense count: 3 RSpec/NestedGroups: Max: 4 @@ -184,12 +177,12 @@ RSpec/VerifiedDoubles: Exclude: - 'spec/configuration_spec.rb' -# Offense count: 1 +# Offense count: 3 # Configuration parameters: ForbiddenMethods, AllowedMethods. # ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all Rails/SkipsModelValidations: Exclude: - - 'spec/settings_spec.rb' + - 'spec/multi_search_spec.rb' # Offense count: 2 # This cop supports safe auto-correction (--auto-correct). @@ -247,7 +240,7 @@ Style/StringLiterals: Exclude: - 'spec/ms_clean_up_job_spec.rb' -# Offense count: 15 +# Offense count: 16 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/spec/multi_search_spec.rb b/spec/multi_search_spec.rb index 7f86696..a0cb38a 100644 --- a/spec/multi_search_spec.rb +++ b/spec/multi_search_spec.rb @@ -4,33 +4,37 @@ require 'support/models/color' describe 'multi-search' do - def reset_indexes + before do [Book, Color, Product].each do |klass| klass.delete_all - klass.clear_index!(true) + klass.clear_index! end - end - before do - reset_indexes - - Product.create! name: 'palm pixi plus', href: 'ebay', tags: ['terrible'] - Product.create! name: 'lg vortex', href: 'ebay', tags: ['decent'] - Product.create! name: 'palmpre', href: 'ebay', tags: ['discontinued', 'worst phone ever'] + Product.insert_all([ + { name: 'palm pixi plus', href: 'ebay', tags: ['terrible'] }, + { name: 'lg vortex', href: 'ebay', tags: ['decent'] }, + { name: 'palmpre', href: 'ebay', tags: ['discontinued', 'worst phone ever'] } + ]) Product.reindex! - Color.create! name: 'blue', short_name: 'blu', hex: 0x0000FF - Color.create! name: 'black', short_name: 'bla', hex: 0x000000 - Color.create! name: 'green', short_name: 'gre', hex: 0x00FF00 - - Book.create! name: 'Steve Jobs', author: 'Walter Isaacson' - Book.create! name: 'Moby Dick', author: 'Herman Melville' + Color.insert_all([ + { name: 'blue', short_name: 'blu', hex: 0x0000FF }, + { name: 'black', short_name: 'bla', hex: 0x000000 }, + { name: 'green', short_name: 'gre', hex: 0x00FF00 } + ]) + Color.reindex! + + Book.insert_all([ + { name: 'Steve Jobs', author: 'Walter Isaacson' }, + { name: 'Moby Dick', author: 'Herman Melville' } + ]) + Book.reindex! end - let!(:palm_pixi_plus) { Product.find_by name: 'palm pixi plus' } - let!(:steve_jobs) { Book.find_by name: 'Steve Jobs' } - let!(:blue) { Color.find_by name: 'blue' } - let!(:black) { Color.find_by name: 'black' } + let(:palm_pixi_plus) { Product.find_by name: 'palm pixi plus' } + let(:steve_jobs) { Book.find_by name: 'Steve Jobs' } + let(:blue) { Color.find_by name: 'blue' } + let(:black) { Color.find_by name: 'black' } context 'with class keys' do it 'returns ORM records' do @@ -40,8 +44,10 @@ def reset_indexes Color => { q: 'bl' } ) - expect(results).to contain_exactly( - steve_jobs, palm_pixi_plus, blue, black + expect(results.to_h).to match( + Book => [steve_jobs], + Product => [palm_pixi_plus], + Color => contain_exactly(blue, black) ) end end @@ -65,11 +71,13 @@ def reset_indexes 'colors' => { q: 'bl', index_uid: Color.index.uid } ) - expect(results).to contain_exactly( - a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs'), - a_hash_including('name' => 'palm pixi plus'), - a_hash_including('name' => 'blue', 'short_name' => 'blu'), - a_hash_including('name' => 'black', 'short_name' => 'bla') + expect(results.to_h).to match( + 'books' => [a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs')], + 'products' => [a_hash_including('name' => 'palm pixi plus')], + 'colors' => contain_exactly( + a_hash_including('name' => 'blue', 'short_name' => 'blu'), + a_hash_including('name' => 'black', 'short_name' => 'bla') + ) ) end @@ -82,10 +90,10 @@ def reset_indexes 'nature_colors' => { q: 'green', index_uid: index_uid } ) - expect(results).to contain_exactly( - a_hash_including('name' => 'blue', 'short_name' => 'blu'), - a_hash_including('name' => 'black', 'short_name' => 'bla'), - a_hash_including('name' => 'green', 'short_name' => 'gre') + expect(results.to_h).to match( + 'bright_colors' => [a_hash_including('name' => 'blue', 'short_name' => 'blu')], + 'dark_colors' => [a_hash_including('name' => 'black', 'short_name' => 'bla')], + 'nature_colors' => [a_hash_including('name' => 'green', 'short_name' => 'gre')] ) end @@ -97,8 +105,10 @@ def reset_indexes 'colors' => { q: 'bl', index_uid: Color.index.uid, class_name: 'Color' } ) - expect(results).to contain_exactly( - steve_jobs, palm_pixi_plus, blue, black + expect(results.to_h).to match( + 'books' => [steve_jobs], + 'products' => [palm_pixi_plus], + 'colors' => contain_exactly(blue, black) ) end end @@ -113,11 +123,13 @@ def reset_indexes Color.index.uid => { q: 'bl' } ) - expect(results).to contain_exactly( - a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs'), - a_hash_including('name' => 'palm pixi plus'), - a_hash_including('name' => 'blue', 'short_name' => 'blu'), - a_hash_including('name' => 'black', 'short_name' => 'bla') + expect(results.to_h).to match( + Book.index.uid => [a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs')], + Product.index.uid.to_sym => [a_hash_including('name' => 'palm pixi plus')], + Color.index.uid => contain_exactly( + a_hash_including('name' => 'blue', 'short_name' => 'blu'), + a_hash_including('name' => 'black', 'short_name' => 'bla') + ) ) end @@ -129,8 +141,10 @@ def reset_indexes Color.index.uid => { q: 'bl', class_name: 'Color' } ) - expect(results).to contain_exactly( - steve_jobs, palm_pixi_plus, blue, black + expect(results.to_h).to match( + Book.index.uid => [steve_jobs], + Product.index.uid.to_sym => [palm_pixi_plus], + Color.index.uid => contain_exactly(blue, black) ) end @@ -154,10 +168,13 @@ def reset_indexes Color.index.uid => { q: 'bl' } ) - expect(results).to contain_exactly( - steve_jobs, palm_pixi_plus, - a_hash_including('name' => 'blue', 'short_name' => 'blu'), - a_hash_including('name' => 'black', 'short_name' => 'bla') + expect(results.to_h).to match( + Book => [steve_jobs], + Product.index_uid => [palm_pixi_plus], + Color.index.uid => contain_exactly( + a_hash_including('name' => 'blue', 'short_name' => 'blu'), + a_hash_including('name' => 'black', 'short_name' => 'bla') + ) ) end end @@ -172,9 +189,12 @@ def reset_indexes Color.index.uid => { q: 'bl', page: 1, 'hitsPerPage' => '1' } ) - expect(results).to contain_exactly( - steve_jobs, palm_pixi_plus, - a_hash_including('name' => 'black', 'short_name' => 'bla') + expect(results.to_h).to match( + Book => [steve_jobs], + Product => [palm_pixi_plus], + Color.index_uid => contain_exactly( + a_hash_including('name' => 'black', 'short_name' => 'bla') + ) ) MeiliSearch::Rails.configuration[:pagination_backend] = nil