diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e0943d3a..cff25599 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,26 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-05-27 18:22:30 UTC using RuboCop version 1.27.0. +# on 2024-09-13 15:45:46 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 # versions of RuboCop, may require this file to be generated again. +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'meilisearch-rails.gemspec' + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'meilisearch-rails.gemspec' + # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. @@ -64,14 +79,14 @@ Metrics/BlockLength: # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 169 + Max: 171 -# Offense count: 8 +# Offense count: 9 # Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 27 -# Offense count: 18 +# Offense count: 19 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 102 @@ -123,7 +138,7 @@ RSpec/ContextWording: - 'spec/options_spec.rb' - 'spec/system/tech_shop_spec.rb' -# Offense count: 54 +# Offense count: 55 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 16 @@ -175,7 +190,7 @@ Style/GuardClause: Exclude: - 'lib/meilisearch-rails.rb' -# Offense count: 8 +# Offense count: 7 # This cop supports safe auto-correction (--auto-correct). Style/IfUnlessModifier: Exclude: @@ -217,9 +232,9 @@ Style/StringLiterals: Exclude: - 'spec/ms_clean_up_job_spec.rb' -# Offense count: 16 +# Offense count: 15 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Layout/LineLength: - Max: 170 + Max: 159 diff --git a/lib/meilisearch-rails.rb b/lib/meilisearch-rails.rb index 163a1e0c..a27b03a8 100644 --- a/lib/meilisearch-rails.rb +++ b/lib/meilisearch-rails.rb @@ -88,14 +88,16 @@ def initialize(options, &block) end def warn_searchable_missing_attributes - searchables = get_setting(:searchable_attributes) - attrs = get_setting(:attributes)&.keys + searchables = get_setting(:searchable_attributes)&.map { |searchable| searchable.to_s.split('.').first } + attrs = get_setting(:attributes)&.map { |k, _| k.to_s } if searchables.present? && attrs.present? - (searchables.map(&:to_s) - attrs.map(&:to_s)).each do |missing_searchable| - MeiliSearch::Rails.logger.warn( - "[meilisearch-rails] #{missing_searchable} declared in searchable_attributes but not in attributes. Please add it to attributes if it should be searchable." - ) + (searchables - attrs).each do |missing_searchable| + warning = <<~WARNING + [meilisearch-rails] #{missing_searchable} declared in searchable_attributes but not in attributes. \ + Please add it to attributes if it should be searchable. + WARNING + MeiliSearch::Rails.logger.warn(warning) end end end diff --git a/spec/settings_spec.rb b/spec/settings_spec.rb index 0e7a3dfd..143b6243 100644 --- a/spec/settings_spec.rb +++ b/spec/settings_spec.rb @@ -152,6 +152,26 @@ expect(logger).to have_received(:warn).with(/meilisearch-rails.+last_name/) end end + + context 'when a searchable attribute is nested' do + let(:logger) { instance_double('Logger', warn: nil) } + + before do + allow(MeiliSearch::Rails).to receive(:logger).and_return(logger) + end + + it 'we cannot be certain that it is not defined and don\'t warn the user' do + Comment.meilisearch_settings.add_index(safe_index_uid('nested_searchable_attr_spec')) do + attribute :post do + { title: post&.title } + end + + searchable_attributes ['post.title'] + end + + expect(logger).not_to have_received(:warn) + end + end end describe 'add_index' do diff --git a/spec/support/models/post.rb b/spec/support/models/post.rb index f5b8cd1c..194df20c 100644 --- a/spec/support/models/post.rb +++ b/spec/support/models/post.rb @@ -24,4 +24,9 @@ class Post < ActiveRecord::Base end class Comment < ActiveRecord::Base + belongs_to :post + + include MeiliSearch::Rails + + meilisearch end