thinking-sphinx 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Appraisals +13 -0
- data/Gemfile +2 -1
- data/HISTORY +19 -0
- data/README.textile +3 -2
- data/gemfiles/rails_3_2.gemfile +2 -1
- data/gemfiles/rails_4_0.gemfile +2 -1
- data/gemfiles/rails_4_1.gemfile +2 -1
- data/gemfiles/rails_4_2.gemfile +2 -1
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/lib/thinking_sphinx.rb +2 -0
- data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
- data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
- data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
- data/lib/thinking_sphinx/configuration.rb +3 -2
- data/lib/thinking_sphinx/connection.rb +23 -10
- data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
- data/lib/thinking_sphinx/errors.rb +25 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
- data/lib/thinking_sphinx/railtie.rb +1 -1
- data/lib/thinking_sphinx/rake_interface.rb +71 -23
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
- data/lib/thinking_sphinx/real_time/populator.rb +3 -3
- data/lib/thinking_sphinx/tasks.rb +7 -8
- data/lib/thinking_sphinx/wildcard.rb +1 -1
- data/spec/acceptance/association_scoping_spec.rb +5 -5
- data/spec/acceptance/attribute_access_spec.rb +4 -4
- data/spec/acceptance/attribute_updates_spec.rb +3 -3
- data/spec/acceptance/batch_searching_spec.rb +4 -4
- data/spec/acceptance/big_integers_spec.rb +6 -6
- data/spec/acceptance/connection_spec.rb +23 -0
- data/spec/acceptance/excerpts_spec.rb +8 -8
- data/spec/acceptance/facets_spec.rb +13 -13
- data/spec/acceptance/geosearching_spec.rb +8 -8
- data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
- data/spec/acceptance/index_options_spec.rb +16 -16
- data/spec/acceptance/indexing_spec.rb +3 -3
- data/spec/acceptance/paginating_search_results_spec.rb +3 -3
- data/spec/acceptance/real_time_updates_spec.rb +4 -4
- data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
- data/spec/acceptance/search_counts_spec.rb +2 -2
- data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
- data/spec/acceptance/searching_across_models_spec.rb +6 -6
- data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
- data/spec/acceptance/searching_on_fields_spec.rb +9 -9
- data/spec/acceptance/searching_with_filters_spec.rb +16 -16
- data/spec/acceptance/searching_with_sti_spec.rb +9 -9
- data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
- data/spec/acceptance/sorting_search_results_spec.rb +6 -6
- data/spec/acceptance/specifying_sql_spec.rb +62 -62
- data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
- data/spec/acceptance/sql_deltas_spec.rb +7 -7
- data/spec/acceptance/support/database_cleaner.rb +1 -1
- data/spec/acceptance/support/sphinx_controller.rb +4 -1
- data/spec/acceptance/support/sphinx_helpers.rb +4 -0
- data/spec/acceptance/suspended_deltas_spec.rb +9 -9
- data/spec/internal/app/indices/article_index.rb +2 -2
- data/spec/internal/app/indices/book_index.rb +2 -1
- data/spec/internal/app/indices/product_index.rb +0 -2
- data/spec/internal/app/models/categorisation.rb +8 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/json_column.rb +5 -1
- data/spec/support/multi_schema.rb +3 -1
- data/spec/support/sphinx_yaml_helpers.rb +1 -1
- data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
- data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
- data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
- data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
- data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
- data/spec/thinking_sphinx/configuration_spec.rb +81 -81
- data/spec/thinking_sphinx/connection_spec.rb +13 -13
- data/spec/thinking_sphinx/deletion_spec.rb +11 -11
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
- data/spec/thinking_sphinx/deltas_spec.rb +12 -12
- data/spec/thinking_sphinx/errors_spec.rb +30 -30
- data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
- data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
- data/spec/thinking_sphinx/index_set_spec.rb +7 -7
- data/spec/thinking_sphinx/index_spec.rb +24 -24
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
- data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
- data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
- data/spec/thinking_sphinx/scopes_spec.rb +5 -5
- data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
- data/spec/thinking_sphinx/search/query_spec.rb +10 -10
- data/spec/thinking_sphinx/search_spec.rb +28 -28
- data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
- data/spec/thinking_sphinx_spec.rb +6 -6
- data/thinking-sphinx.gemspec +4 -4
- metadata +12 -9
@@ -5,50 +5,50 @@ describe 'Suspend deltas for a given action', :live => true do
|
|
5
5
|
book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
|
6
6
|
index
|
7
7
|
|
8
|
-
Book.search('Harry').to_a.
|
8
|
+
expect(Book.search('Harry').to_a).to eq([book])
|
9
9
|
|
10
10
|
ThinkingSphinx::Deltas.suspend :book do
|
11
11
|
book.reload.update_attributes(:author => 'Terry Pratchett')
|
12
12
|
sleep 0.25
|
13
13
|
|
14
|
-
Book.search('Terry').to_a.
|
14
|
+
expect(Book.search('Terry').to_a).to eq([])
|
15
15
|
end
|
16
16
|
|
17
17
|
sleep 0.25
|
18
|
-
Book.search('Terry').to_a.
|
18
|
+
expect(Book.search('Terry').to_a).to eq([book])
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns core records even though they are no longer valid" do
|
22
22
|
book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
|
23
23
|
index
|
24
24
|
|
25
|
-
Book.search('Harry').to_a.
|
25
|
+
expect(Book.search('Harry').to_a).to eq([book])
|
26
26
|
|
27
27
|
ThinkingSphinx::Deltas.suspend :book do
|
28
28
|
book.reload.update_attributes(:author => 'Terry Pratchett')
|
29
29
|
sleep 0.25
|
30
30
|
|
31
|
-
Book.search('Terry').to_a.
|
31
|
+
expect(Book.search('Terry').to_a).to eq([])
|
32
32
|
end
|
33
33
|
|
34
34
|
sleep 0.25
|
35
|
-
Book.search('Harry').to_a.
|
35
|
+
expect(Book.search('Harry').to_a).to eq([book])
|
36
36
|
end
|
37
37
|
|
38
38
|
it "marks core records as deleted" do
|
39
39
|
book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
|
40
40
|
index
|
41
41
|
|
42
|
-
Book.search('Harry').to_a.
|
42
|
+
expect(Book.search('Harry').to_a).to eq([book])
|
43
43
|
|
44
44
|
ThinkingSphinx::Deltas.suspend_and_update :book do
|
45
45
|
book.reload.update_attributes(:author => 'Terry Pratchett')
|
46
46
|
sleep 0.25
|
47
47
|
|
48
|
-
Book.search('Terry').to_a.
|
48
|
+
expect(Book.search('Terry').to_a).to eq([])
|
49
49
|
end
|
50
50
|
|
51
51
|
sleep 0.25
|
52
|
-
Book.search('Harry').to_a.
|
52
|
+
expect(Book.search('Harry').to_a).to be_empty
|
53
53
|
end
|
54
54
|
end
|
@@ -5,7 +5,7 @@ ThinkingSphinx::Index.define :article, :with => :active_record do
|
|
5
5
|
|
6
6
|
has published, user_id
|
7
7
|
has taggings.tag_id, :as => :tag_ids, :source => :query
|
8
|
-
has taggings.created_at, :as => :taggings_at
|
8
|
+
has taggings.created_at, :as => :taggings_at, :type => :timestamp
|
9
9
|
|
10
10
|
set_property :min_infix_len => 4
|
11
11
|
set_property :enable_star => true
|
@@ -18,7 +18,7 @@ ThinkingSphinx::Index.define :article, :with => :active_record,
|
|
18
18
|
|
19
19
|
has published, user_id
|
20
20
|
has taggings.tag_id, :as => :tag_ids
|
21
|
-
has taggings.created_at, :as => :taggings_at
|
21
|
+
has taggings.created_at, :as => :taggings_at, :type => :timestamp
|
22
22
|
|
23
23
|
set_property :morphology => 'stem_en'
|
24
24
|
end
|
@@ -8,8 +8,6 @@ ThinkingSphinx::Index.define :product, :with => :real_time do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
if multi_schema.active?
|
11
|
-
multi_schema.create 'thinking_sphinx'
|
12
|
-
|
13
11
|
ThinkingSphinx::Index.define(:product,
|
14
12
|
:name => :product_two, :offset_as => :product_two, :with => :real_time
|
15
13
|
) do
|
@@ -2,5 +2,12 @@ class Categorisation < ActiveRecord::Base
|
|
2
2
|
belongs_to :category
|
3
3
|
belongs_to :product
|
4
4
|
|
5
|
-
|
5
|
+
after_commit :update_product
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def update_product
|
10
|
+
product.reload
|
11
|
+
ThinkingSphinx::RealTime.callback_for(:product, [:product]).after_save self
|
12
|
+
end
|
6
13
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/json_column.rb
CHANGED
@@ -6,7 +6,7 @@ class JSONColumn
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call
|
9
|
-
postgresql? && column?
|
9
|
+
sphinx? && postgresql? && column?
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
@@ -26,4 +26,8 @@ class JSONColumn
|
|
26
26
|
def postgresql?
|
27
27
|
ENV['DATABASE'] == 'postgresql'
|
28
28
|
end
|
29
|
+
|
30
|
+
def sphinx?
|
31
|
+
ENV['SPHINX_VERSION'].nil? || ENV['SPHINX_VERSION'].to_f > 2.0
|
32
|
+
end
|
29
33
|
end
|
@@ -4,12 +4,14 @@ class MultiSchema
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def create(schema_name)
|
7
|
+
return unless active?
|
8
|
+
|
7
9
|
unless connection.schema_exists? schema_name
|
8
10
|
connection.execute %Q{CREATE SCHEMA "#{schema_name}"}
|
9
11
|
end
|
10
12
|
|
11
13
|
switch schema_name
|
12
|
-
|
14
|
+
load Rails.root.join('db', 'schema.rb')
|
13
15
|
end
|
14
16
|
|
15
17
|
def current
|
@@ -23,52 +23,55 @@ describe ThinkingSphinx::ActiveRecord::Attribute::Type do
|
|
23
23
|
before :each do
|
24
24
|
column.__stack << :foo
|
25
25
|
|
26
|
-
model.
|
26
|
+
allow(model).to receive(:reflect_on_association).and_return(association)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns true if there are has_many associations" do
|
30
|
-
association.
|
30
|
+
allow(association).to receive(:macro).and_return(:has_many)
|
31
31
|
|
32
|
-
type.
|
32
|
+
expect(type).to be_multi
|
33
33
|
end
|
34
34
|
|
35
35
|
it "returns true if there are has_and_belongs_to_many associations" do
|
36
|
-
association.
|
36
|
+
allow(association).to receive(:macro).and_return(:has_and_belongs_to_many)
|
37
37
|
|
38
|
-
type.
|
38
|
+
expect(type).to be_multi
|
39
39
|
end
|
40
40
|
|
41
41
|
it "returns false if there are no associations" do
|
42
42
|
column.__stack.clear
|
43
43
|
|
44
|
-
type.
|
44
|
+
expect(type).not_to be_multi
|
45
45
|
end
|
46
46
|
|
47
47
|
it "returns false if there are only belongs_to associations" do
|
48
|
-
association.
|
48
|
+
allow(association).to receive(:macro).and_return(:belongs_to)
|
49
49
|
|
50
|
-
type.
|
50
|
+
expect(type).not_to be_multi
|
51
51
|
end
|
52
52
|
|
53
53
|
it "returns false if there are only has_one associations" do
|
54
|
-
association.
|
54
|
+
allow(association).to receive(:macro).and_return(:has_one)
|
55
55
|
|
56
|
-
type.
|
56
|
+
expect(type).not_to be_multi
|
57
57
|
end
|
58
58
|
|
59
59
|
it "returns true if deeper associations have many" do
|
60
60
|
column.__stack << :bar
|
61
61
|
deep_association = double(:klass => double, :macro => :has_many)
|
62
|
-
association.stub :macro => :belongs_to,
|
63
|
-
:klass => double(:reflect_on_association => deep_association)
|
64
62
|
|
65
|
-
|
63
|
+
allow(association).to receive(:macro).and_return(:belongs_to)
|
64
|
+
allow(association).to receive(:klass).and_return(
|
65
|
+
double(:reflect_on_association => deep_association)
|
66
|
+
)
|
67
|
+
|
68
|
+
expect(type).to be_multi
|
66
69
|
end
|
67
70
|
|
68
71
|
it "respects the provided setting" do
|
69
72
|
attribute.options[:multi] = true
|
70
73
|
|
71
|
-
type.
|
74
|
+
expect(type).to be_multi
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
@@ -76,79 +79,79 @@ describe ThinkingSphinx::ActiveRecord::Attribute::Type do
|
|
76
79
|
it "returns the type option provided" do
|
77
80
|
attribute.options[:type] = :datetime
|
78
81
|
|
79
|
-
type.type.
|
82
|
+
expect(type.type).to eq(:datetime)
|
80
83
|
end
|
81
84
|
|
82
85
|
it "detects integer types from the database" do
|
83
|
-
db_column.
|
86
|
+
allow(db_column).to receive_messages(:type => :integer, :sql_type => 'integer(11)')
|
84
87
|
|
85
|
-
type.type.
|
88
|
+
expect(type.type).to eq(:integer)
|
86
89
|
end
|
87
90
|
|
88
91
|
it "detects boolean types from the database" do
|
89
|
-
db_column.
|
92
|
+
allow(db_column).to receive_messages(:type => :boolean)
|
90
93
|
|
91
|
-
type.type.
|
94
|
+
expect(type.type).to eq(:boolean)
|
92
95
|
end
|
93
96
|
|
94
97
|
it "detects datetime types from the database as timestamps" do
|
95
|
-
db_column.
|
98
|
+
allow(db_column).to receive_messages(:type => :datetime)
|
96
99
|
|
97
|
-
type.type.
|
100
|
+
expect(type.type).to eq(:timestamp)
|
98
101
|
end
|
99
102
|
|
100
103
|
it "detects date types from the database as timestamps" do
|
101
|
-
db_column.
|
104
|
+
allow(db_column).to receive_messages(:type => :date)
|
102
105
|
|
103
|
-
type.type.
|
106
|
+
expect(type.type).to eq(:timestamp)
|
104
107
|
end
|
105
108
|
|
106
109
|
it "detects string types from the database" do
|
107
|
-
db_column.
|
110
|
+
allow(db_column).to receive_messages(:type => :string)
|
108
111
|
|
109
|
-
type.type.
|
112
|
+
expect(type.type).to eq(:string)
|
110
113
|
end
|
111
114
|
|
112
115
|
it "detects text types from the database as strings" do
|
113
|
-
db_column.
|
116
|
+
allow(db_column).to receive_messages(:type => :text)
|
114
117
|
|
115
|
-
type.type.
|
118
|
+
expect(type.type).to eq(:string)
|
116
119
|
end
|
117
120
|
|
118
121
|
it "detects float types from the database" do
|
119
|
-
db_column.
|
122
|
+
allow(db_column).to receive_messages(:type => :float)
|
120
123
|
|
121
|
-
type.type.
|
124
|
+
expect(type.type).to eq(:float)
|
122
125
|
end
|
123
126
|
|
124
127
|
it "detects decimal types from the database as floats" do
|
125
|
-
db_column.
|
128
|
+
allow(db_column).to receive_messages(:type => :decimal)
|
126
129
|
|
127
|
-
type.type.
|
130
|
+
expect(type.type).to eq(:float)
|
128
131
|
end
|
129
132
|
|
130
133
|
it "detects big ints as big ints" do
|
131
|
-
db_column.
|
134
|
+
allow(db_column).to receive_messages :type => :bigint
|
132
135
|
|
133
|
-
type.type.
|
136
|
+
expect(type.type).to eq(:bigint)
|
134
137
|
end
|
135
138
|
|
136
139
|
it "detects large integers as big ints" do
|
137
|
-
db_column.
|
140
|
+
allow(db_column).to receive_messages :type => :integer, :sql_type => 'bigint(20)'
|
138
141
|
|
139
|
-
type.type.
|
142
|
+
expect(type.type).to eq(:bigint)
|
140
143
|
end
|
141
144
|
|
142
145
|
it "detects JSON" do
|
143
|
-
db_column.
|
146
|
+
allow(db_column).to receive_messages :type => :json
|
144
147
|
|
145
|
-
type.type.
|
148
|
+
expect(type.type).to eq(:json)
|
146
149
|
end
|
147
150
|
|
148
151
|
it "respects provided type setting" do
|
149
152
|
attribute.options[:type] = :timestamp
|
150
153
|
|
151
|
-
type.type.
|
154
|
+
expect(type.type).to eq(:timestamp)
|
152
155
|
end
|
153
156
|
|
154
157
|
it 'raises an error if the database column does not exist' do
|
@@ -16,34 +16,34 @@ describe ThinkingSphinx::ActiveRecord::Base do
|
|
16
16
|
|
17
17
|
describe '.facets' do
|
18
18
|
it "returns a new search object" do
|
19
|
-
model.facets.
|
19
|
+
expect(model.facets).to be_a(ThinkingSphinx::FacetSearch)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "passes through arguments to the search object" do
|
23
|
-
model.facets('pancakes').query.
|
23
|
+
expect(model.facets('pancakes').query).to eq('pancakes')
|
24
24
|
end
|
25
25
|
|
26
26
|
it "scopes the search to a given model" do
|
27
|
-
model.facets('pancakes').options[:classes].
|
27
|
+
expect(model.facets('pancakes').options[:classes]).to eq([model])
|
28
28
|
end
|
29
29
|
|
30
30
|
it "merges the :classes option with the model" do
|
31
|
-
model.facets('pancakes', :classes => [sub_model]).
|
32
|
-
options[:classes].
|
31
|
+
expect(model.facets('pancakes', :classes => [sub_model]).
|
32
|
+
options[:classes]).to eq([sub_model, model])
|
33
33
|
end
|
34
34
|
|
35
35
|
it "applies the default scope if there is one" do
|
36
|
-
model.
|
36
|
+
allow(model).to receive_messages :default_sphinx_scope => :default,
|
37
37
|
:sphinx_scopes => {:default => Proc.new { {:order => :created_at} }}
|
38
38
|
|
39
|
-
model.facets.options[:order].
|
39
|
+
expect(model.facets.options[:order]).to eq(:created_at)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "does not apply a default scope if one is not set" do
|
43
|
-
model.
|
43
|
+
allow(model).to receive_messages :default_sphinx_scope => nil,
|
44
44
|
:default => {:order => :created_at}
|
45
45
|
|
46
|
-
model.facets.options[:order].
|
46
|
+
expect(model.facets.options[:order]).to be_nil
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -55,55 +55,55 @@ describe ThinkingSphinx::ActiveRecord::Base do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns a new search object" do
|
58
|
-
model.search.
|
58
|
+
expect(model.search).to be_a(ThinkingSphinx::Search)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "passes through arguments to the search object" do
|
62
|
-
model.search('pancakes').query.
|
62
|
+
expect(model.search('pancakes').query).to eq('pancakes')
|
63
63
|
end
|
64
64
|
|
65
65
|
it "scopes the search to a given model" do
|
66
|
-
model.search('pancakes').options[:classes].
|
66
|
+
expect(model.search('pancakes').options[:classes]).to eq([model])
|
67
67
|
end
|
68
68
|
|
69
69
|
it "passes through options to the search object" do
|
70
|
-
model.search('pancakes', populate: true).
|
71
|
-
options[:populate].
|
70
|
+
expect(model.search('pancakes', populate: true).
|
71
|
+
options[:populate]).to be_truthy
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should automatically populate when :populate is set to true" do
|
75
|
-
stack.
|
75
|
+
expect(stack).to receive(:call).and_return(true)
|
76
76
|
|
77
77
|
model.search('pancakes', populate: true)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "merges the :classes option with the model" do
|
81
|
-
model.search('pancakes', :classes => [sub_model]).
|
82
|
-
options[:classes].
|
81
|
+
expect(model.search('pancakes', :classes => [sub_model]).
|
82
|
+
options[:classes]).to eq([sub_model, model])
|
83
83
|
end
|
84
84
|
|
85
85
|
it "respects provided middleware" do
|
86
|
-
model.search(:middleware => ThinkingSphinx::Middlewares::RAW_ONLY).
|
87
|
-
options[:middleware].
|
86
|
+
expect(model.search(:middleware => ThinkingSphinx::Middlewares::RAW_ONLY).
|
87
|
+
options[:middleware]).to eq(ThinkingSphinx::Middlewares::RAW_ONLY)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "respects provided masks" do
|
91
|
-
model.search(:masks => [ThinkingSphinx::Masks::PaginationMask]).
|
92
|
-
masks.
|
91
|
+
expect(model.search(:masks => [ThinkingSphinx::Masks::PaginationMask]).
|
92
|
+
masks).to eq([ThinkingSphinx::Masks::PaginationMask])
|
93
93
|
end
|
94
94
|
|
95
95
|
it "applies the default scope if there is one" do
|
96
|
-
model.
|
96
|
+
allow(model).to receive_messages :default_sphinx_scope => :default,
|
97
97
|
:sphinx_scopes => {:default => Proc.new { {:order => :created_at} }}
|
98
98
|
|
99
|
-
model.search.options[:order].
|
99
|
+
expect(model.search.options[:order]).to eq(:created_at)
|
100
100
|
end
|
101
101
|
|
102
102
|
it "does not apply a default scope if one is not set" do
|
103
|
-
model.
|
103
|
+
allow(model).to receive_messages :default_sphinx_scope => nil,
|
104
104
|
:default => {:order => :created_at}
|
105
105
|
|
106
|
-
model.search.options[:order].
|
106
|
+
expect(model.search.options[:order]).to be_nil
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -112,18 +112,18 @@ describe ThinkingSphinx::ActiveRecord::Base do
|
|
112
112
|
:populated? => false) }
|
113
113
|
|
114
114
|
before :each do
|
115
|
-
ThinkingSphinx.
|
116
|
-
FileUtils.
|
115
|
+
allow(ThinkingSphinx).to receive_messages :search => search
|
116
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
117
117
|
end
|
118
118
|
|
119
119
|
it "returns the search object's total entries count" do
|
120
|
-
model.search_count.
|
120
|
+
expect(model.search_count).to eq(search.total_entries)
|
121
121
|
end
|
122
122
|
|
123
123
|
it "scopes the search to a given model" do
|
124
124
|
model.search_count
|
125
125
|
|
126
|
-
search.options[:classes].
|
126
|
+
expect(search.options[:classes]).to eq([model])
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|