Skip to content

Commit fb6354e

Browse files
committed
Fix conflicts and update code to work in v1.3
1 parent 537bf61 commit fb6354e

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

lib/meilisearch/utils.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ module Utils
55
SNAKE_CASE = /[^a-zA-Z0-9]+(.)/.freeze
66

77
def self.transform_attributes(body)
8-
warn_on_non_conforming_attribute_names(body)
9-
108
case body
119
when Array
1210
body.map { |item| transform_attributes(item) }
1311
when Hash
12+
warn_on_non_conforming_attribute_names(body)
1413
parse(body)
1514
else
1615
body

spec/meilisearch/index/settings_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ def update_synonyms(index, synonyms)
773773
update_task = index.update_faceting({ 'max_values_per_facet' => 333 })
774774
client.wait_for_task(update_task['taskUid'])
775775

776-
expect(index.faceting).to eq({ 'maxValuesPerFacet' => 333 })
776+
expect(index.faceting['maxValuesPerFacet']).to eq(333)
777+
expect(index.faceting.transform_keys(&:to_sym).keys).to include(*default_faceting.keys)
777778
end
778779

779780
it 'updates faceting at null' do

spec/meilisearch/utils_spec.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,47 @@
4545
]
4646
)
4747
end
48+
49+
it 'warns when using camelCase' do
50+
attrs = { distinctAttribute: 'title' }
51+
52+
expect do
53+
described_class.transform_attributes(attrs)
54+
end.to output(include('Attributes will be expected to be snake_case', 'distinctAttribute')).to_stderr
55+
end
56+
57+
it 'warns when using camelCase in an array' do
58+
attrs = [
59+
{ 'index_uid' => 'movies', 'q' => 'prince' },
60+
{ 'indexUid' => 'books', 'q' => 'prince' }
61+
]
62+
63+
expect do
64+
described_class.transform_attributes(attrs)
65+
end.to output(include('Attributes will be expected to be snake_case', 'indexUid')).to_stderr
66+
end
4867
end
4968

5069
describe '.version_error_handler' do
5170
it 'spawns same error message' do
5271
expect do
53-
MeiliSearch::Utils.version_error_handler(:my_method) do
72+
described_class.version_error_handler(:my_method) do
5473
raise MeiliSearch::ApiError.new(405, 'I came from Meili server', {})
5574
end
5675
end.to raise_error(MeiliSearch::ApiError, /I came from Meili server/)
5776
end
5877

5978
it 'spawns message with version hint' do
6079
expect do
61-
MeiliSearch::Utils.version_error_handler(:my_method) do
80+
described_class.version_error_handler(:my_method) do
6281
raise MeiliSearch::ApiError.new(405, 'I came from Meili server', {})
6382
end
6483
end.to raise_error(MeiliSearch::ApiError, /that `my_method` call requires/)
6584
end
6685

6786
it 'adds hints to all error types' do
6887
expect do
69-
MeiliSearch::Utils.version_error_handler(:my_method) do
88+
described_class.version_error_handler(:my_method) do
7089
raise MeiliSearch::CommunicationError, 'I am an error'
7190
end
7291
end.to raise_error(MeiliSearch::CommunicationError, /that `my_method` call requires/)
@@ -77,23 +96,23 @@
7796
attrs = { attributesToHighlight: ['field'] }
7897

7998
expect do
80-
Utils.warn_on_non_conforming_attribute_names(attrs)
99+
described_class.warn_on_non_conforming_attribute_names(attrs)
81100
end.to output(include('Attributes will be expected to be snake_case', 'attributesToHighlight')).to_stderr
82101
end
83102

84103
it 'warns when using a mixed case' do
85104
attrs = { distinct_ATTribute: 'title' }
86105

87106
expect do
88-
Utils.warn_on_non_conforming_attribute_names(attrs)
107+
described_class.warn_on_non_conforming_attribute_names(attrs)
89108
end.to output(include('Attributes will be expected to be snake_case', 'distinct_ATTribute')).to_stderr
90109
end
91110

92111
it 'does not warn when using snake_case' do
93112
attrs = { q: 'query', attributes_to_highlight: ['field'] }
94113

95114
expect do
96-
Utils.warn_on_non_conforming_attribute_names(attrs)
115+
described_class.warn_on_non_conforming_attribute_names(attrs)
97116
end.not_to output.to_stderr
98117
end
99118
end

0 commit comments

Comments
 (0)