friendlyfashion-thinking-sphinx 2.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +244 -0
- data/LICENCE +20 -0
- data/README.textile +235 -0
- data/features/abstract_inheritance.feature +10 -0
- data/features/alternate_primary_key.feature +27 -0
- data/features/attribute_transformation.feature +22 -0
- data/features/attribute_updates.feature +77 -0
- data/features/deleting_instances.feature +67 -0
- data/features/direct_attributes.feature +11 -0
- data/features/excerpts.feature +21 -0
- data/features/extensible_delta_indexing.feature +9 -0
- data/features/facets.feature +88 -0
- data/features/facets_across_model.feature +29 -0
- data/features/field_sorting.feature +18 -0
- data/features/handling_edits.feature +94 -0
- data/features/retry_stale_indexes.feature +24 -0
- data/features/searching_across_models.feature +20 -0
- data/features/searching_by_index.feature +40 -0
- data/features/searching_by_model.feature +175 -0
- data/features/searching_with_find_arguments.feature +56 -0
- data/features/sphinx_detection.feature +25 -0
- data/features/sphinx_scopes.feature +68 -0
- data/features/step_definitions/alpha_steps.rb +16 -0
- data/features/step_definitions/beta_steps.rb +7 -0
- data/features/step_definitions/common_steps.rb +201 -0
- data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
- data/features/step_definitions/facet_steps.rb +96 -0
- data/features/step_definitions/find_arguments_steps.rb +36 -0
- data/features/step_definitions/gamma_steps.rb +15 -0
- data/features/step_definitions/scope_steps.rb +19 -0
- data/features/step_definitions/search_steps.rb +94 -0
- data/features/step_definitions/sphinx_steps.rb +35 -0
- data/features/sti_searching.feature +19 -0
- data/features/support/env.rb +27 -0
- data/features/support/lib/generic_delta_handler.rb +8 -0
- data/features/thinking_sphinx/database.example.yml +3 -0
- data/features/thinking_sphinx/db/.gitignore +1 -0
- data/features/thinking_sphinx/db/fixtures/alphas.rb +8 -0
- data/features/thinking_sphinx/db/fixtures/authors.rb +1 -0
- data/features/thinking_sphinx/db/fixtures/betas.rb +11 -0
- data/features/thinking_sphinx/db/fixtures/boxes.rb +9 -0
- data/features/thinking_sphinx/db/fixtures/categories.rb +1 -0
- data/features/thinking_sphinx/db/fixtures/cats.rb +3 -0
- data/features/thinking_sphinx/db/fixtures/comments.rb +24 -0
- data/features/thinking_sphinx/db/fixtures/developers.rb +31 -0
- data/features/thinking_sphinx/db/fixtures/dogs.rb +3 -0
- data/features/thinking_sphinx/db/fixtures/extensible_betas.rb +10 -0
- data/features/thinking_sphinx/db/fixtures/foxes.rb +3 -0
- data/features/thinking_sphinx/db/fixtures/gammas.rb +10 -0
- data/features/thinking_sphinx/db/fixtures/music.rb +4 -0
- data/features/thinking_sphinx/db/fixtures/people.rb +1001 -0
- data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
- data/features/thinking_sphinx/db/fixtures/posts.rb +10 -0
- data/features/thinking_sphinx/db/fixtures/robots.rb +8 -0
- data/features/thinking_sphinx/db/fixtures/tags.rb +27 -0
- data/features/thinking_sphinx/db/migrations/create_alphas.rb +8 -0
- data/features/thinking_sphinx/db/migrations/create_animals.rb +5 -0
- data/features/thinking_sphinx/db/migrations/create_authors.rb +3 -0
- data/features/thinking_sphinx/db/migrations/create_authors_posts.rb +6 -0
- data/features/thinking_sphinx/db/migrations/create_betas.rb +5 -0
- data/features/thinking_sphinx/db/migrations/create_boxes.rb +5 -0
- data/features/thinking_sphinx/db/migrations/create_categories.rb +3 -0
- data/features/thinking_sphinx/db/migrations/create_comments.rb +10 -0
- data/features/thinking_sphinx/db/migrations/create_developers.rb +7 -0
- data/features/thinking_sphinx/db/migrations/create_extensible_betas.rb +5 -0
- data/features/thinking_sphinx/db/migrations/create_gammas.rb +3 -0
- data/features/thinking_sphinx/db/migrations/create_genres.rb +3 -0
- data/features/thinking_sphinx/db/migrations/create_music.rb +6 -0
- data/features/thinking_sphinx/db/migrations/create_people.rb +13 -0
- data/features/thinking_sphinx/db/migrations/create_posts.rb +6 -0
- data/features/thinking_sphinx/db/migrations/create_robots.rb +4 -0
- data/features/thinking_sphinx/db/migrations/create_taggings.rb +5 -0
- data/features/thinking_sphinx/db/migrations/create_tags.rb +4 -0
- data/features/thinking_sphinx/models/alpha.rb +23 -0
- data/features/thinking_sphinx/models/andrew.rb +17 -0
- data/features/thinking_sphinx/models/animal.rb +5 -0
- data/features/thinking_sphinx/models/author.rb +3 -0
- data/features/thinking_sphinx/models/beta.rb +13 -0
- data/features/thinking_sphinx/models/box.rb +8 -0
- data/features/thinking_sphinx/models/cat.rb +3 -0
- data/features/thinking_sphinx/models/category.rb +4 -0
- data/features/thinking_sphinx/models/comment.rb +10 -0
- data/features/thinking_sphinx/models/developer.rb +21 -0
- data/features/thinking_sphinx/models/dog.rb +3 -0
- data/features/thinking_sphinx/models/extensible_beta.rb +9 -0
- data/features/thinking_sphinx/models/fox.rb +5 -0
- data/features/thinking_sphinx/models/gamma.rb +5 -0
- data/features/thinking_sphinx/models/genre.rb +3 -0
- data/features/thinking_sphinx/models/medium.rb +5 -0
- data/features/thinking_sphinx/models/music.rb +10 -0
- data/features/thinking_sphinx/models/person.rb +24 -0
- data/features/thinking_sphinx/models/post.rb +22 -0
- data/features/thinking_sphinx/models/robot.rb +12 -0
- data/features/thinking_sphinx/models/tag.rb +3 -0
- data/features/thinking_sphinx/models/tagging.rb +4 -0
- data/lib/cucumber/thinking_sphinx/external_world.rb +12 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +137 -0
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +28 -0
- data/lib/thinking-sphinx.rb +1 -0
- data/lib/thinking_sphinx/action_controller.rb +31 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +53 -0
- data/lib/thinking_sphinx/active_record/collection_proxy.rb +47 -0
- data/lib/thinking_sphinx/active_record/collection_proxy_with_scopes.rb +27 -0
- data/lib/thinking_sphinx/active_record/delta.rb +67 -0
- data/lib/thinking_sphinx/active_record/has_many_association.rb +44 -0
- data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +21 -0
- data/lib/thinking_sphinx/active_record/log_subscriber.rb +61 -0
- data/lib/thinking_sphinx/active_record/scopes.rb +110 -0
- data/lib/thinking_sphinx/active_record.rb +386 -0
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +87 -0
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +62 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +188 -0
- data/lib/thinking_sphinx/association.rb +230 -0
- data/lib/thinking_sphinx/attribute.rb +405 -0
- data/lib/thinking_sphinx/auto_version.rb +40 -0
- data/lib/thinking_sphinx/bundled_search.rb +44 -0
- data/lib/thinking_sphinx/class_facet.rb +20 -0
- data/lib/thinking_sphinx/configuration.rb +375 -0
- data/lib/thinking_sphinx/context.rb +76 -0
- data/lib/thinking_sphinx/core/string.rb +15 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +62 -0
- data/lib/thinking_sphinx/deltas.rb +28 -0
- data/lib/thinking_sphinx/deploy/capistrano.rb +99 -0
- data/lib/thinking_sphinx/excerpter.rb +23 -0
- data/lib/thinking_sphinx/facet.rb +135 -0
- data/lib/thinking_sphinx/facet_search.rb +170 -0
- data/lib/thinking_sphinx/field.rb +98 -0
- data/lib/thinking_sphinx/index/builder.rb +315 -0
- data/lib/thinking_sphinx/index/faux_column.rb +118 -0
- data/lib/thinking_sphinx/index.rb +159 -0
- data/lib/thinking_sphinx/join.rb +37 -0
- data/lib/thinking_sphinx/property.rb +187 -0
- data/lib/thinking_sphinx/railtie.rb +43 -0
- data/lib/thinking_sphinx/search.rb +1061 -0
- data/lib/thinking_sphinx/search_methods.rb +439 -0
- data/lib/thinking_sphinx/sinatra.rb +7 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +51 -0
- data/lib/thinking_sphinx/source/sql.rb +174 -0
- data/lib/thinking_sphinx/source.rb +194 -0
- data/lib/thinking_sphinx/tasks.rb +142 -0
- data/lib/thinking_sphinx/test.rb +55 -0
- data/lib/thinking_sphinx/version.rb +3 -0
- data/lib/thinking_sphinx.rb +297 -0
- data/spec/fixtures/data.sql +32 -0
- data/spec/fixtures/database.yml.default +3 -0
- data/spec/fixtures/models.rb +164 -0
- data/spec/fixtures/structure.sql +146 -0
- data/spec/spec_helper.rb +61 -0
- data/spec/sphinx_helper.rb +60 -0
- data/spec/support/rails.rb +25 -0
- data/spec/thinking_sphinx/active_record/delta_spec.rb +122 -0
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +173 -0
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +176 -0
- data/spec/thinking_sphinx/active_record_spec.rb +573 -0
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +145 -0
- data/spec/thinking_sphinx/association_spec.rb +250 -0
- data/spec/thinking_sphinx/attribute_spec.rb +552 -0
- data/spec/thinking_sphinx/auto_version_spec.rb +103 -0
- data/spec/thinking_sphinx/configuration_spec.rb +326 -0
- data/spec/thinking_sphinx/context_spec.rb +126 -0
- data/spec/thinking_sphinx/core/array_spec.rb +9 -0
- data/spec/thinking_sphinx/core/string_spec.rb +9 -0
- data/spec/thinking_sphinx/excerpter_spec.rb +49 -0
- data/spec/thinking_sphinx/facet_search_spec.rb +176 -0
- data/spec/thinking_sphinx/facet_spec.rb +359 -0
- data/spec/thinking_sphinx/field_spec.rb +127 -0
- data/spec/thinking_sphinx/index/builder_spec.rb +532 -0
- data/spec/thinking_sphinx/index/faux_column_spec.rb +36 -0
- data/spec/thinking_sphinx/index_spec.rb +189 -0
- data/spec/thinking_sphinx/search_methods_spec.rb +156 -0
- data/spec/thinking_sphinx/search_spec.rb +1455 -0
- data/spec/thinking_sphinx/source_spec.rb +267 -0
- data/spec/thinking_sphinx/test_spec.rb +20 -0
- data/spec/thinking_sphinx_spec.rb +204 -0
- metadata +524 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::Index do
|
4
|
+
describe "prefix_fields method" do
|
5
|
+
before :each do
|
6
|
+
@index = ThinkingSphinx::Index.new(Person)
|
7
|
+
|
8
|
+
@field_a = stub('field', :prefixes => true)
|
9
|
+
@field_b = stub('field', :prefixes => false)
|
10
|
+
@field_c = stub('field', :prefixes => true)
|
11
|
+
|
12
|
+
@index.stub!(:fields => [@field_a, @field_b, @field_c])
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return fields that are flagged as prefixed" do
|
16
|
+
@index.prefix_fields.should include(@field_a)
|
17
|
+
@index.prefix_fields.should include(@field_c)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not return fields that aren't flagged as prefixed" do
|
21
|
+
@index.prefix_fields.should_not include(@field_b)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "infix_fields method" do
|
26
|
+
before :each do
|
27
|
+
@index = ThinkingSphinx::Index.new(Person)
|
28
|
+
|
29
|
+
@field_a = stub('field', :infixes => true)
|
30
|
+
@field_b = stub('field', :infixes => false)
|
31
|
+
@field_c = stub('field', :infixes => true)
|
32
|
+
|
33
|
+
@index.stub!(:fields => [@field_a, @field_b, @field_c])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return fields that are flagged as infixed" do
|
37
|
+
@index.infix_fields.should include(@field_a)
|
38
|
+
@index.infix_fields.should include(@field_c)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not return fields that aren't flagged as infixed" do
|
42
|
+
@index.infix_fields.should_not include(@field_b)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '.name_for' do
|
47
|
+
it "should return the model's name downcased" do
|
48
|
+
ThinkingSphinx::Index.name_for(Alpha).should == 'alpha'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should separate words by underscores" do
|
52
|
+
ThinkingSphinx::Index.name_for(ActiveRecord).should == 'active_record'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should separate namespaces by underscores" do
|
56
|
+
ThinkingSphinx::Index.name_for(ActiveRecord::Base).
|
57
|
+
should == 'active_record_base'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#name' do
|
62
|
+
it "should return the downcased name of the index's model" do
|
63
|
+
ThinkingSphinx::Index.new(Alpha).name.should == 'alpha'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return a custom name if one is set" do
|
67
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
68
|
+
index.name = 'custom'
|
69
|
+
index.name.should == 'custom'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#core_name' do
|
74
|
+
it "should take the index's name and append _core" do
|
75
|
+
ThinkingSphinx::Index.new(Alpha).core_name.should == 'alpha_core'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#delta_name' do
|
80
|
+
it "should take the index's name and append _delta" do
|
81
|
+
ThinkingSphinx::Index.new(Alpha).delta_name.should == 'alpha_delta'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#all_names' do
|
86
|
+
it "should return the core index name by default" do
|
87
|
+
ThinkingSphinx::Index.new(Alpha).all_names.should == ['alpha_core']
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return both core and delta names if deltas are enabled" do
|
91
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
92
|
+
index.delta_object = stub('delta')
|
93
|
+
|
94
|
+
index.all_names.should == ['alpha_core', 'alpha_delta']
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should respect custom names" do
|
98
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
99
|
+
index.name = 'custom'
|
100
|
+
|
101
|
+
index.all_names.should == ['custom_core']
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should respect custom names when deltas are enabled" do
|
105
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
106
|
+
index.name = 'custom'
|
107
|
+
index.delta_object = stub('delta')
|
108
|
+
|
109
|
+
index.all_names.should == ['custom_core', 'custom_delta']
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#to_riddle' do
|
114
|
+
it "should return two Riddle indexes if deltas are disabled" do
|
115
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
116
|
+
|
117
|
+
index.to_riddle(0).length.should == 2
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return three Riddle indexes if deltas are enabled" do
|
121
|
+
index = ThinkingSphinx::Index.new(Beta)
|
122
|
+
index.delta_object = stub('delta')
|
123
|
+
|
124
|
+
index.to_riddle(0).length.should == 3
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should include a distributed index" do
|
128
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
129
|
+
|
130
|
+
index.to_riddle(0).last.
|
131
|
+
should be_a(Riddle::Configuration::DistributedIndex)
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'core index' do
|
135
|
+
it "should use the core name" do
|
136
|
+
@index = ThinkingSphinx::Index.new(Alpha).to_riddle(0).first
|
137
|
+
@index.name.should == 'alpha_core'
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should not try to set disable_range on the index" do
|
141
|
+
ThinkingSphinx::Configuration.instance.
|
142
|
+
index_options[:disable_range] = true
|
143
|
+
|
144
|
+
lambda {
|
145
|
+
@index = ThinkingSphinx::Index.new(Alpha).to_riddle(0).first
|
146
|
+
}.should_not raise_error(NoMethodError)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'delta index' do
|
151
|
+
before :each do
|
152
|
+
index = ThinkingSphinx::Index.new(Beta)
|
153
|
+
index.delta_object = stub('delta')
|
154
|
+
@index = index.to_riddle(0)[1]
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should use the delta name" do
|
158
|
+
@index.name.should == 'beta_delta'
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'distributed index' do
|
163
|
+
it "should use the index's name" do
|
164
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
165
|
+
|
166
|
+
index.to_riddle(0).last.name.should == 'alpha'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should add the core index" do
|
170
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
171
|
+
|
172
|
+
index.to_riddle(0).last.local_indices.should include('alpha_core')
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should add the delta index if there is one" do
|
176
|
+
index = ThinkingSphinx::Index.new(Beta)
|
177
|
+
index.delta_object = stub('delta')
|
178
|
+
|
179
|
+
index.to_riddle(0).last.local_indices.should include('beta_delta')
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should add additional local indexes if there are any" do
|
183
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
184
|
+
index.additional_indices << "other_index_core"
|
185
|
+
index.to_riddle(0).last.local_indices.should include('other_index_core')
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::SearchMethods do
|
4
|
+
it "should be included into models with indexes" do
|
5
|
+
Alpha.included_modules.should include(ThinkingSphinx::SearchMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should not be included into models that don't have indexes" do
|
9
|
+
Gamma.included_modules.should_not include(ThinkingSphinx::SearchMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.search_context' do
|
13
|
+
it "should return nil if not within a model" do
|
14
|
+
ThinkingSphinx.search_context.should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return the model if within one" do
|
18
|
+
Alpha.search_context.should == Alpha
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.search' do
|
23
|
+
it "should return an instance of ThinkingSphinx::Search" do
|
24
|
+
Alpha.search.class.should == ThinkingSphinx::Search
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set the classes option if not already set" do
|
28
|
+
search = Alpha.search
|
29
|
+
search.options[:classes].should == [Alpha]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "shouldn't set the classes option if already defined" do
|
33
|
+
search = Alpha.search :classes => [Beta]
|
34
|
+
search.options[:classes].should == [Beta]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should default to nil for the classes options" do
|
38
|
+
ThinkingSphinx.search.options[:classes].should be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.search_for_ids' do
|
43
|
+
it "should return an instance of ThinkingSphinx::Search" do
|
44
|
+
Alpha.search.class.should == ThinkingSphinx::Search
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set the classes option if not already set" do
|
48
|
+
search = Alpha.search_for_ids
|
49
|
+
search.options[:classes].should == [Alpha]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "shouldn't set the classes option if already defined" do
|
53
|
+
search = Alpha.search_for_ids :classes => [Beta]
|
54
|
+
search.options[:classes].should == [Beta]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set ids_only to true" do
|
58
|
+
search = Alpha.search_for_ids
|
59
|
+
search.options[:ids_only].should be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.search_for_id' do
|
64
|
+
before :each do
|
65
|
+
@config = ThinkingSphinx::Configuration.instance
|
66
|
+
@client = Riddle::Client.new
|
67
|
+
|
68
|
+
@config.stub!(:client => @client)
|
69
|
+
@client.stub!(:query => {:matches => [], :total_found => 0})
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set the id range to the given id value" do
|
73
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core')
|
74
|
+
|
75
|
+
@client.id_range.should == (101..101)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not make any calls to the database" do
|
79
|
+
Alpha.should_not_receive(:find)
|
80
|
+
|
81
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core', :classes => [Alpha])
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return true if there is a record" do
|
85
|
+
@client.stub!(:query => {:matches => [
|
86
|
+
{:attributes => {'sphinx_internal_id' => 100}}
|
87
|
+
], :total_found => 1})
|
88
|
+
|
89
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core').should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return false if there isn't a record" do
|
93
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core').should be_false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '.count' do
|
98
|
+
before :each do
|
99
|
+
@config = ThinkingSphinx::Configuration.instance
|
100
|
+
@client = Riddle::Client.new
|
101
|
+
|
102
|
+
@config.stub!(:client => @client)
|
103
|
+
@client.stub!(:query => {:matches => [], :total_found => 42})
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should fall through to ActiveRecord if called on a class" do
|
107
|
+
@client.should_not_receive(:query)
|
108
|
+
|
109
|
+
Alpha.count
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return the total number of results if called globally" do
|
113
|
+
ThinkingSphinx.count.should == 42
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.search_count' do
|
118
|
+
before :each do
|
119
|
+
@config = ThinkingSphinx::Configuration.instance
|
120
|
+
@client = Riddle::Client.new
|
121
|
+
|
122
|
+
@config.stub!(:client => @client)
|
123
|
+
@client.stub!(:query => {:matches => [], :total_found => 42})
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return the total number of results" do
|
127
|
+
Alpha.search_count.should == 42
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should not make any calls to the database" do
|
131
|
+
Alpha.should_not_receive(:find)
|
132
|
+
|
133
|
+
Alpha.search_count
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '.facets' do
|
138
|
+
before :each do
|
139
|
+
ThinkingSphinx::Search.stub!(:bundle_searches => [])
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return a FacetSearch instance" do
|
143
|
+
Alpha.facets.should be_a(ThinkingSphinx::FacetSearch)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should set the classes option if not already set" do
|
147
|
+
facets = Alpha.facets
|
148
|
+
facets.options[:classes].should == [Alpha]
|
149
|
+
end
|
150
|
+
|
151
|
+
it "shouldn't set the classes option if already defined" do
|
152
|
+
facets = Alpha.facets :classes => [Beta]
|
153
|
+
facets.options[:classes].should == [Beta]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|