|
18 | 18 | require 'spec_helper'
|
19 | 19 |
|
20 | 20 | describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
|
21 |
| - |
22 | 21 | before(:all) do
|
23 | 22 | ActiveRecord::Schema.define(:version => 1) do
|
24 | 23 | create_table :import_articles do |t|
|
|
43 | 42 | end
|
44 | 43 |
|
45 | 44 | describe '#import' do
|
46 |
| - |
47 | 45 | context 'when no search criteria is specified' do
|
48 |
| - |
49 | 46 | before do
|
50 |
| - 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" } |
| 47 | + 10.times { |i| ImportArticle.create! title: 'Test', views: i.to_s } |
51 | 48 | ImportArticle.import
|
52 | 49 | ImportArticle.__elasticsearch__.refresh_index!
|
53 | 50 | end
|
|
58 | 55 | end
|
59 | 56 |
|
60 | 57 | context 'when batch size is specified' do
|
61 |
| - |
62 | 58 | before do
|
63 | 59 | 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
|
64 | 60 | end
|
|
82 | 78 | end
|
83 | 79 |
|
84 | 80 | context 'when a scope is specified' do
|
85 |
| - |
86 | 81 | before do
|
87 | 82 | 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
|
88 | 83 | ImportArticle.import(scope: 'popular', force: true)
|
|
95 | 90 | end
|
96 | 91 |
|
97 | 92 | context 'when a query is specified' do
|
98 |
| - |
99 | 93 | before do
|
100 | 94 | 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
|
101 | 95 | ImportArticle.import(query: -> { where('views >= 3') })
|
|
108 | 102 | end
|
109 | 103 |
|
110 | 104 | context 'when there are invalid documents' do
|
111 |
| - |
112 | 105 | let!(:result) do
|
113 | 106 | 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
|
114 | 107 | new_article
|
|
132 | 125 | end
|
133 | 126 |
|
134 | 127 | context 'when a transform proc is specified' do
|
135 |
| - |
136 | 128 | before do
|
137 | 129 | 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
|
138 | 130 | ImportArticle.import( transform: ->(a) {{ index: { data: { name: a.title, foo: 'BAR' } }}} )
|
|
151 | 143 | end
|
152 | 144 |
|
153 | 145 | context 'when the model has a default scope' do
|
154 |
| - |
155 | 146 | around(:all) do |example|
|
156 | 147 | 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
|
157 | 148 | ImportArticle.instance_eval { default_scope { where('views > 3') } }
|
|
170 | 161 | end
|
171 | 162 |
|
172 | 163 | context 'when there is a default scope and a query specified' do
|
173 |
| - |
174 | 164 | around(:all) do |example|
|
175 | 165 | 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
|
176 | 166 | ImportArticle.instance_eval { default_scope { where('views > 3') } }
|
|
189 | 179 | end
|
190 | 180 |
|
191 | 181 | context 'when the batch is empty' do
|
192 |
| - |
193 | 182 | before do
|
194 | 183 | ImportArticle.delete_all
|
195 | 184 | ImportArticle.import
|
|
0 commit comments