Skip to content

Commit 5caa63f

Browse files
authored
Merge pull request #1249 from akostadinov/develop
handle rt and plain indices the same
2 parents 13d0db2 + 4b7cc68 commit 5caa63f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/thinking_sphinx/configuration/minimum_fields.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ def reconcile
1818
attr_reader :indices
1919

2020
def field_collections
21-
plain_indices_without_inheritance.collect(&:sources).flatten +
22-
indices_of_type('rt')
23-
end
24-
25-
def indices_of_type(type)
26-
indices.select { |index| index.type == type }
21+
indices_without_inheritance_of_type('plain').collect(&:sources).flatten +
22+
indices_without_inheritance_of_type('rt')
2723
end
2824

2925
def inheritance_columns?(index)
3026
index.model.table_exists? && index.model.column_names.include?(index.model.inheritance_column)
3127
end
3228

33-
def plain_indices_without_inheritance
34-
indices_of_type('plain').reject(&method(:inheritance_columns?))
29+
def indices_without_inheritance_of_type(type)
30+
indices_without_inheritance.select { |index| index.type == type }
31+
end
32+
33+
def indices_without_inheritance
34+
indices.reject(&method(:inheritance_columns?))
3535
end
3636
end

spec/thinking_sphinx/configuration/minimum_fields_spec.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let(:indices) { [index_a, index_b] }
77
let(:index_a) { double 'Index A', :model => model_a, :type => 'plain',
88
:sources => [double(:fields => [field_a1, field_a2])] }
9-
let(:index_b) { double 'Index B', :model => model_a, :type => 'rt',
9+
let(:index_b) { double 'Index B', :model => model_b, :type => 'rt',
1010
:fields => [field_b1, field_b2] }
1111
let(:field_a1) { double :name => 'sphinx_internal_class_name' }
1212
let(:field_a2) { double :name => 'name' }
@@ -38,7 +38,7 @@
3838
expect(index_b.fields).to eq([field_b2])
3939
end
4040

41-
it 'removes the class name fields only for the indices without type column' do
41+
it 'removes the class name fields only for the rt indices without type column' do
4242
allow(model_a).to receive(:column_names).and_return(['id', 'name', 'type'])
4343
allow(model_b).to receive(:column_names).and_return(['id', 'name'])
4444

@@ -47,4 +47,14 @@
4747
expect(index_a.sources.first.fields).to eq([field_a1, field_a2])
4848
expect(index_b.fields).to eq([field_b2])
4949
end
50+
51+
it 'removes the class name fields only for the plain indices without type column' do
52+
allow(model_a).to receive(:column_names).and_return(['id', 'name'])
53+
allow(model_b).to receive(:column_names).and_return(['id', 'name', 'type'])
54+
55+
subject.reconcile
56+
57+
expect(index_a.sources.first.fields).to eq([field_a2])
58+
expect(index_b.fields).to eq([field_b1, field_b2])
59+
end
5060
end

0 commit comments

Comments
 (0)