thinking-sphinx 1.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +157 -0
  3. data/VERSION.yml +4 -0
  4. data/lib/thinking_sphinx.rb +211 -0
  5. data/lib/thinking_sphinx/active_record.rb +307 -0
  6. data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
  7. data/lib/thinking_sphinx/active_record/delta.rb +87 -0
  8. data/lib/thinking_sphinx/active_record/has_many_association.rb +28 -0
  9. data/lib/thinking_sphinx/active_record/scopes.rb +39 -0
  10. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
  11. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
  12. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +136 -0
  13. data/lib/thinking_sphinx/association.rb +164 -0
  14. data/lib/thinking_sphinx/attribute.rb +342 -0
  15. data/lib/thinking_sphinx/class_facet.rb +15 -0
  16. data/lib/thinking_sphinx/configuration.rb +282 -0
  17. data/lib/thinking_sphinx/core/array.rb +7 -0
  18. data/lib/thinking_sphinx/core/string.rb +15 -0
  19. data/lib/thinking_sphinx/deltas.rb +30 -0
  20. data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
  21. data/lib/thinking_sphinx/deltas/default_delta.rb +68 -0
  22. data/lib/thinking_sphinx/deltas/delayed_delta.rb +30 -0
  23. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
  24. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
  25. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
  26. data/lib/thinking_sphinx/deploy/capistrano.rb +100 -0
  27. data/lib/thinking_sphinx/excerpter.rb +22 -0
  28. data/lib/thinking_sphinx/facet.rb +125 -0
  29. data/lib/thinking_sphinx/facet_search.rb +134 -0
  30. data/lib/thinking_sphinx/field.rb +82 -0
  31. data/lib/thinking_sphinx/index.rb +99 -0
  32. data/lib/thinking_sphinx/index/builder.rb +286 -0
  33. data/lib/thinking_sphinx/index/faux_column.rb +110 -0
  34. data/lib/thinking_sphinx/property.rb +162 -0
  35. data/lib/thinking_sphinx/rails_additions.rb +150 -0
  36. data/lib/thinking_sphinx/search.rb +707 -0
  37. data/lib/thinking_sphinx/search_methods.rb +421 -0
  38. data/lib/thinking_sphinx/source.rb +150 -0
  39. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  40. data/lib/thinking_sphinx/source/sql.rb +128 -0
  41. data/lib/thinking_sphinx/tasks.rb +165 -0
  42. data/rails/init.rb +14 -0
  43. data/spec/lib/thinking_sphinx/active_record/delta_spec.rb +130 -0
  44. data/spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb +49 -0
  45. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +96 -0
  46. data/spec/lib/thinking_sphinx/active_record_spec.rb +364 -0
  47. data/spec/lib/thinking_sphinx/association_spec.rb +239 -0
  48. data/spec/lib/thinking_sphinx/attribute_spec.rb +500 -0
  49. data/spec/lib/thinking_sphinx/configuration_spec.rb +268 -0
  50. data/spec/lib/thinking_sphinx/core/array_spec.rb +9 -0
  51. data/spec/lib/thinking_sphinx/core/string_spec.rb +9 -0
  52. data/spec/lib/thinking_sphinx/excerpter_spec.rb +49 -0
  53. data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
  54. data/spec/lib/thinking_sphinx/facet_spec.rb +333 -0
  55. data/spec/lib/thinking_sphinx/field_spec.rb +154 -0
  56. data/spec/lib/thinking_sphinx/index/builder_spec.rb +455 -0
  57. data/spec/lib/thinking_sphinx/index/faux_column_spec.rb +30 -0
  58. data/spec/lib/thinking_sphinx/index_spec.rb +45 -0
  59. data/spec/lib/thinking_sphinx/rails_additions_spec.rb +203 -0
  60. data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
  61. data/spec/lib/thinking_sphinx/search_spec.rb +1092 -0
  62. data/spec/lib/thinking_sphinx/source_spec.rb +227 -0
  63. data/spec/lib/thinking_sphinx_spec.rb +162 -0
  64. data/tasks/distribution.rb +50 -0
  65. data/tasks/rails.rake +1 -0
  66. data/tasks/testing.rb +83 -0
  67. data/vendor/after_commit/LICENSE +20 -0
  68. data/vendor/after_commit/README +16 -0
  69. data/vendor/after_commit/Rakefile +22 -0
  70. data/vendor/after_commit/init.rb +8 -0
  71. data/vendor/after_commit/lib/after_commit.rb +45 -0
  72. data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
  73. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
  74. data/vendor/after_commit/test/after_commit_test.rb +53 -0
  75. data/vendor/delayed_job/lib/delayed/job.rb +251 -0
  76. data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
  77. data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
  78. data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
  79. data/vendor/riddle/lib/riddle.rb +30 -0
  80. data/vendor/riddle/lib/riddle/client.rb +635 -0
  81. data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
  82. data/vendor/riddle/lib/riddle/client/message.rb +66 -0
  83. data/vendor/riddle/lib/riddle/client/response.rb +84 -0
  84. data/vendor/riddle/lib/riddle/configuration.rb +33 -0
  85. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
  86. data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
  87. data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
  88. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
  89. data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
  90. data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
  91. data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
  92. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
  93. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
  94. data/vendor/riddle/lib/riddle/controller.rb +53 -0
  95. metadata +172 -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,50 @@
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 = "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["spec/**/*_spec.rb"]
29
+
30
+ gem.add_dependency 'activerecord', '>= 1.15.6'
31
+
32
+ gem.post_install_message = <<-MESSAGE
33
+ With the release of Thinking Sphinx 1.1.18, there is one important change to
34
+ note: previously, the default morphology for indexing was 'stem_en'. The new
35
+ default is nil, to avoid any unexpected behavior. If you wish to keep the old
36
+ value though, you will need to add the following settings to your
37
+ config/sphinx.yml file:
38
+
39
+ development:
40
+ morphology: stem_en
41
+ test:
42
+ morphology: stem_en
43
+ production:
44
+ morphology: stem_en
45
+
46
+ To understand morphologies/stemmers better, visit the following link:
47
+ http://www.sphinxsearch.com/docs/manual-0.9.8.html#conf-morphology
48
+
49
+ MESSAGE
50
+ end
data/tasks/rails.rake ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '/../lib/thinking_sphinx/tasks')
data/tasks/testing.rb ADDED
@@ -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