Skip to content

Commit eefe6be

Browse files
committed
Refactor proximity_precision test
1 parent 84d355b commit eefe6be

File tree

4 files changed

+16
-39
lines changed

4 files changed

+16
-39
lines changed

spec/integration_spec.rb

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,3 @@
2020
end
2121
end
2222

23-
describe 'proximity_precision' do
24-
before do
25-
stub_const(
26-
'OtherColor',
27-
Class.new do
28-
include ActiveModel::Model
29-
include MeiliSearch::Rails
30-
end
31-
)
32-
end
33-
34-
context 'when the value is byWord' do
35-
before do
36-
OtherColor.meilisearch synchronize: true, index_uid: safe_index_uid('OtherColors') do
37-
proximity_precision 'byWord'
38-
end
39-
end
40-
41-
it 'sets the value byWord to proximity precision' do
42-
AsyncHelper.await_last_task
43-
expect(OtherColor.index.get_settings['proximityPrecision']).to eq('byWord')
44-
end
45-
end
46-
47-
context 'when the value is byAttribute' do
48-
before do
49-
OtherColor.meilisearch synchronize: true, index_uid: safe_index_uid('OtherColors') do
50-
proximity_precision 'byAttribute'
51-
end
52-
end
53-
54-
it 'sets the value byAttribute to proximity precision' do
55-
OtherColor.index.get_settings # induce update_settings
56-
AsyncHelper.await_last_task
57-
expect(OtherColor.index.get_settings['proximityPrecision']).to eq('byAttribute')
58-
end
59-
end
60-
end
61-

spec/settings_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'support/models/restaurant'
55
require 'support/models/specialty_models'
66
require 'support/models/song'
7+
require 'support/models/color'
78

89
describe MeiliSearch::Rails::IndexSettings do
910
describe 'attribute' do
@@ -113,6 +114,18 @@
113114
end
114115
end
115116

117+
describe 'proximity_precision' do
118+
it 'can be set to byWord' do
119+
expect(Color.index.get_settings['proximityPrecision']).to eq('byWord')
120+
end
121+
122+
it 'can be set to byAttribute' do
123+
Song.create!(name: 'Coconut nut', artist: 'Smokey Mountain', premium: false, released: true)
124+
AsyncHelper.await_last_task
125+
expect(Song.index.get_settings['proximityPrecision']).to eq('byAttribute')
126+
end
127+
end
128+
116129
describe 'force_utf8_encoding' do
117130
it 'converts to utf8' do
118131
EncodedString.create!

spec/support/models/color.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Color < ActiveRecord::Base
2525
]
2626
attributes_to_highlight [:name]
2727
faceting max_values_per_facet: 20
28+
proximity_precision 'byWord'
2829
end
2930

3031
def will_save_change_to_hex?

spec/support/models/song.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Song < ActiveRecord::Base
1919
add_index PUBLIC_INDEX_UID, if: :public? do
2020
searchable_attributes %i[name artist]
2121
end
22+
23+
proximity_precision 'byAttribute'
2224
end
2325

2426
private

0 commit comments

Comments
 (0)