Skip to content

Commit 1422382

Browse files
committed
specs: removes active_record_at_least_4? function and related code
1 parent 8f645f5 commit 1422382

File tree

3 files changed

+50
-95
lines changed

3 files changed

+50
-95
lines changed

elasticsearch-model/spec/elasticsearch/model/adapters/active_record/associations_spec.rb

Lines changed: 48 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
require 'spec_helper'
1919

2020
describe 'Elasticsearch::Model::Adapter::ActiveRecord Associations' do
21-
2221
before(:all) do
2322
ActiveRecord::Schema.define(version: 1) do
2423
create_table :categories do |t|
@@ -76,7 +75,6 @@
7675
end
7776

7877
context 'when a document is created' do
79-
8078
before do
8179
Post.create!(title: 'Test')
8280
Post.create!(title: 'Testing Coding')
@@ -97,9 +95,7 @@
9795
end
9896

9997
describe 'has_many_and_belongs_to association' do
100-
101-
context 'when an association is updated' do
102-
98+
context 'when an association is updated' do
10399
before do
104100
post.categories = [category_a, category_b]
105101
Post.__elasticsearch__.refresh_index!
@@ -119,20 +115,20 @@
119115

120116
let(:search_result) do
121117
Post.search(query: {
122-
bool: {
123-
must: {
124-
multi_match: {
125-
fields: ['title'],
126-
query: 'first'
127-
}
128-
},
129-
filter: {
130-
terms: {
131-
categories: ['One']
132-
}
133-
}
134-
}
135-
} )
118+
bool: {
119+
must: {
120+
multi_match: {
121+
fields: ['title'],
122+
query: 'first'
123+
}
124+
},
125+
filter: {
126+
terms: {
127+
categories: ['One']
128+
}
129+
}
130+
}
131+
} )
136132
end
137133

138134
it 'applies the update with' do
@@ -144,7 +140,6 @@
144140
end
145141

146142
context 'when an association is deleted' do
147-
148143
before do
149144
post.categories = [category_a, category_b]
150145
post.categories = [category_b]
@@ -165,20 +160,20 @@
165160

166161
let(:search_result) do
167162
Post.search(query: {
168-
bool: {
169-
must: {
170-
multi_match: {
171-
fields: ['title'],
172-
query: 'first'
173-
}
174-
},
175-
filter: {
176-
terms: {
177-
categories: ['One']
178-
}
179-
}
180-
}
181-
} )
163+
bool: {
164+
must: {
165+
multi_match: {
166+
fields: ['title'],
167+
query: 'first'
168+
}
169+
},
170+
filter: {
171+
terms: {
172+
categories: ['One']
173+
}
174+
}
175+
}
176+
} )
182177
end
183178

184179
it 'applies the update with a reindex' do
@@ -189,9 +184,7 @@
189184
end
190185

191186
describe 'has_many through association' do
192-
193187
context 'when the association is updated' do
194-
195188
before do
196189
author_a = Author.where(first_name: "John", last_name: "Smith").first_or_create!
197190
author_b = Author.where(first_name: "Mary", last_name: "Smith").first_or_create!
@@ -210,33 +203,17 @@
210203
Post.__elasticsearch__.refresh_index!
211204
end
212205

213-
context 'if active record is at least 4' do
214-
215-
let(:search_result) do
216-
Post.search('authors.full_name:john')
217-
end
218-
219-
it 'applies the update', if: active_record_at_least_4? do
220-
expect(search_result.results.size).to eq(2)
221-
expect(search_result.records.size).to eq(2)
222-
end
206+
let(:search_result) do
207+
Post.search('authors.full_name:john')
223208
end
224209

225-
context 'if active record is less than 4' do
226-
227-
let(:search_result) do
228-
Post.search('authors.author.full_name:john')
229-
end
230-
231-
it 'applies the update', if: !active_record_at_least_4? do
232-
expect(search_result.results.size).to eq(2)
233-
expect(search_result.records.size).to eq(2)
234-
end
210+
it 'applies the update' do
211+
expect(search_result.results.size).to eq(2)
212+
expect(search_result.records.size).to eq(2)
235213
end
236214
end
237215

238-
context 'when an association is added', if: active_record_at_least_4? do
239-
216+
context 'when an association is added' do
240217
before do
241218
author_a = Author.where(first_name: "John", last_name: "Smith").first_or_create!
242219
author_b = Author.where(first_name: "Mary", last_name: "Smith").first_or_create!
@@ -262,9 +239,7 @@
262239
end
263240

264241
describe 'has_many association' do
265-
266-
context 'when an association is added', if: active_record_at_least_4? do
267-
242+
context 'when an association is added' do
268243
before do
269244
# Create posts
270245
post_1 = Post.create!(title: "First Post", text: "This is the first post...")
@@ -282,18 +257,18 @@
282257

283258
let(:search_result) do
284259
Post.search(query: {
285-
nested: {
286-
path: 'comments',
287-
query: {
288-
bool: {
289-
must: [
290-
{ match: { 'comments.author' => 'john' } },
291-
{ match: { 'comments.text' => 'good' } }
292-
]
293-
}
294-
}
295-
}
296-
})
260+
nested: {
261+
path: 'comments',
262+
query: {
263+
bool: {
264+
must: [
265+
{ match: { 'comments.author' => 'john' } },
266+
{ match: { 'comments.text' => 'good' } }
267+
]
268+
}
269+
}
270+
}
271+
})
297272
end
298273

299274
it 'adds the association' do
@@ -303,9 +278,7 @@
303278
end
304279

305280
describe '#touch' do
306-
307281
context 'when a touch callback is defined on the model' do
308-
309282
before do
310283
# Create categories
311284
category_a = Category.where(title: "One").first_or_create!
@@ -329,7 +302,6 @@
329302
end
330303

331304
describe '#includes' do
332-
333305
before do
334306
post_1 = Post.create(title: 'One')
335307
post_2 = Post.create(title: 'Two')

elasticsearch-model/spec/elasticsearch/model/adapters/active_record/basic_spec.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,31 +327,23 @@
327327
end
328328

329329
describe 'ordering of SQL queries' do
330-
331330
context 'when order is called on the ActiveRecord query' do
332-
333331
let(:search_result) do
334332
Article.search query: { match: { title: { query: 'test' } } }
335333
end
336334

337-
it 'allows the SQL query to be ordered independent of the Elasticsearch results order', unless: active_record_at_least_4? do
338-
expect(search_result.records.order('title DESC').first.title).to eq('Testing Coding')
339-
expect(search_result.records.order('title DESC')[0].title).to eq('Testing Coding')
340-
end
341-
342-
it 'allows the SQL query to be ordered independent of the Elasticsearch results order', if: active_record_at_least_4? do
335+
it 'allows the SQL query to be ordered independent of the Elasticsearch results order' do
343336
expect(search_result.records.order(title: :desc).first.title).to eq('Testing Coding')
344337
expect(search_result.records.order(title: :desc)[0].title).to eq('Testing Coding')
345338
end
346339
end
347340

348341
context 'when more methods are chained on the ActiveRecord query' do
349-
350342
let(:search_result) do
351343
Article.search query: {match: {title: {query: 'test'}}}
352344
end
353345

354-
it 'allows the SQL query to be ordered independent of the Elasticsearch results order', if: active_record_at_least_4? do
346+
it 'allows the SQL query to be ordered independent of the Elasticsearch results order' do
355347
expect(search_result.records.distinct.order(title: :desc).first.title).to eq('Testing Coding')
356348
expect(search_result.records.distinct.order(title: :desc)[0].title).to eq('Testing Coding')
357349
end

elasticsearch-model/spec/spec_helper.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,6 @@
6565
end
6666
end
6767

68-
# Is the ActiveRecord version at least 4.0?
69-
#
70-
# @return [ true, false ] Whether the ActiveRecord version is at least 4.0.
71-
#
72-
# @since 6.0.1
73-
def active_record_at_least_4?
74-
defined?(::ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 4
75-
end
76-
7768
# Delete all documents from the indices of the provided list of models.
7869
#
7970
# @param [ Array<ActiveRecord::Base> ] models The list of models.

0 commit comments

Comments
 (0)