warp-thinking-sphinx 1.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +144 -0
  3. data/VERSION.yml +4 -0
  4. data/features/a.rb +17 -0
  5. data/features/alternate_primary_key.feature +27 -0
  6. data/features/attribute_transformation.feature +22 -0
  7. data/features/attribute_updates.feature +33 -0
  8. data/features/datetime_deltas.feature +66 -0
  9. data/features/delayed_delta_indexing.feature +37 -0
  10. data/features/deleting_instances.feature +64 -0
  11. data/features/direct_attributes.feature +11 -0
  12. data/features/excerpts.feature +13 -0
  13. data/features/extensible_delta_indexing.feature +9 -0
  14. data/features/facets.feature +76 -0
  15. data/features/facets_across_model.feature +29 -0
  16. data/features/handling_edits.feature +92 -0
  17. data/features/retry_stale_indexes.feature +24 -0
  18. data/features/searching_across_models.feature +20 -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 +35 -0
  23. data/features/step_definitions/alpha_steps.rb +3 -0
  24. data/features/step_definitions/beta_steps.rb +7 -0
  25. data/features/step_definitions/common_steps.rb +178 -0
  26. data/features/step_definitions/datetime_delta_steps.rb +15 -0
  27. data/features/step_definitions/delayed_delta_indexing_steps.rb +7 -0
  28. data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
  29. data/features/step_definitions/facet_steps.rb +92 -0
  30. data/features/step_definitions/find_arguments_steps.rb +36 -0
  31. data/features/step_definitions/gamma_steps.rb +15 -0
  32. data/features/step_definitions/scope_steps.rb +11 -0
  33. data/features/step_definitions/search_steps.rb +89 -0
  34. data/features/step_definitions/sphinx_steps.rb +31 -0
  35. data/features/sti_searching.feature +14 -0
  36. data/features/support/db/active_record.rb +40 -0
  37. data/features/support/db/database.example.yml +3 -0
  38. data/features/support/db/fixtures/alphas.rb +10 -0
  39. data/features/support/db/fixtures/authors.rb +1 -0
  40. data/features/support/db/fixtures/betas.rb +10 -0
  41. data/features/support/db/fixtures/boxes.rb +9 -0
  42. data/features/support/db/fixtures/categories.rb +1 -0
  43. data/features/support/db/fixtures/cats.rb +3 -0
  44. data/features/support/db/fixtures/comments.rb +24 -0
  45. data/features/support/db/fixtures/delayed_betas.rb +10 -0
  46. data/features/support/db/fixtures/developers.rb +29 -0
  47. data/features/support/db/fixtures/dogs.rb +3 -0
  48. data/features/support/db/fixtures/extensible_betas.rb +10 -0
  49. data/features/support/db/fixtures/gammas.rb +10 -0
  50. data/features/support/db/fixtures/people.rb +1001 -0
  51. data/features/support/db/fixtures/posts.rb +6 -0
  52. data/features/support/db/fixtures/robots.rb +14 -0
  53. data/features/support/db/fixtures/tags.rb +27 -0
  54. data/features/support/db/fixtures/thetas.rb +10 -0
  55. data/features/support/db/migrations/create_alphas.rb +7 -0
  56. data/features/support/db/migrations/create_animals.rb +5 -0
  57. data/features/support/db/migrations/create_authors.rb +3 -0
  58. data/features/support/db/migrations/create_authors_posts.rb +6 -0
  59. data/features/support/db/migrations/create_betas.rb +5 -0
  60. data/features/support/db/migrations/create_boxes.rb +5 -0
  61. data/features/support/db/migrations/create_categories.rb +3 -0
  62. data/features/support/db/migrations/create_comments.rb +10 -0
  63. data/features/support/db/migrations/create_delayed_betas.rb +17 -0
  64. data/features/support/db/migrations/create_developers.rb +9 -0
  65. data/features/support/db/migrations/create_extensible_betas.rb +5 -0
  66. data/features/support/db/migrations/create_gammas.rb +3 -0
  67. data/features/support/db/migrations/create_people.rb +13 -0
  68. data/features/support/db/migrations/create_posts.rb +5 -0
  69. data/features/support/db/migrations/create_robots.rb +5 -0
  70. data/features/support/db/migrations/create_taggings.rb +5 -0
  71. data/features/support/db/migrations/create_tags.rb +4 -0
  72. data/features/support/db/migrations/create_thetas.rb +5 -0
  73. data/features/support/db/mysql.rb +3 -0
  74. data/features/support/db/postgresql.rb +3 -0
  75. data/features/support/env.rb +6 -0
  76. data/features/support/lib/generic_delta_handler.rb +8 -0
  77. data/features/support/models/alpha.rb +10 -0
  78. data/features/support/models/animal.rb +5 -0
  79. data/features/support/models/author.rb +3 -0
  80. data/features/support/models/beta.rb +8 -0
  81. data/features/support/models/box.rb +8 -0
  82. data/features/support/models/cat.rb +3 -0
  83. data/features/support/models/category.rb +4 -0
  84. data/features/support/models/comment.rb +10 -0
  85. data/features/support/models/delayed_beta.rb +7 -0
  86. data/features/support/models/developer.rb +16 -0
  87. data/features/support/models/dog.rb +3 -0
  88. data/features/support/models/extensible_beta.rb +9 -0
  89. data/features/support/models/gamma.rb +5 -0
  90. data/features/support/models/person.rb +23 -0
  91. data/features/support/models/post.rb +20 -0
  92. data/features/support/models/robot.rb +8 -0
  93. data/features/support/models/tag.rb +3 -0
  94. data/features/support/models/tagging.rb +4 -0
  95. data/features/support/models/theta.rb +7 -0
  96. data/features/support/post_database.rb +43 -0
  97. data/features/support/z.rb +19 -0
  98. data/lib/thinking_sphinx.rb +212 -0
  99. data/lib/thinking_sphinx/active_record.rb +306 -0
  100. data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
  101. data/lib/thinking_sphinx/active_record/delta.rb +87 -0
  102. data/lib/thinking_sphinx/active_record/has_many_association.rb +28 -0
  103. data/lib/thinking_sphinx/active_record/scopes.rb +39 -0
  104. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
  105. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
  106. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +136 -0
  107. data/lib/thinking_sphinx/association.rb +243 -0
  108. data/lib/thinking_sphinx/attribute.rb +340 -0
  109. data/lib/thinking_sphinx/class_facet.rb +15 -0
  110. data/lib/thinking_sphinx/configuration.rb +282 -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 +30 -0
  114. data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
  115. data/lib/thinking_sphinx/deltas/default_delta.rb +68 -0
  116. data/lib/thinking_sphinx/deltas/delayed_delta.rb +30 -0
  117. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
  118. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
  119. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
  120. data/lib/thinking_sphinx/deploy/capistrano.rb +100 -0
  121. data/lib/thinking_sphinx/excerpter.rb +22 -0
  122. data/lib/thinking_sphinx/facet.rb +125 -0
  123. data/lib/thinking_sphinx/facet_search.rb +134 -0
  124. data/lib/thinking_sphinx/field.rb +81 -0
  125. data/lib/thinking_sphinx/index.rb +99 -0
  126. data/lib/thinking_sphinx/index/builder.rb +286 -0
  127. data/lib/thinking_sphinx/index/faux_column.rb +110 -0
  128. data/lib/thinking_sphinx/property.rb +163 -0
  129. data/lib/thinking_sphinx/rails_additions.rb +150 -0
  130. data/lib/thinking_sphinx/search.rb +708 -0
  131. data/lib/thinking_sphinx/search_methods.rb +421 -0
  132. data/lib/thinking_sphinx/source.rb +152 -0
  133. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  134. data/lib/thinking_sphinx/source/sql.rb +127 -0
  135. data/lib/thinking_sphinx/tasks.rb +165 -0
  136. data/rails/init.rb +14 -0
  137. data/spec/lib/thinking_sphinx/active_record/delta_spec.rb +130 -0
  138. data/spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb +49 -0
  139. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +96 -0
  140. data/spec/lib/thinking_sphinx/active_record_spec.rb +353 -0
  141. data/spec/lib/thinking_sphinx/association_spec.rb +239 -0
  142. data/spec/lib/thinking_sphinx/attribute_spec.rb +507 -0
  143. data/spec/lib/thinking_sphinx/configuration_spec.rb +268 -0
  144. data/spec/lib/thinking_sphinx/core/array_spec.rb +9 -0
  145. data/spec/lib/thinking_sphinx/core/string_spec.rb +9 -0
  146. data/spec/lib/thinking_sphinx/deltas/job_spec.rb +32 -0
  147. data/spec/lib/thinking_sphinx/excerpter_spec.rb +57 -0
  148. data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
  149. data/spec/lib/thinking_sphinx/facet_spec.rb +333 -0
  150. data/spec/lib/thinking_sphinx/field_spec.rb +154 -0
  151. data/spec/lib/thinking_sphinx/index/builder_spec.rb +455 -0
  152. data/spec/lib/thinking_sphinx/index/faux_column_spec.rb +30 -0
  153. data/spec/lib/thinking_sphinx/index_spec.rb +45 -0
  154. data/spec/lib/thinking_sphinx/rails_additions_spec.rb +203 -0
  155. data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
  156. data/spec/lib/thinking_sphinx/search_spec.rb +1101 -0
  157. data/spec/lib/thinking_sphinx/source_spec.rb +227 -0
  158. data/spec/lib/thinking_sphinx_spec.rb +162 -0
  159. data/tasks/distribution.rb +55 -0
  160. data/tasks/rails.rake +1 -0
  161. data/tasks/testing.rb +83 -0
  162. data/vendor/after_commit/LICENSE +20 -0
  163. data/vendor/after_commit/README +16 -0
  164. data/vendor/after_commit/Rakefile +22 -0
  165. data/vendor/after_commit/init.rb +8 -0
  166. data/vendor/after_commit/lib/after_commit.rb +45 -0
  167. data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
  168. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
  169. data/vendor/after_commit/test/after_commit_test.rb +53 -0
  170. data/vendor/delayed_job/lib/delayed/job.rb +251 -0
  171. data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
  172. data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
  173. data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
  174. data/vendor/riddle/lib/riddle.rb +30 -0
  175. data/vendor/riddle/lib/riddle/client.rb +635 -0
  176. data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
  177. data/vendor/riddle/lib/riddle/client/message.rb +66 -0
  178. data/vendor/riddle/lib/riddle/client/response.rb +84 -0
  179. data/vendor/riddle/lib/riddle/configuration.rb +33 -0
  180. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
  181. data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
  182. data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
  183. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
  184. data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
  185. data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
  186. data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
  187. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
  188. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
  189. data/vendor/riddle/lib/riddle/controller.rb +53 -0
  190. metadata +267 -0
@@ -0,0 +1,227 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ThinkingSphinx::Source do
4
+ before :each do
5
+ @index = ThinkingSphinx::Index.new(Person)
6
+ @source = ThinkingSphinx::Source.new(@index, :sql_range_step => 1000)
7
+ end
8
+
9
+ it "should generate the name from the model" do
10
+ @source.name.should == "person"
11
+ end
12
+
13
+ it "should handle namespaced models for name generation" do
14
+ index = ThinkingSphinx::Index.new(Admin::Person)
15
+ source = ThinkingSphinx::Source.new(index)
16
+ source.name.should == "admin_person"
17
+ end
18
+
19
+ describe "#to_riddle_for_core" do
20
+ before :each do
21
+ config = ThinkingSphinx::Configuration.instance
22
+ config.source_options[:sql_ranged_throttle] = 100
23
+
24
+ ThinkingSphinx::Field.new(
25
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
26
+ )
27
+ ThinkingSphinx::Field.new(
28
+ @source, ThinkingSphinx::Index::FauxColumn.new(:last_name)
29
+ )
30
+
31
+ ThinkingSphinx::Attribute.new(
32
+ @source, ThinkingSphinx::Index::FauxColumn.new(:id), :as => :internal_id
33
+ )
34
+ ThinkingSphinx::Attribute.new(
35
+ @source, ThinkingSphinx::Index::FauxColumn.new(:birthday)
36
+ )
37
+ ThinkingSphinx::Attribute.new(
38
+ @source, ThinkingSphinx::Index::FauxColumn.new(:tags, :id), :as => :tag_ids
39
+ )
40
+ ThinkingSphinx::Attribute.new(
41
+ @source, ThinkingSphinx::Index::FauxColumn.new(:contacts, :id),
42
+ :as => :contact_ids, :source => :query
43
+ )
44
+
45
+ @source.conditions << "`birthday` <= NOW()"
46
+ @source.groupings << "`first_name`"
47
+
48
+ @index.local_options[:group_concat_max_len] = 1024
49
+
50
+ @riddle = @source.to_riddle_for_core(1, 0)
51
+ end
52
+
53
+ it "should generate a Riddle Source object" do
54
+ @riddle.should be_a_kind_of(Riddle::Configuration::SQLSource)
55
+ end
56
+
57
+ it "should use the index and name its own name" do
58
+ @riddle.name.should == "person_core_0"
59
+ end
60
+
61
+ it "should use the model's database connection to determine type" do
62
+ @riddle.type.should == "mysql"
63
+ end
64
+
65
+ it "should match the model's database settings" do
66
+ config = Person.connection.instance_variable_get(:@config)
67
+ @riddle.sql_db.should == config[:database]
68
+ @riddle.sql_user.should == config[:username]
69
+ @riddle.sql_pass.should == config[:password].to_s
70
+ @riddle.sql_host.should == config[:host]
71
+ @riddle.sql_port.should == config[:port]
72
+ @riddle.sql_sock.should == config[:socket]
73
+ end
74
+
75
+ it "should use a default username of root if nothing else is provided" do
76
+ Person.connection.stub!(:instance_variable_get => {
77
+ :user => nil,
78
+ :username => nil
79
+ })
80
+
81
+ riddle = @source.to_riddle_for_core(1, 0)
82
+ riddle.sql_user.should == 'root'
83
+ end
84
+
85
+ it "should assign attributes" do
86
+ # 3 internal attributes plus the one requested
87
+ @riddle.sql_attr_uint.length.should == 4
88
+ @riddle.sql_attr_uint.last.should == :internal_id
89
+
90
+ @riddle.sql_attr_timestamp.length.should == 1
91
+ @riddle.sql_attr_timestamp.first.should == :birthday
92
+ end
93
+
94
+ it "should set Sphinx Source options" do
95
+ @riddle.sql_range_step.should == 1000
96
+ @riddle.sql_ranged_throttle.should == 100
97
+ end
98
+
99
+ describe "#sql_query" do
100
+ before :each do
101
+ @query = @riddle.sql_query
102
+ end
103
+
104
+ it "should select data from the model table" do
105
+ @query.should match(/FROM `people`/)
106
+ end
107
+
108
+ it "should select each of the fields" do
109
+ @query.should match(/`first_name`.+FROM/)
110
+ @query.should match(/`last_name`.+FROM/)
111
+ end
112
+
113
+ it "should select each of the attributes" do
114
+ @query.should match(/`id` AS `internal_id`.+FROM/)
115
+ @query.should match(/`birthday`.+FROM/)
116
+ @query.should match(/`tags`.`id`.+ AS `tag_ids`.+FROM/)
117
+ end
118
+
119
+ it "should not match the sourced MVA attribute" do
120
+ @query.should_not match(/contact_ids/)
121
+ end
122
+
123
+ it "should include joins for required associations" do
124
+ @query.should match(/LEFT OUTER JOIN `tags`/)
125
+ end
126
+
127
+ it "should not include joins for the sourced MVA attribute" do
128
+ @query.should_not match(/LEFT OUTER JOIN `contacts`/)
129
+ end
130
+
131
+ it "should include any defined conditions" do
132
+ @query.should match(/WHERE.+`birthday` <= NOW()/)
133
+ end
134
+
135
+ it "should include any defined groupings" do
136
+ @query.should match(/GROUP BY.+`first_name`/)
137
+ end
138
+ end
139
+
140
+ describe "#sql_query_range" do
141
+ before :each do
142
+ @query = @riddle.sql_query_range
143
+ end
144
+
145
+ it "should select data from the model table" do
146
+ @query.should match(/FROM `people`/)
147
+ end
148
+
149
+ it "should select the minimum and the maximum ids" do
150
+ @query.should match(/SELECT.+MIN.+MAX.+FROM/)
151
+ end
152
+ end
153
+
154
+ describe "#sql_query_info" do
155
+ before :each do
156
+ @query = @riddle.sql_query_info
157
+ end
158
+
159
+ it "should select all fields from the model table" do
160
+ @query.should match(/SELECT \* FROM `people`/)
161
+ end
162
+
163
+ it "should filter the primary key with the offset" do
164
+ model_count = ThinkingSphinx.indexed_models.size
165
+ @query.should match(/WHERE `id` = \(\(\$id - 1\) \/ #{model_count}\)/)
166
+ end
167
+ end
168
+
169
+ describe "#sql_query_pre" do
170
+ before :each do
171
+ @queries = @riddle.sql_query_pre
172
+ end
173
+
174
+ it "should default to just the UTF8 statement" do
175
+ @queries.detect { |query|
176
+ query == "SET NAMES utf8"
177
+ }.should_not be_nil
178
+ end
179
+
180
+ it "should set the group_concat_max_len session value for MySQL if requested" do
181
+ @queries.detect { |query|
182
+ query == "SET SESSION group_concat_max_len = 1024"
183
+ }.should_not be_nil
184
+ end
185
+ end
186
+ end
187
+
188
+ describe "#to_riddle_for_core with range disabled" do
189
+ before :each do
190
+ ThinkingSphinx::Field.new(
191
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
192
+ )
193
+ end
194
+
195
+ describe "set per-index" do
196
+ before :each do
197
+ @index.local_options[:disable_range] = true
198
+ @riddle = @source.to_riddle_for_core(1, 0)
199
+ end
200
+
201
+ it "should not have the range in the sql_query" do
202
+ @riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
203
+ @riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
204
+ end
205
+
206
+ it "should not have a sql_query_range" do
207
+ @riddle.sql_query_range.should be_nil
208
+ end
209
+ end
210
+
211
+ describe "set globally" do
212
+ before :each do
213
+ ThinkingSphinx::Configuration.instance.index_options[:disable_range] = true
214
+ @riddle = @source.to_riddle_for_core(1, 0)
215
+ end
216
+
217
+ it "should not have the range in the sql_query" do
218
+ @riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
219
+ @riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
220
+ end
221
+
222
+ it "should not have a sql_query_range" do
223
+ @riddle.sql_query_range.should be_nil
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,162 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ThinkingSphinx do
4
+ it "should define indexes by default" do
5
+ ThinkingSphinx.define_indexes?.should be_true
6
+ end
7
+
8
+ it "should disable index definition" do
9
+ ThinkingSphinx.define_indexes = false
10
+ ThinkingSphinx.define_indexes?.should be_false
11
+ end
12
+
13
+ it "should enable index definition" do
14
+ ThinkingSphinx.define_indexes = false
15
+ ThinkingSphinx.define_indexes?.should be_false
16
+ ThinkingSphinx.define_indexes = true
17
+ ThinkingSphinx.define_indexes?.should be_true
18
+ end
19
+
20
+ it "should index deltas by default" do
21
+ ThinkingSphinx.deltas_enabled = nil
22
+ ThinkingSphinx.deltas_enabled?.should be_true
23
+ end
24
+
25
+ it "should disable delta indexing" do
26
+ ThinkingSphinx.deltas_enabled = false
27
+ ThinkingSphinx.deltas_enabled?.should be_false
28
+ end
29
+
30
+ it "should enable delta indexing" do
31
+ ThinkingSphinx.deltas_enabled = false
32
+ ThinkingSphinx.deltas_enabled?.should be_false
33
+ ThinkingSphinx.deltas_enabled = true
34
+ ThinkingSphinx.deltas_enabled?.should be_true
35
+ end
36
+
37
+ it "should update indexes by default" do
38
+ ThinkingSphinx.updates_enabled = nil
39
+ ThinkingSphinx.updates_enabled?.should be_true
40
+ end
41
+
42
+ it "should disable index updating" do
43
+ ThinkingSphinx.updates_enabled = false
44
+ ThinkingSphinx.updates_enabled?.should be_false
45
+ end
46
+
47
+ it "should enable index updating" do
48
+ ThinkingSphinx.updates_enabled = false
49
+ ThinkingSphinx.updates_enabled?.should be_false
50
+ ThinkingSphinx.updates_enabled = true
51
+ ThinkingSphinx.updates_enabled?.should be_true
52
+ end
53
+
54
+ it "should always say Sphinx is running if flagged as being on a remote machine" do
55
+ ThinkingSphinx.remote_sphinx = true
56
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
57
+
58
+ ThinkingSphinx.sphinx_running?.should be_true
59
+ end
60
+
61
+ it "should actually pay attention to Sphinx if not on a remote machine" do
62
+ ThinkingSphinx.remote_sphinx = false
63
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
64
+ ThinkingSphinx.sphinx_running?.should be_false
65
+
66
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
67
+ ThinkingSphinx.sphinx_running?.should be_true
68
+ end
69
+
70
+ describe '.version' do
71
+ it "should return the version from the stored YAML file" do
72
+ version = Jeweler::VersionHelper.new(
73
+ File.join(File.dirname(__FILE__), '../..')
74
+ ).to_s
75
+
76
+ ThinkingSphinx.version.should == version
77
+ end
78
+ end
79
+
80
+ describe "use_group_by_shortcut? method" do
81
+ before :each do
82
+ adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
83
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
84
+ pending "No MySQL"
85
+ return
86
+ end
87
+
88
+ @connection = stub('adapter',
89
+ :select_all => true,
90
+ :class => ActiveRecord::ConnectionAdapters::MysqlAdapter,
91
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
92
+ )
93
+ ::ActiveRecord::Base.stub!(
94
+ :connection => @connection
95
+ )
96
+ end
97
+
98
+ it "should return true if no ONLY_FULL_GROUP_BY" do
99
+ @connection.stub!(
100
+ :select_all => {:a => "OTHER SETTINGS"}
101
+ )
102
+
103
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
104
+ end
105
+
106
+ it "should return true if NULL value" do
107
+ @connection.stub!(
108
+ :select_all => {:a => nil}
109
+ )
110
+
111
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
112
+ end
113
+
114
+ it "should return false if ONLY_FULL_GROUP_BY is set" do
115
+ @connection.stub!(
116
+ :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
117
+ )
118
+
119
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
120
+ end
121
+
122
+ it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
123
+ @connection.stub!(
124
+ :select_all => {
125
+ :a => "OTHER SETTINGS",
126
+ :b => "ONLY_FULL_GROUP_BY"
127
+ }
128
+ )
129
+
130
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
131
+ end
132
+
133
+ describe "if not using MySQL" do
134
+ before :each do
135
+ adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
136
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
137
+ pending "No PostgreSQL"
138
+ return
139
+ end
140
+
141
+ @connection = stub(adapter).as_null_object
142
+ @connection.stub!(
143
+ :select_all => true,
144
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
145
+ )
146
+ ::ActiveRecord::Base.stub!(
147
+ :connection => @connection
148
+ )
149
+ end
150
+
151
+ it "should return false" do
152
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
153
+ end
154
+
155
+ it "should not call select_all" do
156
+ @connection.should_not_receive(:select_all)
157
+
158
+ ThinkingSphinx.use_group_by_shortcut?
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,55 @@
1
+ require 'yard'
2
+ require 'jeweler'
3
+
4
+ desc 'Generate documentation'
5
+ YARD::Rake::YardocTask.new do |t|
6
+ # t.title = 'Thinking Sphinx - ActiveRecord Sphinx Plugin'
7
+ end
8
+
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "warp-thinking-sphinx"
11
+ gem.summary = "ActiveRecord/Rails Sphinx library"
12
+ gem.description = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
13
+ gem.author = "Pat Allan"
14
+ gem.email = "pat@freelancing-gods.com"
15
+ gem.homepage = "http://ts.freelancing-gods.com"
16
+
17
+ # s.rubyforge_project = "thinking-sphinx"
18
+ gem.files = FileList[
19
+ "rails/*.rb",
20
+ "lib/**/*.rb",
21
+ "LICENCE",
22
+ "README.textile",
23
+ "tasks/**/*.rb",
24
+ "tasks/**/*.rake",
25
+ "vendor/**/*",
26
+ "VERSION.yml"
27
+ ]
28
+ gem.test_files = FileList[
29
+ "features/**/*",
30
+ "spec/**/*_spec.rb"
31
+ ]
32
+
33
+ gem.add_dependency 'activerecord', '>= 1.15.6'
34
+
35
+ gem.post_install_message = <<-MESSAGE
36
+ With the release of Thinking Sphinx 1.1.18, there is one important change to
37
+ note: previously, the default morphology for indexing was 'stem_en'. The new
38
+ default is nil, to avoid any unexpected behavior. If you wish to keep the old
39
+ value though, you will need to add the following settings to your
40
+ config/sphinx.yml file:
41
+
42
+ development:
43
+ morphology: stem_en
44
+ test:
45
+ morphology: stem_en
46
+ production:
47
+ morphology: stem_en
48
+
49
+ To understand morphologies/stemmers better, visit the following link:
50
+ http://www.sphinxsearch.com/docs/manual-0.9.8.html#conf-morphology
51
+
52
+ MESSAGE
53
+ end
54
+
55
+ Jeweler::GemcutterTasks.new
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '/../lib/thinking_sphinx/tasks')
@@ -0,0 +1,83 @@
1
+ require 'rubygems'
2
+ require 'spec/rake/spectask'
3
+ require 'cucumber/rake/task'
4
+
5
+ desc "Run the specs under spec"
6
+ Spec::Rake::SpecTask.new do |t|
7
+ t.spec_files = FileList['spec/**/*_spec.rb']
8
+ t.spec_opts << "-c"
9
+ end
10
+
11
+ desc "Run all feature-set configurations"
12
+ task :features do |t|
13
+ puts "rake features:mysql"
14
+ system "rake features:mysql"
15
+ puts "rake features:postgresql"
16
+ system "rake features:postgresql"
17
+ end
18
+
19
+ namespace :features do
20
+ def add_task(name, description)
21
+ Cucumber::Rake::Task.new(name, description) do |t|
22
+ t.cucumber_opts = "--format pretty"
23
+ t.profile = name
24
+ end
25
+ end
26
+
27
+ add_task :mysql, "Run feature-set against MySQL"
28
+ add_task :postgresql, "Run feature-set against PostgreSQL"
29
+ end
30
+
31
+ desc "Generate RCov reports"
32
+ Spec::Rake::SpecTask.new(:rcov) do |t|
33
+ t.libs << 'lib'
34
+ t.spec_files = FileList['spec/**/*_spec.rb']
35
+ t.rcov = true
36
+ t.rcov_opts = [
37
+ '--exclude', 'spec',
38
+ '--exclude', 'gems',
39
+ '--exclude', 'riddle',
40
+ '--exclude', 'ruby'
41
+ ]
42
+ end
43
+
44
+ namespace :rcov do
45
+ def add_task(name, description)
46
+ Cucumber::Rake::Task.new(name, description) do |t|
47
+ t.cucumber_opts = "--format pretty"
48
+ t.profile = name
49
+ t.rcov = true
50
+ t.rcov_opts = [
51
+ '--exclude', 'spec',
52
+ '--exclude', 'gems',
53
+ '--exclude', 'riddle',
54
+ '--exclude', 'features'
55
+ ]
56
+ end
57
+ end
58
+
59
+ add_task :mysql, "Run feature-set against MySQL with rcov"
60
+ add_task :postgresql, "Run feature-set against PostgreSQL with rcov"
61
+ end
62
+
63
+ desc "Build cucumber.yml file"
64
+ task :cucumber_defaults do
65
+ default_requires = %w(
66
+ --require features/support/env.rb
67
+ --require features/support/db/mysql.rb
68
+ --require features/support/db/active_record.rb
69
+ --require features/support/post_database.rb
70
+ ).join(" ")
71
+
72
+ step_definitions = FileList["features/step_definitions/**.rb"].collect { |path|
73
+ "--require #{path}"
74
+ }.join(" ")
75
+
76
+ features = FileList["features/*.feature"].join(" ")
77
+
78
+ File.open('cucumber.yml', 'w') { |f|
79
+ f.write "default: \"#{default_requires} #{step_definitions}\"\n\n"
80
+ f.write "mysql: \"#{default_requires} #{step_definitions} #{features}\"\n\n"
81
+ f.write "postgresql: \"#{default_requires.gsub(/mysql/, 'postgresql')} #{step_definitions} #{features}\""
82
+ }
83
+ end