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,243 @@
1
+ require '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
+ describe '#initialize' do
10
+ it "should store the current connection details" do
11
+ config = Person.connection.instance_variable_get(:@config)
12
+ @source.database_configuration.should == config
13
+ end
14
+ end
15
+
16
+ it "should generate the name from the model" do
17
+ @source.name.should == "person"
18
+ end
19
+
20
+ it "should handle namespaced models for name generation" do
21
+ index = ThinkingSphinx::Index.new(Admin::Person)
22
+ source = ThinkingSphinx::Source.new(index)
23
+ source.name.should == "admin_person"
24
+ end
25
+
26
+ describe "#to_riddle_for_core" do
27
+ before :each do
28
+ config = ThinkingSphinx::Configuration.instance
29
+ config.source_options[:sql_ranged_throttle] = 100
30
+
31
+ ThinkingSphinx::Field.new(
32
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
33
+ )
34
+ ThinkingSphinx::Field.new(
35
+ @source, ThinkingSphinx::Index::FauxColumn.new(:last_name)
36
+ )
37
+
38
+ ThinkingSphinx::Attribute.new(
39
+ @source, ThinkingSphinx::Index::FauxColumn.new(:id), :as => :internal_id
40
+ )
41
+ ThinkingSphinx::Attribute.new(
42
+ @source, ThinkingSphinx::Index::FauxColumn.new(:birthday)
43
+ )
44
+ ThinkingSphinx::Attribute.new(
45
+ @source, ThinkingSphinx::Index::FauxColumn.new(:tags, :id), :as => :tag_ids
46
+ )
47
+ ThinkingSphinx::Attribute.new(
48
+ @source, ThinkingSphinx::Index::FauxColumn.new(:contacts, :id),
49
+ :as => :contact_ids, :source => :query
50
+ )
51
+
52
+ ThinkingSphinx::Join.new(
53
+ @source, ThinkingSphinx::Index::FauxColumn.new(:links)
54
+ )
55
+
56
+ @source.conditions << "`birthday` <= NOW()"
57
+ @source.groupings << "`first_name`"
58
+
59
+ @index.local_options[:group_concat_max_len] = 1024
60
+
61
+ @riddle = @source.to_riddle_for_core(1, 0)
62
+ end
63
+
64
+ it "should generate a Riddle Source object" do
65
+ @riddle.should be_a_kind_of(Riddle::Configuration::SQLSource)
66
+ end
67
+
68
+ it "should use the index and name its own name" do
69
+ @riddle.name.should == "person_core_0"
70
+ end
71
+
72
+ it "should use the model's database connection to determine type" do
73
+ @riddle.type.should == "mysql"
74
+ end
75
+
76
+ it "should match the model's database settings" do
77
+ config = Person.connection.instance_variable_get(:@config)
78
+ @riddle.sql_db.should == config[:database]
79
+ @riddle.sql_user.should == config[:username]
80
+ @riddle.sql_pass.should == config[:password].to_s
81
+ @riddle.sql_host.should == config[:host]
82
+ @riddle.sql_port.should == config[:port]
83
+ @riddle.sql_sock.should == config[:socket]
84
+ end
85
+
86
+ it "should use a default username of root if nothing else is provided" do
87
+ Person.connection.stub!(:instance_variable_get => {
88
+ :user => nil,
89
+ :username => nil
90
+ })
91
+ @source = ThinkingSphinx::Source.new(@index)
92
+
93
+ riddle = @source.to_riddle_for_core(1, 0)
94
+ riddle.sql_user.should == 'root'
95
+ end
96
+
97
+ it "should assign attributes" do
98
+ # 3 internal attributes plus the one requested
99
+ @riddle.sql_attr_uint.length.should == 4
100
+ @riddle.sql_attr_uint.last.should == :internal_id
101
+
102
+ @riddle.sql_attr_timestamp.length.should == 1
103
+ @riddle.sql_attr_timestamp.first.should == :birthday
104
+ end
105
+
106
+ it "should set Sphinx Source options" do
107
+ @riddle.sql_range_step.should == 1000
108
+ @riddle.sql_ranged_throttle.should == 100
109
+ end
110
+
111
+ describe "#sql_query" do
112
+ before :each do
113
+ @query = @riddle.sql_query
114
+ end
115
+
116
+ it "should select data from the model table" do
117
+ @query.should match(/FROM `people`/)
118
+ end
119
+
120
+ it "should select each of the fields" do
121
+ @query.should match(/`first_name`.+FROM/)
122
+ @query.should match(/`last_name`.+FROM/)
123
+ end
124
+
125
+ it "should select each of the attributes" do
126
+ @query.should match(/`id` AS `internal_id`.+FROM/)
127
+ @query.should match(/`birthday`.+FROM/)
128
+ @query.should match(/`tags`.`id`.+ AS `tag_ids`.+FROM/)
129
+ end
130
+
131
+ it "should not match the sourced MVA attribute" do
132
+ @query.should_not match(/contact_ids/)
133
+ end
134
+
135
+ it "should include joins for required associations" do
136
+ @query.should match(/LEFT OUTER JOIN `tags`/)
137
+ end
138
+
139
+ it "should not include joins for the sourced MVA attribute" do
140
+ @query.should_not match(/LEFT OUTER JOIN `contacts`/)
141
+ end
142
+
143
+ it "should include explicitly requested joins" do
144
+ @query.should match(/LEFT OUTER JOIN `links`/)
145
+ end
146
+
147
+ it "should include any defined conditions" do
148
+ @query.should match(/WHERE.+`birthday` <= NOW()/)
149
+ end
150
+
151
+ it "should include any defined groupings" do
152
+ @query.should match(/GROUP BY.+`first_name`/)
153
+ end
154
+ end
155
+
156
+ describe "#sql_query_range" do
157
+ before :each do
158
+ @query = @riddle.sql_query_range
159
+ end
160
+
161
+ it "should select data from the model table" do
162
+ @query.should match(/FROM `people`/)
163
+ end
164
+
165
+ it "should select the minimum and the maximum ids" do
166
+ @query.should match(/SELECT.+MIN.+MAX.+FROM/)
167
+ end
168
+ end
169
+
170
+ describe "#sql_query_info" do
171
+ before :each do
172
+ @query = @riddle.sql_query_info
173
+ end
174
+
175
+ it "should select all fields from the model table" do
176
+ @query.should match(/SELECT \* FROM `people`/)
177
+ end
178
+
179
+ it "should filter the primary key with the offset" do
180
+ model_count = ThinkingSphinx.context.indexed_models.size
181
+ @query.should match(/WHERE `id` = \(\(\$id - 1\) \/ #{model_count}\)/)
182
+ end
183
+ end
184
+
185
+ describe "#sql_query_pre" do
186
+ before :each do
187
+ @queries = @riddle.sql_query_pre
188
+ end
189
+
190
+ it "should default to just the UTF8 statement" do
191
+ @queries.detect { |query|
192
+ query == "SET NAMES utf8"
193
+ }.should_not be_nil
194
+ end
195
+
196
+ it "should set the group_concat_max_len session value for MySQL if requested" do
197
+ @queries.detect { |query|
198
+ query == "SET SESSION group_concat_max_len = 1024"
199
+ }.should_not be_nil
200
+ end
201
+ end
202
+ end
203
+
204
+ describe "#to_riddle_for_core with range disabled" do
205
+ before :each do
206
+ ThinkingSphinx::Field.new(
207
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
208
+ )
209
+ end
210
+
211
+ describe "set per-index" do
212
+ before :each do
213
+ @index.local_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
+
227
+ describe "set globally" do
228
+ before :each do
229
+ ThinkingSphinx::Configuration.instance.index_options[:disable_range] = true
230
+ @riddle = @source.to_riddle_for_core(1, 0)
231
+ end
232
+
233
+ it "should not have the range in the sql_query" do
234
+ @riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
235
+ @riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
236
+ end
237
+
238
+ it "should not have a sql_query_range" do
239
+ @riddle.sql_query_range.should be_nil
240
+ end
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,204 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThinkingSphinx do
4
+ describe '.context' do
5
+ it "should return a Context instance" do
6
+ ThinkingSphinx.context.should be_a(ThinkingSphinx::Context)
7
+ end
8
+
9
+ it "should remember changes to the Context instance" do
10
+ models = ThinkingSphinx.context.indexed_models
11
+
12
+ ThinkingSphinx.context.indexed_models.replace([:model])
13
+ ThinkingSphinx.context.indexed_models.should == [:model]
14
+
15
+ ThinkingSphinx.context.indexed_models.replace(models)
16
+ end
17
+ end
18
+
19
+ describe '.reset_context!' do
20
+ it "should remove the existing Context instance" do
21
+ existing = ThinkingSphinx.context
22
+
23
+ ThinkingSphinx.reset_context!
24
+ ThinkingSphinx.context.should_not == existing
25
+
26
+ Thread.current[:thinking_sphinx_context] = existing
27
+ end
28
+ end
29
+
30
+ describe '.define_indexes?' do
31
+ it "should define indexes by default" do
32
+ ThinkingSphinx.define_indexes?.should be_true
33
+ end
34
+ end
35
+
36
+ describe '.define_indexes=' do
37
+ it "should disable index definition" do
38
+ ThinkingSphinx.define_indexes = false
39
+ ThinkingSphinx.define_indexes?.should be_false
40
+ end
41
+
42
+ it "should enable index definition" do
43
+ ThinkingSphinx.define_indexes = false
44
+ ThinkingSphinx.define_indexes?.should be_false
45
+ ThinkingSphinx.define_indexes = true
46
+ ThinkingSphinx.define_indexes?.should be_true
47
+ end
48
+ end
49
+
50
+ describe '.deltas_enabled?' do
51
+ it "should index deltas by default" do
52
+ ThinkingSphinx.deltas_enabled = nil
53
+ ThinkingSphinx.deltas_enabled?.should be_true
54
+ end
55
+ end
56
+
57
+ describe '.deltas_enabled=' do
58
+ it "should disable delta indexing" do
59
+ ThinkingSphinx.deltas_enabled = false
60
+ ThinkingSphinx.deltas_enabled?.should be_false
61
+ end
62
+
63
+ it "should enable delta indexing" do
64
+ ThinkingSphinx.deltas_enabled = false
65
+ ThinkingSphinx.deltas_enabled?.should be_false
66
+ ThinkingSphinx.deltas_enabled = true
67
+ ThinkingSphinx.deltas_enabled?.should be_true
68
+ end
69
+ end
70
+
71
+ describe '.updates_enabled?' do
72
+ it "should update indexes by default" do
73
+ ThinkingSphinx.updates_enabled = nil
74
+ ThinkingSphinx.updates_enabled?.should be_true
75
+ end
76
+ end
77
+
78
+ describe '.updates_enabled=' do
79
+ it "should disable index updating" do
80
+ ThinkingSphinx.updates_enabled = false
81
+ ThinkingSphinx.updates_enabled?.should be_false
82
+ end
83
+
84
+ it "should enable index updating" do
85
+ ThinkingSphinx.updates_enabled = false
86
+ ThinkingSphinx.updates_enabled?.should be_false
87
+ ThinkingSphinx.updates_enabled = true
88
+ ThinkingSphinx.updates_enabled?.should be_true
89
+ end
90
+ end
91
+
92
+ describe '.sphinx_running?' do
93
+ it "should always say Sphinx is running if flagged as being on a remote machine" do
94
+ ThinkingSphinx.remote_sphinx = true
95
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
96
+
97
+ ThinkingSphinx.sphinx_running?.should be_true
98
+ end
99
+
100
+ it "should actually pay attention to Sphinx if not on a remote machine" do
101
+ ThinkingSphinx.remote_sphinx = false
102
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
103
+ ThinkingSphinx.sphinx_running?.should be_false
104
+
105
+ ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
106
+ ThinkingSphinx.sphinx_running?.should be_true
107
+ end
108
+ end
109
+
110
+ describe '.version' do
111
+ it "should return the version from the stored YAML file" do
112
+ version = Jeweler::VersionHelper.new(
113
+ File.join(File.dirname(__FILE__), '..')
114
+ ).to_s
115
+
116
+ ThinkingSphinx.version.should == version
117
+ end
118
+ end
119
+
120
+ describe "use_group_by_shortcut? method" do
121
+ before :each do
122
+ adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
123
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
124
+ pending "No MySQL"
125
+ return
126
+ end
127
+
128
+ @connection = stub('adapter',
129
+ :select_all => true,
130
+ :class => ActiveRecord::ConnectionAdapters::MysqlAdapter,
131
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
132
+ )
133
+ ::ActiveRecord::Base.stub!(
134
+ :connection => @connection
135
+ )
136
+
137
+ Thread.current[:thinking_sphinx_use_group_by_shortcut] = nil
138
+ end
139
+
140
+ it "should return true if no ONLY_FULL_GROUP_BY" do
141
+ @connection.stub!(
142
+ :select_all => {:a => "OTHER SETTINGS"}
143
+ )
144
+
145
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
146
+ end
147
+
148
+ it "should return true if NULL value" do
149
+ @connection.stub!(
150
+ :select_all => {:a => nil}
151
+ )
152
+
153
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
154
+ end
155
+
156
+ it "should return false if ONLY_FULL_GROUP_BY is set" do
157
+ @connection.stub!(
158
+ :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
159
+ )
160
+
161
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
162
+ end
163
+
164
+ it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
165
+ @connection.stub!(
166
+ :select_all => {
167
+ :a => "OTHER SETTINGS",
168
+ :b => "ONLY_FULL_GROUP_BY"
169
+ }
170
+ )
171
+
172
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
173
+ end
174
+
175
+ describe "if not using MySQL" do
176
+ before :each do
177
+ adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
178
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
179
+ pending "No PostgreSQL"
180
+ return
181
+ end
182
+
183
+ @connection = stub(adapter).as_null_object
184
+ @connection.stub!(
185
+ :select_all => true,
186
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
187
+ )
188
+ ::ActiveRecord::Base.stub!(
189
+ :connection => @connection
190
+ )
191
+ end
192
+
193
+ it "should return false" do
194
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
195
+ end
196
+
197
+ it "should not call select_all" do
198
+ @connection.should_not_receive(:select_all)
199
+
200
+ ThinkingSphinx.use_group_by_shortcut?
201
+ end
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,46 @@
1
+ require 'yard'
2
+ require 'jeweler'
3
+
4
+ desc 'Generate documentation'
5
+ YARD::Rake::YardocTask.new
6
+
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "thinking-sphinx"
9
+ gem.summary = "ActiveRecord/Rails Sphinx library"
10
+ gem.description = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
11
+ gem.author = "Pat Allan"
12
+ gem.email = "pat@freelancing-gods.com"
13
+ gem.homepage = "http://ts.freelancing-gods.com"
14
+
15
+ # s.rubyforge_project = "thinking-sphinx"
16
+ gem.files = FileList[
17
+ "rails/*.rb",
18
+ "lib/**/*.rb",
19
+ "LICENCE",
20
+ "README.textile",
21
+ "tasks/**/*.rb",
22
+ "tasks/**/*.rake",
23
+ "VERSION"
24
+ ]
25
+ gem.test_files = FileList[
26
+ "features/**/*",
27
+ "spec/**/*_spec.rb"
28
+ ]
29
+
30
+ gem.add_dependency 'activerecord', '>= 1.15.6'
31
+ gem.add_dependency 'riddle', '>= 1.0.10'
32
+ gem.add_dependency 'after_commit', '>= 1.0.6'
33
+
34
+ gem.add_development_dependency "yard", ">= 0"
35
+ gem.add_development_dependency "rspec", ">= 1.2.9"
36
+ gem.add_development_dependency "cucumber", ">= 0"
37
+ gem.add_development_dependency "will_paginate", "2.3.11"
38
+ gem.add_development_dependency "ginger", "1.2.0"
39
+ gem.add_development_dependency "faker", "0.3.1"
40
+
41
+ gem.post_install_message = <<-MESSAGE
42
+ If you're upgrading, you should read this:
43
+ http://freelancing-god.github.com/ts/en/upgrading.html
44
+
45
+ MESSAGE
46
+ end