Skip to content

Commit 3f69153

Browse files
committed
[MODEL] Added integration test for importing Mongoid models
1 parent cfd6f29 commit 3f69153

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

elasticsearch-model/test/integration/mongoid_basic_test.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,35 @@ def as_indexed_json(options={})
134134
assert_equal 'Testing Coding', response.records.first.title
135135
end
136136

137+
138+
context "importing" do
139+
setup do
140+
MongoidArticle.delete_all
141+
97.times { |i| MongoidArticle.create! title: "Test #{i}" }
142+
MongoidArticle.__elasticsearch__.create_index! force: true
143+
end
144+
145+
should "import all the documents" do
146+
assert_equal 97, MongoidArticle.count
147+
148+
MongoidArticle.__elasticsearch__.refresh_index!
149+
assert_equal 0, MongoidArticle.search('*').results.total
150+
151+
batches = 0
152+
errors = MongoidArticle.import(batch_size: 10) do |response|
153+
batches += 1
154+
end
155+
156+
assert_equal 0, errors
157+
assert_equal 10, batches
158+
159+
MongoidArticle.__elasticsearch__.refresh_index!
160+
assert_equal 97, MongoidArticle.search('*').results.total
161+
162+
response = MongoidArticle.search('test')
163+
assert response.results.any?, "Search has not returned results: #{response.to_a}"
164+
end
165+
end
137166
end
138167

139168
end

0 commit comments

Comments
 (0)