Skip to content

Commit 6e52a08

Browse files
committed
[MODEL] Add test for not importing when ActiveRecord query is empty
1 parent f2a89cd commit 6e52a08

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

elasticsearch-model/test/integration/active_record_import_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@ class ::ImportArticle < ActiveRecord::Base
163163
assert_equal 1, ImportArticle.search('*').results.total
164164
end
165165
end
166+
167+
context 'ActiveRecord importing when the batch is empty' do
168+
169+
setup do
170+
Object.send(:remove_const, :ImportArticle) if defined?(ImportArticle)
171+
class ::ImportArticle < ActiveRecord::Base
172+
include Elasticsearch::Model
173+
mapping { indexes :title, type: 'text' }
174+
end
175+
176+
ActiveRecord::Schema.define(:version => 1) do
177+
create_table :import_articles do |t|
178+
t.string :title
179+
end
180+
end
181+
182+
ImportArticle.delete_all
183+
ImportArticle.__elasticsearch__.delete_index! force: true
184+
ImportArticle.__elasticsearch__.create_index! force: true
185+
ImportArticle.__elasticsearch__.client.cluster.health wait_for_status: 'yellow'
186+
end
187+
188+
should 'not make any requests to create documents to Elasticsearch' do
189+
assert_equal 0, ImportArticle.count
190+
assert_equal 0, ImportArticle.import
191+
192+
ImportArticle.__elasticsearch__.refresh_index!
193+
assert_equal 0, ImportArticle.search('*').results.total
194+
end
195+
end
166196
end
167197
end
168198
end

0 commit comments

Comments
 (0)