File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,20 @@ def self.version_error_handler(method_name)
5252 raise e . class , message_builder ( e . message , method_name )
5353 end
5454
55+ def self . warn_on_non_conforming_attribute_names ( body )
56+ non_snake_case = body . keys . grep_v ( /^[a-z0-9_]+$/ )
57+
58+ return if non_snake_case . empty?
59+
60+ message = <<~MSG
61+ Attributes will be expected to be snake_case in future versions of MeiliSearch.
62+
63+ Non-conforming attributes: #{ non_snake_case . join ( ', ' ) }
64+ MSG
65+
66+ warn ( message )
67+ end
68+
5569 private_class_method :parse , :message_builder
5670 end
5771end
Original file line number Diff line number Diff line change 7171 end
7272 end . to raise_error ( MeiliSearch ::CommunicationError , /that `my_method` call requires/ )
7373 end
74+
75+ describe '.warn_on_non_conforming_attribute_names' do
76+ it 'warns when using camelCase attributes' do
77+ attrs = { attributesToHighlight : [ 'field' ] }
78+
79+ expect do
80+ Utils . warn_on_non_conforming_attribute_names ( attrs )
81+ end . to output ( include ( 'Attributes will be expected to be snake_case' , 'attributesToHighlight' ) ) . to_stderr
82+ end
83+
84+ it 'warns when using a mixed case' do
85+ attrs = { distinct_ATTribute : 'title' }
86+
87+ expect do
88+ Utils . warn_on_non_conforming_attribute_names ( attrs )
89+ end . to output ( include ( 'Attributes will be expected to be snake_case' , 'distinct_ATTribute' ) ) . to_stderr
90+ end
91+
92+ it 'does not warn when using snake_case' do
93+ attrs = { q : 'query' , attributes_to_highlight : [ 'field' ] }
94+
95+ expect do
96+ Utils . warn_on_non_conforming_attribute_names ( attrs )
97+ end . not_to output . to_stderr
98+ end
99+ end
74100 end
75101end
You can’t perform that action at this time.
0 commit comments