skalee-thinking-sphinx 1.3.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENCE +20 -0
- data/README.textile +201 -0
- data/Rakefile +3 -0
- data/VERSION +1 -0
- data/contribute.rb +385 -0
- data/cucumber.yml +1 -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 +51 -0
- data/features/deleting_instances.feature +67 -0
- data/features/direct_attributes.feature +11 -0
- data/features/excerpts.feature +13 -0
- data/features/extensible_delta_indexing.feature +9 -0
- data/features/facets.feature +82 -0
- data/features/facets_across_model.feature +29 -0
- data/features/handling_edits.feature +92 -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 +42 -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 +188 -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 +15 -0
- data/features/step_definitions/search_steps.rb +89 -0
- data/features/step_definitions/sphinx_steps.rb +35 -0
- data/features/sti_searching.feature +19 -0
- data/features/support/database.example.yml +3 -0
- data/features/support/db/.gitignore +1 -0
- data/features/support/db/fixtures/alphas.rb +10 -0
- data/features/support/db/fixtures/authors.rb +1 -0
- data/features/support/db/fixtures/betas.rb +10 -0
- data/features/support/db/fixtures/boxes.rb +9 -0
- data/features/support/db/fixtures/categories.rb +1 -0
- data/features/support/db/fixtures/cats.rb +3 -0
- data/features/support/db/fixtures/comments.rb +24 -0
- data/features/support/db/fixtures/developers.rb +29 -0
- data/features/support/db/fixtures/dogs.rb +3 -0
- data/features/support/db/fixtures/extensible_betas.rb +10 -0
- data/features/support/db/fixtures/foxes.rb +3 -0
- data/features/support/db/fixtures/gammas.rb +10 -0
- data/features/support/db/fixtures/music.rb +4 -0
- data/features/support/db/fixtures/people.rb +1001 -0
- data/features/support/db/fixtures/posts.rb +6 -0
- data/features/support/db/fixtures/robots.rb +14 -0
- data/features/support/db/fixtures/tags.rb +27 -0
- data/features/support/db/migrations/create_alphas.rb +8 -0
- data/features/support/db/migrations/create_animals.rb +5 -0
- data/features/support/db/migrations/create_authors.rb +3 -0
- data/features/support/db/migrations/create_authors_posts.rb +6 -0
- data/features/support/db/migrations/create_betas.rb +5 -0
- data/features/support/db/migrations/create_boxes.rb +5 -0
- data/features/support/db/migrations/create_categories.rb +3 -0
- data/features/support/db/migrations/create_comments.rb +10 -0
- data/features/support/db/migrations/create_developers.rb +9 -0
- data/features/support/db/migrations/create_extensible_betas.rb +5 -0
- data/features/support/db/migrations/create_gammas.rb +3 -0
- data/features/support/db/migrations/create_genres.rb +3 -0
- data/features/support/db/migrations/create_music.rb +6 -0
- data/features/support/db/migrations/create_people.rb +13 -0
- data/features/support/db/migrations/create_posts.rb +5 -0
- data/features/support/db/migrations/create_robots.rb +4 -0
- data/features/support/db/migrations/create_taggings.rb +5 -0
- data/features/support/db/migrations/create_tags.rb +4 -0
- data/features/support/env.rb +21 -0
- data/features/support/lib/generic_delta_handler.rb +8 -0
- data/features/support/models/alpha.rb +22 -0
- data/features/support/models/animal.rb +5 -0
- data/features/support/models/author.rb +3 -0
- data/features/support/models/beta.rb +8 -0
- data/features/support/models/box.rb +8 -0
- data/features/support/models/cat.rb +3 -0
- data/features/support/models/category.rb +4 -0
- data/features/support/models/comment.rb +10 -0
- data/features/support/models/developer.rb +16 -0
- data/features/support/models/dog.rb +3 -0
- data/features/support/models/extensible_beta.rb +9 -0
- data/features/support/models/fox.rb +5 -0
- data/features/support/models/gamma.rb +5 -0
- data/features/support/models/genre.rb +3 -0
- data/features/support/models/medium.rb +5 -0
- data/features/support/models/music.rb +8 -0
- data/features/support/models/person.rb +23 -0
- data/features/support/models/post.rb +21 -0
- data/features/support/models/robot.rb +12 -0
- data/features/support/models/tag.rb +3 -0
- data/features/support/models/tagging.rb +4 -0
- data/ginger_scenarios.rb +28 -0
- data/init.rb +5 -0
- data/install.rb +5 -0
- data/lib/cucumber/thinking_sphinx/external_world.rb +8 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +126 -0
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +19 -0
- data/lib/thinking_sphinx/active_record/delta.rb +47 -0
- data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
- data/lib/thinking_sphinx/active_record/scopes.rb +75 -0
- data/lib/thinking_sphinx/active_record.rb +348 -0
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +143 -0
- data/lib/thinking_sphinx/association.rb +164 -0
- data/lib/thinking_sphinx/attribute.rb +362 -0
- data/lib/thinking_sphinx/auto_version.rb +22 -0
- data/lib/thinking_sphinx/class_facet.rb +15 -0
- data/lib/thinking_sphinx/configuration.rb +300 -0
- data/lib/thinking_sphinx/context.rb +68 -0
- data/lib/thinking_sphinx/core/array.rb +7 -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 +100 -0
- data/lib/thinking_sphinx/excerpter.rb +22 -0
- data/lib/thinking_sphinx/facet.rb +125 -0
- data/lib/thinking_sphinx/facet_search.rb +136 -0
- data/lib/thinking_sphinx/field.rb +82 -0
- data/lib/thinking_sphinx/index/builder.rb +296 -0
- data/lib/thinking_sphinx/index/faux_column.rb +110 -0
- data/lib/thinking_sphinx/index.rb +157 -0
- data/lib/thinking_sphinx/property.rb +162 -0
- data/lib/thinking_sphinx/rails_additions.rb +150 -0
- data/lib/thinking_sphinx/search.rb +769 -0
- data/lib/thinking_sphinx/search_methods.rb +439 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
- data/lib/thinking_sphinx/source/sql.rb +130 -0
- data/lib/thinking_sphinx/source.rb +153 -0
- data/lib/thinking_sphinx/tasks.rb +131 -0
- data/lib/thinking_sphinx/test.rb +52 -0
- data/lib/thinking_sphinx.rb +225 -0
- data/rails/init.rb +16 -0
- data/recipes/thinking_sphinx.rb +3 -0
- data/spec/fixtures/data.sql +32 -0
- data/spec/fixtures/database.yml.default +3 -0
- data/spec/fixtures/models.rb +145 -0
- data/spec/fixtures/structure.sql +125 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/sphinx_helper.rb +81 -0
- data/spec/thinking_sphinx/active_record/delta_spec.rb +128 -0
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +55 -0
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +177 -0
- data/spec/thinking_sphinx/active_record_spec.rb +622 -0
- data/spec/thinking_sphinx/association_spec.rb +239 -0
- data/spec/thinking_sphinx/attribute_spec.rb +570 -0
- data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
- data/spec/thinking_sphinx/configuration_spec.rb +234 -0
- data/spec/thinking_sphinx/context_spec.rb +119 -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 +57 -0
- data/spec/thinking_sphinx/facet_search_spec.rb +176 -0
- data/spec/thinking_sphinx/facet_spec.rb +333 -0
- data/spec/thinking_sphinx/field_spec.rb +154 -0
- data/spec/thinking_sphinx/index/builder_spec.rb +479 -0
- data/spec/thinking_sphinx/index/faux_column_spec.rb +30 -0
- data/spec/thinking_sphinx/index_spec.rb +183 -0
- data/spec/thinking_sphinx/rails_additions_spec.rb +203 -0
- data/spec/thinking_sphinx/search_methods_spec.rb +152 -0
- data/spec/thinking_sphinx/search_spec.rb +1181 -0
- data/spec/thinking_sphinx/source_spec.rb +235 -0
- data/spec/thinking_sphinx_spec.rb +204 -0
- data/tasks/distribution.rb +41 -0
- data/tasks/rails.rake +1 -0
- data/tasks/testing.rb +72 -0
- data/vendor/after_commit/.gitignore +1 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +122 -0
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +168 -0
- data/vendor/after_commit/lib/after_commit/test_bypass.rb +30 -0
- data/vendor/after_commit/lib/after_commit.rb +70 -0
- data/vendor/riddle/lib/riddle/0.9.8.rb +1 -0
- data/vendor/riddle/lib/riddle/0.9.9/client/filter.rb +22 -0
- data/vendor/riddle/lib/riddle/0.9.9/client.rb +49 -0
- data/vendor/riddle/lib/riddle/0.9.9/configuration/searchd.rb +28 -0
- data/vendor/riddle/lib/riddle/0.9.9.rb +7 -0
- data/vendor/riddle/lib/riddle/auto_version.rb +11 -0
- data/vendor/riddle/lib/riddle/client/filter.rb +62 -0
- data/vendor/riddle/lib/riddle/client/message.rb +70 -0
- data/vendor/riddle/lib/riddle/client/response.rb +94 -0
- data/vendor/riddle/lib/riddle/client.rb +745 -0
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +49 -0
- data/vendor/riddle/lib/riddle/configuration/index.rb +149 -0
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +20 -0
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +28 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
- data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +53 -0
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +29 -0
- data/vendor/riddle/lib/riddle/configuration.rb +33 -0
- data/vendor/riddle/lib/riddle/controller.rb +78 -0
- data/vendor/riddle/lib/riddle.rb +51 -0
- metadata +312 -0
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::Association do
|
4
|
+
describe '.children' do
|
5
|
+
before :each do
|
6
|
+
@normal_reflection = stub('reflection', :options => {
|
7
|
+
:polymorphic => false
|
8
|
+
})
|
9
|
+
@normal_association = ThinkingSphinx::Association.new(nil, nil)
|
10
|
+
@poly_reflection = stub('reflection',
|
11
|
+
:options => {:polymorphic => true},
|
12
|
+
:macro => :has_many,
|
13
|
+
:name => 'polly',
|
14
|
+
:active_record => 'AR'
|
15
|
+
)
|
16
|
+
@non_poly_reflection = stub('reflection')
|
17
|
+
|
18
|
+
Person.stub!(:reflect_on_association => @normal_reflection)
|
19
|
+
ThinkingSphinx::Association.stub!(
|
20
|
+
:new => @normal_association,
|
21
|
+
:polymorphic_classes => [Person, Person],
|
22
|
+
:casted_options => {:casted => :options}
|
23
|
+
)
|
24
|
+
::ActiveRecord::Reflection::AssociationReflection.stub!(
|
25
|
+
:new => @non_poly_reflection
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return an empty array if no association exists" do
|
30
|
+
Person.stub!(:reflect_on_association => nil)
|
31
|
+
|
32
|
+
ThinkingSphinx::Association.children(Person, :assoc).should == []
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return a single association instance in an array if assocation isn't polymorphic" do
|
36
|
+
ThinkingSphinx::Association.children(Person, :assoc).should == [@normal_association]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return multiple association instances for polymorphic associations" do
|
40
|
+
Person.stub!(:reflect_on_association => @poly_reflection)
|
41
|
+
|
42
|
+
ThinkingSphinx::Association.children(Person, :assoc).should ==
|
43
|
+
[@normal_association, @normal_association]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should generate non-polymorphic 'casted' associations for each polymorphic possibility" do
|
47
|
+
Person.stub!(:reflect_on_association => @poly_reflection)
|
48
|
+
ThinkingSphinx::Association.should_receive(:casted_options).with(
|
49
|
+
Person, @poly_reflection
|
50
|
+
).twice
|
51
|
+
::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
|
52
|
+
with(:has_many, :polly_Person, {:casted => :options}, "AR").twice
|
53
|
+
ThinkingSphinx::Association.should_receive(:new).with(
|
54
|
+
nil, @non_poly_reflection
|
55
|
+
).twice
|
56
|
+
|
57
|
+
ThinkingSphinx::Association.children(Person, :assoc)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#children' do
|
62
|
+
before :each do
|
63
|
+
@reflection = stub('reflection', :klass => :klass)
|
64
|
+
@association = ThinkingSphinx::Association.new(nil, @reflection)
|
65
|
+
ThinkingSphinx::Association.stub!(:children => :result)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return the children associations for the given association" do
|
69
|
+
@association.children(:assoc).should == :result
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should request children for the reflection klass" do
|
73
|
+
ThinkingSphinx::Association.should_receive(:children).
|
74
|
+
with(:klass, :assoc, @association)
|
75
|
+
|
76
|
+
@association.children(:assoc)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#join_to' do
|
81
|
+
before :each do
|
82
|
+
@parent_join = stub('join assoc').as_null_object
|
83
|
+
@join = stub('join assoc').as_null_object
|
84
|
+
@parent = ThinkingSphinx::Association.new(nil, nil)
|
85
|
+
@parent.stub!(:join_to => true, :join => nil)
|
86
|
+
@base_join = stub('base join', :joins => [:a, :b, :c])
|
87
|
+
::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub!(:new => @join)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should call the parent's join_to if parent has no join" do
|
91
|
+
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
92
|
+
@parent.should_receive(:join_to).with(@base_join)
|
93
|
+
|
94
|
+
@assoc.join_to(@base_join)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should not call the parent's join_to if it already has a join" do
|
98
|
+
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
99
|
+
@parent.stub!(:join => @parent_join)
|
100
|
+
@parent.should_not_receive(:join_to)
|
101
|
+
|
102
|
+
@assoc.join_to(@base_join)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should define the join association with a JoinAssociation instance" do
|
106
|
+
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
107
|
+
|
108
|
+
@assoc.join_to(@base_join).should == @join
|
109
|
+
@assoc.join.should == @join
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#to_sql' do
|
114
|
+
before :each do
|
115
|
+
@reflection = stub('reflection', :klass => Person)
|
116
|
+
@association = ThinkingSphinx::Association.new(nil, @reflection)
|
117
|
+
@parent = stub('parent', :aliased_table_name => "ALIAS TABLE NAME")
|
118
|
+
@join = stub('join assoc',
|
119
|
+
:association_join => "full association join SQL",
|
120
|
+
:parent => @parent
|
121
|
+
)
|
122
|
+
@association.join = @join
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should return the join's association join value" do
|
126
|
+
@association.to_sql.should == "full association join SQL"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should replace ::ts_join_alias:: with the aliased table name" do
|
130
|
+
@join.stub!(:association_join => "text with ::ts_join_alias:: gone")
|
131
|
+
|
132
|
+
@association.to_sql.should == "text with `ALIAS TABLE NAME` gone"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#is_many?' do
|
137
|
+
before :each do
|
138
|
+
@parent = stub('assoc', :is_many? => :parent_is_many)
|
139
|
+
@reflection = stub('reflection', :macro => :has_many)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return true if association is either a has_many or a habtm" do
|
143
|
+
association = ThinkingSphinx::Association.new(@parent, @reflection)
|
144
|
+
association.is_many?.should be_true
|
145
|
+
|
146
|
+
@reflection.stub!(:macro => :has_and_belongs_to_many)
|
147
|
+
association.is_many?.should be_true
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should return the parent value if not a has many or habtm and there is a parent" do
|
151
|
+
association = ThinkingSphinx::Association.new(@parent, @reflection)
|
152
|
+
@reflection.stub!(:macro => :belongs_to)
|
153
|
+
association.is_many?.should == :parent_is_many
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should return false if no parent and not a has many or habtm" do
|
157
|
+
association = ThinkingSphinx::Association.new(nil, @reflection)
|
158
|
+
@reflection.stub!(:macro => :belongs_to)
|
159
|
+
association.is_many?.should be_false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#ancestors' do
|
164
|
+
it "should return an array of associations - including all parents" do
|
165
|
+
parent = stub('assoc', :ancestors => [:all, :ancestors])
|
166
|
+
association = ThinkingSphinx::Association.new(parent, @reflection)
|
167
|
+
association.ancestors.should == [:all, :ancestors, association]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe '.polymorphic_classes' do
|
172
|
+
it "should return all the polymorphic result types as classes" do
|
173
|
+
Person.connection.stub!(:select_all => [
|
174
|
+
{"person_type" => "Person"},
|
175
|
+
{"person_type" => "Friendship"}
|
176
|
+
])
|
177
|
+
ref = stub('ref',
|
178
|
+
:active_record => Person,
|
179
|
+
:options => {:foreign_type => "person_type"}
|
180
|
+
)
|
181
|
+
|
182
|
+
ThinkingSphinx::Association.send(:polymorphic_classes, ref).should == [Person, Friendship]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '.casted_options' do
|
187
|
+
before :each do
|
188
|
+
@options = {
|
189
|
+
:foreign_key => "thing_id",
|
190
|
+
:foreign_type => "thing_type",
|
191
|
+
:polymorphic => true
|
192
|
+
}
|
193
|
+
@reflection = stub('assoc reflection', :options => @options)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should return a new options set for a specific class" do
|
197
|
+
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
198
|
+
:polymorphic => nil,
|
199
|
+
:class_name => "Person",
|
200
|
+
:foreign_key => "thing_id",
|
201
|
+
:foreign_type => "thing_type",
|
202
|
+
:conditions => "::ts_join_alias::.`thing_type` = 'Person'"
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should append to existing Array of conditions" do
|
207
|
+
@options[:conditions] = ["first condition"]
|
208
|
+
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
209
|
+
:polymorphic => nil,
|
210
|
+
:class_name => "Person",
|
211
|
+
:foreign_key => "thing_id",
|
212
|
+
:foreign_type => "thing_type",
|
213
|
+
:conditions => ["first condition", "::ts_join_alias::.`thing_type` = 'Person'"]
|
214
|
+
}
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should merge to an existing Hash of conditions" do
|
218
|
+
@options[:conditions] = {"field" => "value"}
|
219
|
+
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
220
|
+
:polymorphic => nil,
|
221
|
+
:class_name => "Person",
|
222
|
+
:foreign_key => "thing_id",
|
223
|
+
:foreign_type => "thing_type",
|
224
|
+
:conditions => {"field" => "value", "thing_type" => "Person"}
|
225
|
+
}
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should append to an existing String of conditions" do
|
229
|
+
@options[:conditions] = "first condition"
|
230
|
+
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
231
|
+
:polymorphic => nil,
|
232
|
+
:class_name => "Person",
|
233
|
+
:foreign_key => "thing_id",
|
234
|
+
:foreign_type => "thing_type",
|
235
|
+
:conditions => "first condition AND ::ts_join_alias::.`thing_type` = 'Person'"
|
236
|
+
}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|