friendlyfashion-thinking-sphinx 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/HISTORY +244 -0
  2. data/LICENCE +20 -0
  3. data/README.textile +235 -0
  4. data/features/abstract_inheritance.feature +10 -0
  5. data/features/alternate_primary_key.feature +27 -0
  6. data/features/attribute_transformation.feature +22 -0
  7. data/features/attribute_updates.feature +77 -0
  8. data/features/deleting_instances.feature +67 -0
  9. data/features/direct_attributes.feature +11 -0
  10. data/features/excerpts.feature +21 -0
  11. data/features/extensible_delta_indexing.feature +9 -0
  12. data/features/facets.feature +88 -0
  13. data/features/facets_across_model.feature +29 -0
  14. data/features/field_sorting.feature +18 -0
  15. data/features/handling_edits.feature +94 -0
  16. data/features/retry_stale_indexes.feature +24 -0
  17. data/features/searching_across_models.feature +20 -0
  18. data/features/searching_by_index.feature +40 -0
  19. data/features/searching_by_model.feature +175 -0
  20. data/features/searching_with_find_arguments.feature +56 -0
  21. data/features/sphinx_detection.feature +25 -0
  22. data/features/sphinx_scopes.feature +68 -0
  23. data/features/step_definitions/alpha_steps.rb +16 -0
  24. data/features/step_definitions/beta_steps.rb +7 -0
  25. data/features/step_definitions/common_steps.rb +201 -0
  26. data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
  27. data/features/step_definitions/facet_steps.rb +96 -0
  28. data/features/step_definitions/find_arguments_steps.rb +36 -0
  29. data/features/step_definitions/gamma_steps.rb +15 -0
  30. data/features/step_definitions/scope_steps.rb +19 -0
  31. data/features/step_definitions/search_steps.rb +94 -0
  32. data/features/step_definitions/sphinx_steps.rb +35 -0
  33. data/features/sti_searching.feature +19 -0
  34. data/features/support/env.rb +27 -0
  35. data/features/support/lib/generic_delta_handler.rb +8 -0
  36. data/features/thinking_sphinx/database.example.yml +3 -0
  37. data/features/thinking_sphinx/db/.gitignore +1 -0
  38. data/features/thinking_sphinx/db/fixtures/alphas.rb +8 -0
  39. data/features/thinking_sphinx/db/fixtures/authors.rb +1 -0
  40. data/features/thinking_sphinx/db/fixtures/betas.rb +11 -0
  41. data/features/thinking_sphinx/db/fixtures/boxes.rb +9 -0
  42. data/features/thinking_sphinx/db/fixtures/categories.rb +1 -0
  43. data/features/thinking_sphinx/db/fixtures/cats.rb +3 -0
  44. data/features/thinking_sphinx/db/fixtures/comments.rb +24 -0
  45. data/features/thinking_sphinx/db/fixtures/developers.rb +31 -0
  46. data/features/thinking_sphinx/db/fixtures/dogs.rb +3 -0
  47. data/features/thinking_sphinx/db/fixtures/extensible_betas.rb +10 -0
  48. data/features/thinking_sphinx/db/fixtures/foxes.rb +3 -0
  49. data/features/thinking_sphinx/db/fixtures/gammas.rb +10 -0
  50. data/features/thinking_sphinx/db/fixtures/music.rb +4 -0
  51. data/features/thinking_sphinx/db/fixtures/people.rb +1001 -0
  52. data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
  53. data/features/thinking_sphinx/db/fixtures/posts.rb +10 -0
  54. data/features/thinking_sphinx/db/fixtures/robots.rb +8 -0
  55. data/features/thinking_sphinx/db/fixtures/tags.rb +27 -0
  56. data/features/thinking_sphinx/db/migrations/create_alphas.rb +8 -0
  57. data/features/thinking_sphinx/db/migrations/create_animals.rb +5 -0
  58. data/features/thinking_sphinx/db/migrations/create_authors.rb +3 -0
  59. data/features/thinking_sphinx/db/migrations/create_authors_posts.rb +6 -0
  60. data/features/thinking_sphinx/db/migrations/create_betas.rb +5 -0
  61. data/features/thinking_sphinx/db/migrations/create_boxes.rb +5 -0
  62. data/features/thinking_sphinx/db/migrations/create_categories.rb +3 -0
  63. data/features/thinking_sphinx/db/migrations/create_comments.rb +10 -0
  64. data/features/thinking_sphinx/db/migrations/create_developers.rb +7 -0
  65. data/features/thinking_sphinx/db/migrations/create_extensible_betas.rb +5 -0
  66. data/features/thinking_sphinx/db/migrations/create_gammas.rb +3 -0
  67. data/features/thinking_sphinx/db/migrations/create_genres.rb +3 -0
  68. data/features/thinking_sphinx/db/migrations/create_music.rb +6 -0
  69. data/features/thinking_sphinx/db/migrations/create_people.rb +13 -0
  70. data/features/thinking_sphinx/db/migrations/create_posts.rb +6 -0
  71. data/features/thinking_sphinx/db/migrations/create_robots.rb +4 -0
  72. data/features/thinking_sphinx/db/migrations/create_taggings.rb +5 -0
  73. data/features/thinking_sphinx/db/migrations/create_tags.rb +4 -0
  74. data/features/thinking_sphinx/models/alpha.rb +23 -0
  75. data/features/thinking_sphinx/models/andrew.rb +17 -0
  76. data/features/thinking_sphinx/models/animal.rb +5 -0
  77. data/features/thinking_sphinx/models/author.rb +3 -0
  78. data/features/thinking_sphinx/models/beta.rb +13 -0
  79. data/features/thinking_sphinx/models/box.rb +8 -0
  80. data/features/thinking_sphinx/models/cat.rb +3 -0
  81. data/features/thinking_sphinx/models/category.rb +4 -0
  82. data/features/thinking_sphinx/models/comment.rb +10 -0
  83. data/features/thinking_sphinx/models/developer.rb +21 -0
  84. data/features/thinking_sphinx/models/dog.rb +3 -0
  85. data/features/thinking_sphinx/models/extensible_beta.rb +9 -0
  86. data/features/thinking_sphinx/models/fox.rb +5 -0
  87. data/features/thinking_sphinx/models/gamma.rb +5 -0
  88. data/features/thinking_sphinx/models/genre.rb +3 -0
  89. data/features/thinking_sphinx/models/medium.rb +5 -0
  90. data/features/thinking_sphinx/models/music.rb +10 -0
  91. data/features/thinking_sphinx/models/person.rb +24 -0
  92. data/features/thinking_sphinx/models/post.rb +22 -0
  93. data/features/thinking_sphinx/models/robot.rb +12 -0
  94. data/features/thinking_sphinx/models/tag.rb +3 -0
  95. data/features/thinking_sphinx/models/tagging.rb +4 -0
  96. data/lib/cucumber/thinking_sphinx/external_world.rb +12 -0
  97. data/lib/cucumber/thinking_sphinx/internal_world.rb +137 -0
  98. data/lib/cucumber/thinking_sphinx/sql_logger.rb +28 -0
  99. data/lib/thinking-sphinx.rb +1 -0
  100. data/lib/thinking_sphinx/action_controller.rb +31 -0
  101. data/lib/thinking_sphinx/active_record/attribute_updates.rb +53 -0
  102. data/lib/thinking_sphinx/active_record/collection_proxy.rb +47 -0
  103. data/lib/thinking_sphinx/active_record/collection_proxy_with_scopes.rb +27 -0
  104. data/lib/thinking_sphinx/active_record/delta.rb +67 -0
  105. data/lib/thinking_sphinx/active_record/has_many_association.rb +44 -0
  106. data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +21 -0
  107. data/lib/thinking_sphinx/active_record/log_subscriber.rb +61 -0
  108. data/lib/thinking_sphinx/active_record/scopes.rb +110 -0
  109. data/lib/thinking_sphinx/active_record.rb +386 -0
  110. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +87 -0
  111. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +62 -0
  112. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +188 -0
  113. data/lib/thinking_sphinx/association.rb +230 -0
  114. data/lib/thinking_sphinx/attribute.rb +405 -0
  115. data/lib/thinking_sphinx/auto_version.rb +40 -0
  116. data/lib/thinking_sphinx/bundled_search.rb +44 -0
  117. data/lib/thinking_sphinx/class_facet.rb +20 -0
  118. data/lib/thinking_sphinx/configuration.rb +375 -0
  119. data/lib/thinking_sphinx/context.rb +76 -0
  120. data/lib/thinking_sphinx/core/string.rb +15 -0
  121. data/lib/thinking_sphinx/deltas/default_delta.rb +62 -0
  122. data/lib/thinking_sphinx/deltas.rb +28 -0
  123. data/lib/thinking_sphinx/deploy/capistrano.rb +99 -0
  124. data/lib/thinking_sphinx/excerpter.rb +23 -0
  125. data/lib/thinking_sphinx/facet.rb +135 -0
  126. data/lib/thinking_sphinx/facet_search.rb +170 -0
  127. data/lib/thinking_sphinx/field.rb +98 -0
  128. data/lib/thinking_sphinx/index/builder.rb +315 -0
  129. data/lib/thinking_sphinx/index/faux_column.rb +118 -0
  130. data/lib/thinking_sphinx/index.rb +159 -0
  131. data/lib/thinking_sphinx/join.rb +37 -0
  132. data/lib/thinking_sphinx/property.rb +187 -0
  133. data/lib/thinking_sphinx/railtie.rb +43 -0
  134. data/lib/thinking_sphinx/search.rb +1061 -0
  135. data/lib/thinking_sphinx/search_methods.rb +439 -0
  136. data/lib/thinking_sphinx/sinatra.rb +7 -0
  137. data/lib/thinking_sphinx/source/internal_properties.rb +51 -0
  138. data/lib/thinking_sphinx/source/sql.rb +174 -0
  139. data/lib/thinking_sphinx/source.rb +194 -0
  140. data/lib/thinking_sphinx/tasks.rb +142 -0
  141. data/lib/thinking_sphinx/test.rb +55 -0
  142. data/lib/thinking_sphinx/version.rb +3 -0
  143. data/lib/thinking_sphinx.rb +297 -0
  144. data/spec/fixtures/data.sql +32 -0
  145. data/spec/fixtures/database.yml.default +3 -0
  146. data/spec/fixtures/models.rb +164 -0
  147. data/spec/fixtures/structure.sql +146 -0
  148. data/spec/spec_helper.rb +61 -0
  149. data/spec/sphinx_helper.rb +60 -0
  150. data/spec/support/rails.rb +25 -0
  151. data/spec/thinking_sphinx/active_record/delta_spec.rb +122 -0
  152. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +173 -0
  153. data/spec/thinking_sphinx/active_record/scopes_spec.rb +176 -0
  154. data/spec/thinking_sphinx/active_record_spec.rb +573 -0
  155. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +145 -0
  156. data/spec/thinking_sphinx/association_spec.rb +250 -0
  157. data/spec/thinking_sphinx/attribute_spec.rb +552 -0
  158. data/spec/thinking_sphinx/auto_version_spec.rb +103 -0
  159. data/spec/thinking_sphinx/configuration_spec.rb +326 -0
  160. data/spec/thinking_sphinx/context_spec.rb +126 -0
  161. data/spec/thinking_sphinx/core/array_spec.rb +9 -0
  162. data/spec/thinking_sphinx/core/string_spec.rb +9 -0
  163. data/spec/thinking_sphinx/excerpter_spec.rb +49 -0
  164. data/spec/thinking_sphinx/facet_search_spec.rb +176 -0
  165. data/spec/thinking_sphinx/facet_spec.rb +359 -0
  166. data/spec/thinking_sphinx/field_spec.rb +127 -0
  167. data/spec/thinking_sphinx/index/builder_spec.rb +532 -0
  168. data/spec/thinking_sphinx/index/faux_column_spec.rb +36 -0
  169. data/spec/thinking_sphinx/index_spec.rb +189 -0
  170. data/spec/thinking_sphinx/search_methods_spec.rb +156 -0
  171. data/spec/thinking_sphinx/search_spec.rb +1455 -0
  172. data/spec/thinking_sphinx/source_spec.rb +267 -0
  173. data/spec/thinking_sphinx/test_spec.rb +20 -0
  174. data/spec/thinking_sphinx_spec.rb +204 -0
  175. metadata +524 -0
@@ -0,0 +1,250 @@
1
+ require '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', :name => 'non_polly')
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
+ reflections = double('reflections', :[]= => nil)
48
+ Person.stub!(:reflections => reflections)
49
+
50
+ Person.should_receive(:reflect_on_association).once.
51
+ and_return(@poly_reflection)
52
+ reflections.should_receive(:[]).with(:polly_Person).twice.and_return(nil)
53
+ ThinkingSphinx::Association.should_receive(:casted_options).with(
54
+ Person, @poly_reflection
55
+ ).twice
56
+ ::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
57
+ with(:has_many, :polly_Person, {:casted => :options}, "AR").twice.
58
+ and_return(@non_poly_reflection)
59
+ ThinkingSphinx::Association.should_receive(:new).with(
60
+ nil, @non_poly_reflection
61
+ ).twice
62
+
63
+ ThinkingSphinx::Association.children(Person, :assoc)
64
+ end
65
+
66
+ it "should use existing non-polymorphic 'casted' associations" do
67
+ reflections = double('reflections', :[]= => nil)
68
+ Person.stub!(:reflections => reflections)
69
+
70
+ Person.stub!(:reflect_on_association).once.
71
+ and_return(@poly_reflection)
72
+ reflections.should_receive(:[]).with(:polly_Person).twice.
73
+ and_return(nil, @non_poly_reflection)
74
+ ThinkingSphinx::Association.should_receive(:casted_options).with(
75
+ Person, @poly_reflection
76
+ ).once
77
+ ::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
78
+ with(:has_many, :polly_Person, {:casted => :options}, "AR").once.
79
+ and_return(@non_poly_reflection)
80
+ ThinkingSphinx::Association.should_receive(:new).with(
81
+ nil, @non_poly_reflection
82
+ ).twice
83
+
84
+ ThinkingSphinx::Association.children(Person, :assoc)
85
+ end
86
+ end
87
+
88
+ describe '#children' do
89
+ before :each do
90
+ @reflection = stub('reflection', :klass => :klass)
91
+ @association = ThinkingSphinx::Association.new(nil, @reflection)
92
+ ThinkingSphinx::Association.stub!(:children => :result)
93
+ end
94
+
95
+ it "should return the children associations for the given association" do
96
+ @association.children(:assoc).should == :result
97
+ end
98
+
99
+ it "should request children for the reflection klass" do
100
+ ThinkingSphinx::Association.should_receive(:children).
101
+ with(:klass, :assoc, @association)
102
+
103
+ @association.children(:assoc)
104
+ end
105
+ end
106
+
107
+ describe '#join_to' do
108
+ before :each do
109
+ @parent_join = stub('join assoc').as_null_object
110
+ @join = stub('join assoc').as_null_object
111
+ @parent = ThinkingSphinx::Association.new(nil, nil)
112
+ @parent.stub!(:join_to => true, :join => nil)
113
+ @base_join = stub('base join', :joins => [:a, :b, :c])
114
+
115
+ if ThinkingSphinx.rails_3_1?
116
+ ::ActiveRecord::Associations::JoinDependency::JoinAssociation.stub!(:new => @join)
117
+ else
118
+ ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub!(:new => @join)
119
+ end
120
+ end
121
+
122
+ it "should call the parent's join_to if parent has no join" do
123
+ @assoc = ThinkingSphinx::Association.new(@parent, :ref)
124
+ @parent.should_receive(:join_to).with(@base_join)
125
+
126
+ @assoc.join_to(@base_join)
127
+ end
128
+
129
+ it "should not call the parent's join_to if it already has a join" do
130
+ @assoc = ThinkingSphinx::Association.new(@parent, :ref)
131
+ @parent.stub!(:join => @parent_join)
132
+ @parent.should_not_receive(:join_to)
133
+
134
+ @assoc.join_to(@base_join)
135
+ end
136
+
137
+ it "should define the join association with a JoinAssociation instance" do
138
+ @assoc = ThinkingSphinx::Association.new(@parent, :ref)
139
+
140
+ @assoc.join_to(@base_join).should == @join
141
+ @assoc.join.should == @join
142
+ end
143
+ end
144
+
145
+ describe '#is_many?' do
146
+ before :each do
147
+ @parent = stub('assoc', :is_many? => :parent_is_many)
148
+ @reflection = stub('reflection', :macro => :has_many)
149
+ end
150
+
151
+ it "should return true if association is either a has_many or a habtm" do
152
+ association = ThinkingSphinx::Association.new(@parent, @reflection)
153
+ association.is_many?.should be_true
154
+
155
+ @reflection.stub!(:macro => :has_and_belongs_to_many)
156
+ association.is_many?.should be_true
157
+ end
158
+
159
+ it "should return the parent value if not a has many or habtm and there is a parent" do
160
+ association = ThinkingSphinx::Association.new(@parent, @reflection)
161
+ @reflection.stub!(:macro => :belongs_to)
162
+ association.is_many?.should == :parent_is_many
163
+ end
164
+
165
+ it "should return false if no parent and not a has many or habtm" do
166
+ association = ThinkingSphinx::Association.new(nil, @reflection)
167
+ @reflection.stub!(:macro => :belongs_to)
168
+ association.is_many?.should be_false
169
+ end
170
+ end
171
+
172
+ describe '#ancestors' do
173
+ it "should return an array of associations - including all parents" do
174
+ parent = stub('assoc', :ancestors => [:all, :ancestors])
175
+ association = ThinkingSphinx::Association.new(parent, @reflection)
176
+ association.ancestors.should == [:all, :ancestors, association]
177
+ end
178
+ end
179
+
180
+ describe '.polymorphic_classes' do
181
+ it "should return all the polymorphic result types as classes" do
182
+ Person.connection.stub!(:select_all => [
183
+ {"person_type" => "Person"},
184
+ {"person_type" => "Friendship"}
185
+ ])
186
+ ref = stub('ref',
187
+ :active_record => Person,
188
+ :options => {:foreign_type => "person_type"}
189
+ )
190
+ ref.stub!(:foreign_type => "person_type") if ThinkingSphinx.rails_3_1?
191
+
192
+ ThinkingSphinx::Association.send(:polymorphic_classes, ref).should == [Person, Friendship]
193
+ end
194
+ end
195
+
196
+ describe '.casted_options' do
197
+ before :each do
198
+ @options = {
199
+ :foreign_key => "thing_id",
200
+ :foreign_type => "thing_type",
201
+ :polymorphic => true
202
+ }
203
+ @reflection = stub('assoc reflection', :options => @options)
204
+ @reflection.stub!(:foreign_type => "thing_type") if ThinkingSphinx.rails_3_1?
205
+ end
206
+
207
+ it "should return a new options set for a specific class" do
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 => "::ts_join_alias::.`thing_type` = 'Person'"
214
+ }
215
+ end
216
+
217
+ it "should append to existing Array of conditions" do
218
+ @options[:conditions] = ["first condition"]
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 => ["first condition", "::ts_join_alias::.`thing_type` = 'Person'"]
225
+ }
226
+ end
227
+
228
+ it "should merge to an existing Hash of conditions" do
229
+ @options[:conditions] = {"field" => "value"}
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 => {"field" => "value", "thing_type" => "Person"}
236
+ }
237
+ end
238
+
239
+ it "should append to an existing String of conditions" do
240
+ @options[:conditions] = "first condition"
241
+ ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
242
+ :polymorphic => nil,
243
+ :class_name => "Person",
244
+ :foreign_key => "thing_id",
245
+ :foreign_type => "thing_type",
246
+ :conditions => "first condition AND ::ts_join_alias::.`thing_type` = 'Person'"
247
+ }
248
+ end
249
+ end
250
+ end