thorsson_thinking-sphinx 1.3.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +169 -0
  3. data/VERSION +1 -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 +13 -0
  11. data/features/extensible_delta_indexing.feature +9 -0
  12. data/features/facets.feature +82 -0
  13. data/features/facets_across_model.feature +29 -0
  14. data/features/handling_edits.feature +92 -0
  15. data/features/retry_stale_indexes.feature +24 -0
  16. data/features/searching_across_models.feature +20 -0
  17. data/features/searching_by_index.feature +40 -0
  18. data/features/searching_by_model.feature +175 -0
  19. data/features/searching_with_find_arguments.feature +56 -0
  20. data/features/sphinx_detection.feature +25 -0
  21. data/features/sphinx_scopes.feature +42 -0
  22. data/features/step_definitions/alpha_steps.rb +16 -0
  23. data/features/step_definitions/beta_steps.rb +7 -0
  24. data/features/step_definitions/common_steps.rb +193 -0
  25. data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
  26. data/features/step_definitions/facet_steps.rb +96 -0
  27. data/features/step_definitions/find_arguments_steps.rb +36 -0
  28. data/features/step_definitions/gamma_steps.rb +15 -0
  29. data/features/step_definitions/scope_steps.rb +15 -0
  30. data/features/step_definitions/search_steps.rb +89 -0
  31. data/features/step_definitions/sphinx_steps.rb +35 -0
  32. data/features/sti_searching.feature +19 -0
  33. data/features/support/env.rb +21 -0
  34. data/features/support/lib/generic_delta_handler.rb +8 -0
  35. data/features/thinking_sphinx/database.example.yml +3 -0
  36. data/features/thinking_sphinx/database.yml +3 -0
  37. data/features/thinking_sphinx/db/fixtures/alphas.rb +10 -0
  38. data/features/thinking_sphinx/db/fixtures/authors.rb +1 -0
  39. data/features/thinking_sphinx/db/fixtures/betas.rb +11 -0
  40. data/features/thinking_sphinx/db/fixtures/boxes.rb +9 -0
  41. data/features/thinking_sphinx/db/fixtures/categories.rb +1 -0
  42. data/features/thinking_sphinx/db/fixtures/cats.rb +3 -0
  43. data/features/thinking_sphinx/db/fixtures/comments.rb +24 -0
  44. data/features/thinking_sphinx/db/fixtures/developers.rb +31 -0
  45. data/features/thinking_sphinx/db/fixtures/dogs.rb +3 -0
  46. data/features/thinking_sphinx/db/fixtures/extensible_betas.rb +10 -0
  47. data/features/thinking_sphinx/db/fixtures/foxes.rb +3 -0
  48. data/features/thinking_sphinx/db/fixtures/gammas.rb +10 -0
  49. data/features/thinking_sphinx/db/fixtures/music.rb +4 -0
  50. data/features/thinking_sphinx/db/fixtures/people.rb +1001 -0
  51. data/features/thinking_sphinx/db/fixtures/posts.rb +6 -0
  52. data/features/thinking_sphinx/db/fixtures/robots.rb +14 -0
  53. data/features/thinking_sphinx/db/fixtures/tags.rb +27 -0
  54. data/features/thinking_sphinx/db/migrations/create_alphas.rb +8 -0
  55. data/features/thinking_sphinx/db/migrations/create_animals.rb +5 -0
  56. data/features/thinking_sphinx/db/migrations/create_authors.rb +3 -0
  57. data/features/thinking_sphinx/db/migrations/create_authors_posts.rb +6 -0
  58. data/features/thinking_sphinx/db/migrations/create_betas.rb +5 -0
  59. data/features/thinking_sphinx/db/migrations/create_boxes.rb +5 -0
  60. data/features/thinking_sphinx/db/migrations/create_categories.rb +3 -0
  61. data/features/thinking_sphinx/db/migrations/create_comments.rb +10 -0
  62. data/features/thinking_sphinx/db/migrations/create_developers.rb +7 -0
  63. data/features/thinking_sphinx/db/migrations/create_extensible_betas.rb +5 -0
  64. data/features/thinking_sphinx/db/migrations/create_gammas.rb +3 -0
  65. data/features/thinking_sphinx/db/migrations/create_genres.rb +3 -0
  66. data/features/thinking_sphinx/db/migrations/create_music.rb +6 -0
  67. data/features/thinking_sphinx/db/migrations/create_people.rb +13 -0
  68. data/features/thinking_sphinx/db/migrations/create_posts.rb +5 -0
  69. data/features/thinking_sphinx/db/migrations/create_robots.rb +4 -0
  70. data/features/thinking_sphinx/db/migrations/create_taggings.rb +5 -0
  71. data/features/thinking_sphinx/db/migrations/create_tags.rb +4 -0
  72. data/features/thinking_sphinx/models/alpha.rb +22 -0
  73. data/features/thinking_sphinx/models/animal.rb +5 -0
  74. data/features/thinking_sphinx/models/author.rb +3 -0
  75. data/features/thinking_sphinx/models/beta.rb +8 -0
  76. data/features/thinking_sphinx/models/box.rb +8 -0
  77. data/features/thinking_sphinx/models/cat.rb +3 -0
  78. data/features/thinking_sphinx/models/category.rb +4 -0
  79. data/features/thinking_sphinx/models/comment.rb +10 -0
  80. data/features/thinking_sphinx/models/developer.rb +16 -0
  81. data/features/thinking_sphinx/models/dog.rb +3 -0
  82. data/features/thinking_sphinx/models/extensible_beta.rb +9 -0
  83. data/features/thinking_sphinx/models/fox.rb +5 -0
  84. data/features/thinking_sphinx/models/gamma.rb +5 -0
  85. data/features/thinking_sphinx/models/genre.rb +3 -0
  86. data/features/thinking_sphinx/models/medium.rb +5 -0
  87. data/features/thinking_sphinx/models/music.rb +8 -0
  88. data/features/thinking_sphinx/models/person.rb +23 -0
  89. data/features/thinking_sphinx/models/post.rb +21 -0
  90. data/features/thinking_sphinx/models/robot.rb +12 -0
  91. data/features/thinking_sphinx/models/tag.rb +3 -0
  92. data/features/thinking_sphinx/models/tagging.rb +4 -0
  93. data/lib/cucumber/thinking_sphinx/external_world.rb +8 -0
  94. data/lib/cucumber/thinking_sphinx/internal_world.rb +127 -0
  95. data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
  96. data/lib/thinking_sphinx.rb +242 -0
  97. data/lib/thinking_sphinx/active_record.rb +380 -0
  98. data/lib/thinking_sphinx/active_record/attribute_updates.rb +50 -0
  99. data/lib/thinking_sphinx/active_record/delta.rb +61 -0
  100. data/lib/thinking_sphinx/active_record/has_many_association.rb +51 -0
  101. data/lib/thinking_sphinx/active_record/scopes.rb +75 -0
  102. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +47 -0
  103. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +58 -0
  104. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +147 -0
  105. data/lib/thinking_sphinx/association.rb +164 -0
  106. data/lib/thinking_sphinx/attribute.rb +380 -0
  107. data/lib/thinking_sphinx/auto_version.rb +22 -0
  108. data/lib/thinking_sphinx/class_facet.rb +15 -0
  109. data/lib/thinking_sphinx/configuration.rb +292 -0
  110. data/lib/thinking_sphinx/context.rb +74 -0
  111. data/lib/thinking_sphinx/core/array.rb +7 -0
  112. data/lib/thinking_sphinx/core/string.rb +15 -0
  113. data/lib/thinking_sphinx/deltas.rb +28 -0
  114. data/lib/thinking_sphinx/deltas/default_delta.rb +62 -0
  115. data/lib/thinking_sphinx/deploy/capistrano.rb +100 -0
  116. data/lib/thinking_sphinx/excerpter.rb +22 -0
  117. data/lib/thinking_sphinx/facet.rb +125 -0
  118. data/lib/thinking_sphinx/facet_search.rb +136 -0
  119. data/lib/thinking_sphinx/field.rb +80 -0
  120. data/lib/thinking_sphinx/index.rb +157 -0
  121. data/lib/thinking_sphinx/index/builder.rb +302 -0
  122. data/lib/thinking_sphinx/index/faux_column.rb +118 -0
  123. data/lib/thinking_sphinx/join.rb +37 -0
  124. data/lib/thinking_sphinx/property.rb +168 -0
  125. data/lib/thinking_sphinx/rails_additions.rb +150 -0
  126. data/lib/thinking_sphinx/search.rb +785 -0
  127. data/lib/thinking_sphinx/search_methods.rb +439 -0
  128. data/lib/thinking_sphinx/source.rb +159 -0
  129. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  130. data/lib/thinking_sphinx/source/sql.rb +130 -0
  131. data/lib/thinking_sphinx/tasks.rb +121 -0
  132. data/lib/thinking_sphinx/test.rb +55 -0
  133. data/rails/init.rb +16 -0
  134. data/spec/thinking_sphinx/active_record/delta_spec.rb +128 -0
  135. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +71 -0
  136. data/spec/thinking_sphinx/active_record/scopes_spec.rb +177 -0
  137. data/spec/thinking_sphinx/active_record_spec.rb +618 -0
  138. data/spec/thinking_sphinx/association_spec.rb +239 -0
  139. data/spec/thinking_sphinx/attribute_spec.rb +548 -0
  140. data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
  141. data/spec/thinking_sphinx/configuration_spec.rb +271 -0
  142. data/spec/thinking_sphinx/context_spec.rb +126 -0
  143. data/spec/thinking_sphinx/core/array_spec.rb +9 -0
  144. data/spec/thinking_sphinx/core/string_spec.rb +9 -0
  145. data/spec/thinking_sphinx/excerpter_spec.rb +49 -0
  146. data/spec/thinking_sphinx/facet_search_spec.rb +176 -0
  147. data/spec/thinking_sphinx/facet_spec.rb +333 -0
  148. data/spec/thinking_sphinx/field_spec.rb +113 -0
  149. data/spec/thinking_sphinx/index/builder_spec.rb +495 -0
  150. data/spec/thinking_sphinx/index/faux_column_spec.rb +36 -0
  151. data/spec/thinking_sphinx/index_spec.rb +183 -0
  152. data/spec/thinking_sphinx/rails_additions_spec.rb +203 -0
  153. data/spec/thinking_sphinx/search_methods_spec.rb +152 -0
  154. data/spec/thinking_sphinx/search_spec.rb +1206 -0
  155. data/spec/thinking_sphinx/source_spec.rb +243 -0
  156. data/spec/thinking_sphinx_spec.rb +204 -0
  157. data/tasks/distribution.rb +46 -0
  158. data/tasks/rails.rake +1 -0
  159. data/tasks/testing.rb +76 -0
  160. metadata +466 -0
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThinkingSphinx::AutoVersion do
4
+ describe '.detect' do
5
+ before :each do
6
+ @config = ThinkingSphinx::Configuration.instance
7
+ end
8
+
9
+ it "should require 0.9.8 if that is the detected version" do
10
+ ThinkingSphinx::AutoVersion.should_receive(:require).
11
+ with('riddle/0.9.8')
12
+
13
+ @config.stub!(:version => '0.9.8')
14
+ ThinkingSphinx::AutoVersion.detect
15
+ end
16
+
17
+ it "should require 0.9.9 if that is the detected version" do
18
+ ThinkingSphinx::AutoVersion.should_receive(:require).
19
+ with('riddle/0.9.9')
20
+
21
+ @config.stub!(:version => '0.9.9')
22
+ ThinkingSphinx::AutoVersion.detect
23
+ end
24
+
25
+ it "should output a warning if the detected version is something else" do
26
+ STDERR.should_receive(:puts)
27
+
28
+ @config.stub!(:version => '0.9.7')
29
+ ThinkingSphinx::AutoVersion.detect
30
+ end
31
+
32
+ it "should output a warning if the version cannot be determined" do
33
+ STDERR.should_receive(:puts)
34
+
35
+ @config.stub!(:version => nil)
36
+ ThinkingSphinx::AutoVersion.detect
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,271 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThinkingSphinx::Configuration do
4
+ describe "environment class method" do
5
+ before :each do
6
+ Thread.current[:thinking_sphinx_environment] = nil
7
+
8
+ ENV["RAILS_ENV"] = nil
9
+ end
10
+
11
+ it "should use the Merb environment value if set" do
12
+ unless defined?(Merb)
13
+ module ::Merb; end
14
+ end
15
+
16
+ ThinkingSphinx::Configuration.stub!(:defined? => true)
17
+ Merb.stub!(:environment => "merb_production")
18
+ ThinkingSphinx::Configuration.environment.should == "merb_production"
19
+
20
+ Object.send :remove_const, :Merb
21
+ end
22
+
23
+ it "should use RAILS_ENV if set" do
24
+ RAILS_ENV = 'global_rails'
25
+
26
+ ThinkingSphinx::Configuration.environment.should == 'global_rails'
27
+
28
+ Object.send :remove_const, :RAILS_ENV
29
+ end
30
+
31
+ it "should use the Rails environment value if set" do
32
+ ENV["RAILS_ENV"] = "rails_production"
33
+ ThinkingSphinx::Configuration.environment.should == "rails_production"
34
+ end
35
+
36
+ it "should default to development" do
37
+ ThinkingSphinx::Configuration.environment.should == "development"
38
+ end
39
+ end
40
+
41
+ describe '#version' do
42
+ before :each do
43
+ @config = ThinkingSphinx::Configuration.instance
44
+ @config.reset
45
+ end
46
+
47
+ it "should use the given version from sphinx.yml if there is one" do
48
+ open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
49
+ f.write YAML.dump({'development' => {'version' => '0.9.7'}})
50
+ end
51
+ @config.reset
52
+
53
+ @config.version.should == '0.9.7'
54
+
55
+ FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
56
+ end
57
+
58
+ it "should detect the version from Riddle otherwise" do
59
+ controller = @config.controller
60
+ controller.stub!(:sphinx_version => '0.9.6')
61
+
62
+ Riddle::Controller.stub!(:new => controller)
63
+ @config.reset
64
+
65
+ @config.version.should == '0.9.6'
66
+ end
67
+ end
68
+
69
+ describe "parse_config method" do
70
+ before :each do
71
+ @settings = {
72
+ "development" => {
73
+ "config_file" => "tmp/config/development.sphinx.conf",
74
+ "searchd_log_file" => "searchd_log_file.log",
75
+ "query_log_file" => "query_log_file.log",
76
+ "pid_file" => "pid_file.pid",
77
+ "searchd_file_path" => "searchd/file/path",
78
+ "address" => "127.0.0.1",
79
+ "port" => 3333,
80
+ "min_prefix_len" => 2,
81
+ "min_infix_len" => 3,
82
+ "mem_limit" => "128M",
83
+ "max_matches" => 1001,
84
+ "morphology" => "stem_ru",
85
+ "charset_type" => "latin1",
86
+ "charset_table" => "table",
87
+ "ignore_chars" => "e",
88
+ "searchd_binary_name" => "sphinx-searchd",
89
+ "indexer_binary_name" => "sphinx-indexer",
90
+ "index_exact_words" => true,
91
+ "indexed_models" => ['Alpha', 'Beta']
92
+ }
93
+ }
94
+
95
+ open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
96
+ f.write YAML.dump(@settings)
97
+ end
98
+ end
99
+
100
+ it "should use the accessors to set the configuration values" do
101
+ config = ThinkingSphinx::Configuration.instance
102
+ config.send(:parse_config)
103
+
104
+ %w(config_file searchd_log_file query_log_file pid_file searchd_file_path
105
+ address port searchd_binary_name indexer_binary_name).each do |key|
106
+ config.send(key).should == @settings["development"][key]
107
+ end
108
+ end
109
+
110
+ after :each do
111
+ FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
112
+ end
113
+ end
114
+
115
+ describe "block configuration" do
116
+ it "should let the user set-up a custom app_root" do
117
+ ThinkingSphinx::Configuration.configure do |config|
118
+ config.app_root = "/here/somewhere"
119
+ end
120
+ ThinkingSphinx::Configuration.instance.app_root.should == "/here/somewhere"
121
+ end
122
+ end
123
+
124
+ describe "initialisation" do
125
+ it "should have a default bin_path of nothing" do
126
+ ThinkingSphinx::Configuration.instance.bin_path.should == ""
127
+ end
128
+
129
+ it "should append a / to bin_path if one is supplied" do
130
+ @settings = {
131
+ "development" => {
132
+ "bin_path" => "path/to/somewhere"
133
+ }
134
+ }
135
+
136
+ open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
137
+ f.write YAML.dump(@settings)
138
+ end
139
+
140
+ ThinkingSphinx::Configuration.instance.send(:parse_config)
141
+ ThinkingSphinx::Configuration.instance.bin_path.should match(/\/$/)
142
+
143
+ FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
144
+ end
145
+ end
146
+
147
+ describe "index options" do
148
+ before :each do
149
+ @settings = {
150
+ "development" => {"disable_range" => true}
151
+ }
152
+
153
+ open("#{RAILS_ROOT}/config/sphinx.yml", "w") do |f|
154
+ f.write YAML.dump(@settings)
155
+ end
156
+
157
+ @config = ThinkingSphinx::Configuration.instance
158
+ @config.send(:parse_config)
159
+ end
160
+
161
+ it "should collect disable_range" do
162
+ @config.index_options[:disable_range].should be_true
163
+ end
164
+
165
+ after :each do
166
+ FileUtils.rm "#{RAILS_ROOT}/config/sphinx.yml"
167
+ end
168
+ end
169
+
170
+ it "should insert set index options into the configuration file" do
171
+ config = ThinkingSphinx::Configuration.instance
172
+
173
+ ThinkingSphinx::Configuration::IndexOptions.each do |option|
174
+ config.reset
175
+ config.index_options[option.to_sym] = "something"
176
+ config.build
177
+
178
+ file = open(config.config_file) { |f| f.read }
179
+ file.should match(/#{option}\s+= something/)
180
+
181
+ config.index_options[option.to_sym] = nil
182
+ end
183
+ end
184
+
185
+ it "should insert set source options into the configuration file" do
186
+ config = ThinkingSphinx::Configuration.instance
187
+ config.reset
188
+
189
+ config.source_options[:sql_query_pre] = ["something"]
190
+ ThinkingSphinx::Configuration::SourceOptions.each do |option|
191
+ config.source_options[option.to_sym] ||= "something"
192
+ config.build
193
+
194
+ file = open(config.config_file) { |f| f.read }
195
+ file.should match(/#{option}\s+= something/)
196
+
197
+ config.source_options.delete option.to_sym
198
+ end
199
+
200
+ config.source_options[:sql_query_pre] = nil
201
+ end
202
+
203
+ it "should not blow away delta or utf options if sql pre is specified in config" do
204
+ config = ThinkingSphinx::Configuration.instance
205
+ config.reset
206
+
207
+ config.source_options[:sql_query_pre] = ["a pre query"]
208
+ config.build
209
+ file = open(config.config_file) { |f| f.read }
210
+
211
+ file.should match(/sql_query_pre = a pre query\n\s*sql_query_pre = UPDATE `\w+` SET `delta` = 0 WHERE `delta` = 1/im)
212
+ file.should match(/sql_query_pre = a pre query\n\s*sql_query_pre = \n/im)
213
+
214
+ config.source_options[:sql_query_pre] = nil
215
+ end
216
+
217
+ it "should set any explicit prefixed or infixed fields" do
218
+ file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
219
+ f.read
220
+ }
221
+ file.should match(/prefix_fields\s+= city/)
222
+ file.should match(/infix_fields\s+= state/)
223
+ end
224
+
225
+ it "should not have prefix fields in indexes where nothing is set" do
226
+ file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
227
+ f.read
228
+ }
229
+ file.should_not match(/index alpha_core\s+\{\s+[^\}]*prefix_fields\s+=[^\}]*\}/m)
230
+ end
231
+
232
+ describe '#client' do
233
+ before :each do
234
+ @config = ThinkingSphinx::Configuration.instance
235
+ @config.address = 'domain.url'
236
+ @config.port = 3333
237
+ @config.configuration.searchd.max_matches = 100
238
+ end
239
+
240
+ it "should return an instance of Riddle::Client" do
241
+ @config.client.should be_a(Riddle::Client)
242
+ end
243
+
244
+ it "should use the configuration address" do
245
+ @config.client.server.should == 'domain.url'
246
+ end
247
+
248
+ it "should use the configuration port" do
249
+ @config.client.port.should == 3333
250
+ end
251
+
252
+ it "should use the configuration max matches" do
253
+ @config.client.max_matches.should == 100
254
+ end
255
+ end
256
+
257
+ describe '#models_by_crc' do
258
+ before :each do
259
+ @config = ThinkingSphinx::Configuration.instance
260
+ end
261
+
262
+ it "should return a hash" do
263
+ @config.models_by_crc.should be_a(Hash)
264
+ end
265
+
266
+ it "should pair class names to their crc codes" do
267
+ @config.models_by_crc[Person.to_crc32].should == 'Person'
268
+ @config.models_by_crc[Alpha.to_crc32].should == 'Alpha'
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThinkingSphinx::Context do
4
+ before :each do
5
+ @context = ThinkingSphinx::Context.new
6
+ end
7
+
8
+ describe '#prepare' do
9
+ before :each do
10
+ @config = ThinkingSphinx::Configuration.instance
11
+ @config.model_directories = ['']
12
+
13
+ @file_name = 'a.rb'
14
+ @model_name_lower = 'a'
15
+ @class_name = 'A'
16
+
17
+ @file_name.stub!(:gsub).and_return(@model_name_lower)
18
+ @model_name_lower.stub!(:camelize).and_return(@class_name)
19
+ Dir.stub(:[]).and_return([@file_name])
20
+ end
21
+
22
+ it "should load the files by guessing the file name" do
23
+ @class_name.should_receive(:constantize).and_return(true)
24
+
25
+ @context.prepare
26
+ end
27
+
28
+ it "should not raise errors if the model name is nil" do
29
+ @file_name.stub!(:gsub).and_return(nil)
30
+
31
+ lambda {
32
+ @context.prepare
33
+ }.should_not raise_error
34
+ end
35
+
36
+ it "should not raise errors if the file name does not represent a class name" do
37
+ @class_name.should_receive(:constantize).and_raise(NameError)
38
+
39
+ lambda {
40
+ @context.prepare
41
+ }.should_not raise_error
42
+ end
43
+
44
+ it "should retry if the first pass fails and contains a directory" do
45
+ @model_name_lower.stub!(:gsub!).and_return(true, nil)
46
+ @class_name.stub(:constantize).and_raise(LoadError)
47
+ @model_name_lower.should_receive(:camelize).twice
48
+
49
+ lambda {
50
+ @context.prepare
51
+ }.should_not raise_error
52
+ end
53
+
54
+ it "should catch database errors with a warning" do
55
+ @class_name.should_receive(:constantize).and_raise(Mysql::Error)
56
+ STDERR.should_receive(:puts).with('Warning: Error loading a.rb')
57
+
58
+ lambda {
59
+ @context.prepare
60
+ }.should_not raise_error
61
+ end
62
+
63
+ it "should not load models if they're explicitly set in the configuration" do
64
+ @config.indexed_models = ['Alpha', 'Beta']
65
+ @context.prepare
66
+
67
+ @context.indexed_models.should == ['Alpha', 'Beta']
68
+ end
69
+ end
70
+
71
+ describe '#define_indexes' do
72
+ it "should call define_indexes on all known indexed models" do
73
+ @context.stub!(:indexed_models => ['Alpha', 'Beta'])
74
+ Alpha.should_receive(:define_indexes)
75
+ Beta.should_receive(:define_indexes)
76
+
77
+ @context.define_indexes
78
+ end
79
+ end
80
+
81
+ describe '#add_indexed_model' do
82
+ before :each do
83
+ @context.indexed_models.clear
84
+ end
85
+
86
+ it "should add the model to the collection" do
87
+ @context.add_indexed_model 'Alpha'
88
+
89
+ @context.indexed_models.should == ['Alpha']
90
+ end
91
+
92
+ it "should not duplicate models in the collection" do
93
+ @context.add_indexed_model 'Alpha'
94
+ @context.add_indexed_model 'Alpha'
95
+
96
+ @context.indexed_models.should == ['Alpha']
97
+ end
98
+
99
+ it "should keep the collection in alphabetical order" do
100
+ @context.add_indexed_model 'Beta'
101
+ @context.add_indexed_model 'Alpha'
102
+
103
+ @context.indexed_models.should == ['Alpha', 'Beta']
104
+ end
105
+
106
+ it "should translate classes to their names" do
107
+ @context.add_indexed_model Alpha
108
+
109
+ @context.indexed_models.should == ['Alpha']
110
+ end
111
+ end
112
+
113
+ describe '#superclass_indexed_models' do
114
+ it "should return indexed model names" do
115
+ @context.stub!(:indexed_models => ['Alpha', 'Beta'])
116
+
117
+ @context.superclass_indexed_models.should == ['Alpha', 'Beta']
118
+ end
119
+
120
+ it "should not include classes which have indexed superclasses" do
121
+ @context.stub!(:indexed_models => ['Parent', 'Person'])
122
+
123
+ @context.superclass_indexed_models.should == ['Person']
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+ describe '.===' do
5
+ it "should return true if an instance of ThinkingSphinx::Search" do
6
+ Array.should === ThinkingSphinx::Search.new
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ describe "to_crc32 instance method" do
5
+ it "should return an integer" do
6
+ 'to_crc32'.to_crc32.should be_a_kind_of(Integer)
7
+ end
8
+ end
9
+ end