File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -496,7 +496,8 @@ def ms_without_auto_index_scope=(value)
496496 end
497497
498498 def ms_without_auto_index_scope
499- Thread . current [ "ms_without_auto_index_scope_for_#{ model_name } " ]
499+ Thread . current [ 'ms_without_auto_index_scope' ] ||
500+ Thread . current [ "ms_without_auto_index_scope_for_#{ model_name } " ]
500501 end
501502
502503 def ms_reindex! ( batch_size = MeiliSearch ::Rails ::IndexSettings ::DEFAULT_BATCH_SIZE , synchronous = false )
Original file line number Diff line number Diff line change @@ -51,6 +51,16 @@ def client
5151 . merge ( client_agents : MeiliSearch ::Rails . qualified_version )
5252 )
5353 end
54+
55+ def without_auto_index ( &block )
56+ Thread . current [ 'ms_without_auto_index_scope' ] = true
57+
58+ begin
59+ yield
60+ ensure
61+ Thread . current [ 'ms_without_auto_index_scope' ] = false
62+ end
63+ end
5464 end
5565 end
5666end
Original file line number Diff line number Diff line change 7070 end
7171 end
7272
73+ # while this is not a model method, it's tested here since it's logically similar
74+ # to the model method by the same name
75+ describe 'Meilisearch::Rails.without_auto_index' do
76+ it 'disables auto indexing for all models' do
77+ TestUtil . reset_colors!
78+ TestUtil . reset_books!
79+
80+ MeiliSearch ::Rails . without_auto_index do
81+ Color . create! ( name : 'blue' , short_name : 'b' , hex : 0xFF0000 )
82+ Book . create! (
83+ name : 'Frankenstein' , author : 'Mary Shelley' ,
84+ premium : false , released : true
85+ )
86+ end
87+
88+ expect ( Color . search ( 'blue' ) ) . to be_empty
89+ expect ( Book . search ( 'Frankenstein' ) ) . to be_empty
90+ end
91+ end
92+
7393 describe '.index_documents' do
7494 it 'updates existing documents' do
7595 TestUtil . reset_colors!
You can’t perform that action at this time.
0 commit comments