initforthe-thinking-sphinx 1.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +141 -0
  3. data/lib/thinking_sphinx.rb +215 -0
  4. data/lib/thinking_sphinx/active_record.rb +278 -0
  5. data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
  6. data/lib/thinking_sphinx/active_record/delta.rb +87 -0
  7. data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
  8. data/lib/thinking_sphinx/active_record/search.rb +57 -0
  9. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
  10. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
  11. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +135 -0
  12. data/lib/thinking_sphinx/association.rb +164 -0
  13. data/lib/thinking_sphinx/attribute.rb +268 -0
  14. data/lib/thinking_sphinx/class_facet.rb +15 -0
  15. data/lib/thinking_sphinx/collection.rb +148 -0
  16. data/lib/thinking_sphinx/configuration.rb +262 -0
  17. data/lib/thinking_sphinx/core/string.rb +15 -0
  18. data/lib/thinking_sphinx/deltas.rb +30 -0
  19. data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
  20. data/lib/thinking_sphinx/deltas/default_delta.rb +68 -0
  21. data/lib/thinking_sphinx/deltas/delayed_delta.rb +27 -0
  22. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
  23. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
  24. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
  25. data/lib/thinking_sphinx/deploy/capistrano.rb +82 -0
  26. data/lib/thinking_sphinx/facet.rb +108 -0
  27. data/lib/thinking_sphinx/facet_collection.rb +59 -0
  28. data/lib/thinking_sphinx/field.rb +82 -0
  29. data/lib/thinking_sphinx/index.rb +99 -0
  30. data/lib/thinking_sphinx/index/builder.rb +287 -0
  31. data/lib/thinking_sphinx/index/faux_column.rb +110 -0
  32. data/lib/thinking_sphinx/property.rb +160 -0
  33. data/lib/thinking_sphinx/rails_additions.rb +136 -0
  34. data/lib/thinking_sphinx/search.rb +727 -0
  35. data/lib/thinking_sphinx/search/facets.rb +104 -0
  36. data/lib/thinking_sphinx/source.rb +150 -0
  37. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  38. data/lib/thinking_sphinx/source/sql.rb +126 -0
  39. data/lib/thinking_sphinx/tasks.rb +162 -0
  40. data/rails/init.rb +14 -0
  41. data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +136 -0
  42. data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +53 -0
  43. data/spec/unit/thinking_sphinx/active_record/search_spec.rb +107 -0
  44. data/spec/unit/thinking_sphinx/active_record_spec.rb +329 -0
  45. data/spec/unit/thinking_sphinx/association_spec.rb +246 -0
  46. data/spec/unit/thinking_sphinx/attribute_spec.rb +338 -0
  47. data/spec/unit/thinking_sphinx/collection_spec.rb +15 -0
  48. data/spec/unit/thinking_sphinx/configuration_spec.rb +222 -0
  49. data/spec/unit/thinking_sphinx/core/string_spec.rb +9 -0
  50. data/spec/unit/thinking_sphinx/facet_collection_spec.rb +64 -0
  51. data/spec/unit/thinking_sphinx/facet_spec.rb +302 -0
  52. data/spec/unit/thinking_sphinx/field_spec.rb +154 -0
  53. data/spec/unit/thinking_sphinx/index/builder_spec.rb +355 -0
  54. data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +30 -0
  55. data/spec/unit/thinking_sphinx/index_spec.rb +45 -0
  56. data/spec/unit/thinking_sphinx/rails_additions_spec.rb +191 -0
  57. data/spec/unit/thinking_sphinx/search_spec.rb +228 -0
  58. data/spec/unit/thinking_sphinx/source_spec.rb +217 -0
  59. data/spec/unit/thinking_sphinx_spec.rb +151 -0
  60. data/tasks/distribution.rb +67 -0
  61. data/tasks/rails.rake +1 -0
  62. data/tasks/testing.rb +78 -0
  63. data/vendor/after_commit/LICENSE +20 -0
  64. data/vendor/after_commit/README +16 -0
  65. data/vendor/after_commit/Rakefile +22 -0
  66. data/vendor/after_commit/init.rb +8 -0
  67. data/vendor/after_commit/lib/after_commit.rb +45 -0
  68. data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
  69. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
  70. data/vendor/after_commit/test/after_commit_test.rb +53 -0
  71. data/vendor/delayed_job/lib/delayed/job.rb +251 -0
  72. data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
  73. data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
  74. data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
  75. data/vendor/riddle/lib/riddle.rb +30 -0
  76. data/vendor/riddle/lib/riddle/client.rb +619 -0
  77. data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
  78. data/vendor/riddle/lib/riddle/client/message.rb +65 -0
  79. data/vendor/riddle/lib/riddle/client/response.rb +84 -0
  80. data/vendor/riddle/lib/riddle/configuration.rb +33 -0
  81. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
  82. data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
  83. data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
  84. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
  85. data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
  86. data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
  87. data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
  88. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
  89. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
  90. data/vendor/riddle/lib/riddle/controller.rb +44 -0
  91. metadata +190 -0
@@ -0,0 +1,217 @@
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 assign attributes" do
76
+ # 3 internal attributes plus the one requested
77
+ @riddle.sql_attr_uint.length.should == 4
78
+ @riddle.sql_attr_uint.last.should == :internal_id
79
+
80
+ @riddle.sql_attr_timestamp.length.should == 1
81
+ @riddle.sql_attr_timestamp.first.should == :birthday
82
+ end
83
+
84
+ it "should set Sphinx Source options" do
85
+ @riddle.sql_range_step.should == 1000
86
+ @riddle.sql_ranged_throttle.should == 100
87
+ end
88
+
89
+ describe "#sql_query" do
90
+ before :each do
91
+ @query = @riddle.sql_query
92
+ end
93
+
94
+ it "should select data from the model table" do
95
+ @query.should match(/FROM `people`/)
96
+ end
97
+
98
+ it "should select each of the fields" do
99
+ @query.should match(/`first_name`.+FROM/)
100
+ @query.should match(/`last_name`.+FROM/)
101
+ end
102
+
103
+ it "should select each of the attributes" do
104
+ @query.should match(/`id` AS `internal_id`.+FROM/)
105
+ @query.should match(/`birthday`.+FROM/)
106
+ @query.should match(/`tags`.`id`.+ AS `tag_ids`.+FROM/)
107
+ end
108
+
109
+ it "should not match the sourced MVA attribute" do
110
+ @query.should_not match(/contact_ids/)
111
+ end
112
+
113
+ it "should include joins for required associations" do
114
+ @query.should match(/LEFT OUTER JOIN `tags`/)
115
+ end
116
+
117
+ it "should not include joins for the sourced MVA attribute" do
118
+ @query.should_not match(/LEFT OUTER JOIN `contacts`/)
119
+ end
120
+
121
+ it "should include any defined conditions" do
122
+ @query.should match(/WHERE.+`birthday` <= NOW()/)
123
+ end
124
+
125
+ it "should include any defined groupings" do
126
+ @query.should match(/GROUP BY.+`first_name`/)
127
+ end
128
+ end
129
+
130
+ describe "#sql_query_range" do
131
+ before :each do
132
+ @query = @riddle.sql_query_range
133
+ end
134
+
135
+ it "should select data from the model table" do
136
+ @query.should match(/FROM `people`/)
137
+ end
138
+
139
+ it "should select the minimum and the maximum ids" do
140
+ @query.should match(/SELECT.+MIN.+MAX.+FROM/)
141
+ end
142
+ end
143
+
144
+ describe "#sql_query_info" do
145
+ before :each do
146
+ @query = @riddle.sql_query_info
147
+ end
148
+
149
+ it "should select all fields from the model table" do
150
+ @query.should match(/SELECT \* FROM `people`/)
151
+ end
152
+
153
+ it "should filter the primary key with the offset" do
154
+ model_count = ThinkingSphinx.indexed_models.size
155
+ @query.should match(/WHERE `id` = \(\(\$id - 1\) \/ #{model_count}\)/)
156
+ end
157
+ end
158
+
159
+ describe "#sql_query_pre" do
160
+ before :each do
161
+ @queries = @riddle.sql_query_pre
162
+ end
163
+
164
+ it "should default to just the UTF8 statement" do
165
+ @queries.detect { |query|
166
+ query == "SET NAMES utf8"
167
+ }.should_not be_nil
168
+ end
169
+
170
+ it "should set the group_concat_max_len session value for MySQL if requested" do
171
+ @queries.detect { |query|
172
+ query == "SET SESSION group_concat_max_len = 1024"
173
+ }.should_not be_nil
174
+ end
175
+ end
176
+ end
177
+
178
+ describe "#to_riddle_for_core with range disabled" do
179
+ before :each do
180
+ ThinkingSphinx::Field.new(
181
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
182
+ )
183
+ end
184
+
185
+ describe "set per-index" do
186
+ before :each do
187
+ @index.local_options[:disable_range] = true
188
+ @riddle = @source.to_riddle_for_core(1, 0)
189
+ end
190
+
191
+ it "should not have the range in the sql_query" do
192
+ @riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
193
+ @riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
194
+ end
195
+
196
+ it "should not have a sql_query_range" do
197
+ @riddle.sql_query_range.should be_nil
198
+ end
199
+ end
200
+
201
+ describe "set globally" do
202
+ before :each do
203
+ ThinkingSphinx::Configuration.instance.index_options[:disable_range] = true
204
+ @riddle = @source.to_riddle_for_core(1, 0)
205
+ end
206
+
207
+ it "should not have the range in the sql_query" do
208
+ @riddle.sql_query.should_not match(/`people`.`id` >= \$start/)
209
+ @riddle.sql_query.should_not match(/`people`.`id` <= \$end/)
210
+ end
211
+
212
+ it "should not have a sql_query_range" do
213
+ @riddle.sql_query_range.should be_nil
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,151 @@
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_method(: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_method(:sphinx_running_by_pid? => false)
64
+ ThinkingSphinx.sphinx_running?.should be_false
65
+
66
+ ThinkingSphinx.stub_method(:sphinx_running_by_pid? => true)
67
+ ThinkingSphinx.sphinx_running?.should be_true
68
+ end
69
+
70
+ describe "use_group_by_shortcut? method" do
71
+ before :each do
72
+ adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
73
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
74
+ pending "No MySQL"
75
+ return
76
+ end
77
+
78
+ @connection = ::ActiveRecord::ConnectionAdapters.const_get(adapter).stub_instance(
79
+ :select_all => true,
80
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
81
+ )
82
+ ::ActiveRecord::Base.stub_method(
83
+ :connection => @connection
84
+ )
85
+ end
86
+
87
+ it "should return true if no ONLY_FULL_GROUP_BY" do
88
+ @connection.stub_method(
89
+ :select_all => {:a => "OTHER SETTINGS"}
90
+ )
91
+
92
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
93
+ end
94
+
95
+ it "should return true if NULL value" do
96
+ @connection.stub_method(
97
+ :select_all => {:a => nil}
98
+ )
99
+
100
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
101
+ end
102
+
103
+ it "should return false if ONLY_FULL_GROUP_BY is set" do
104
+ @connection.stub_method(
105
+ :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
106
+ )
107
+
108
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
109
+ end
110
+
111
+ it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
112
+ @connection.stub_method(
113
+ :select_all => {
114
+ :a => "OTHER SETTINGS",
115
+ :b => "ONLY_FULL_GROUP_BY"
116
+ }
117
+ )
118
+
119
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
120
+ end
121
+
122
+ describe "if not using MySQL" do
123
+ before :each do
124
+ adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
125
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
126
+ pending "No PostgreSQL"
127
+ return
128
+ end
129
+
130
+ @connection = stub(adapter).as_null_object
131
+ @connection.stub!(
132
+ :select_all => true,
133
+ :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
134
+ )
135
+ ::ActiveRecord::Base.stub_method(
136
+ :connection => @connection
137
+ )
138
+ end
139
+
140
+ it "should return false" do
141
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
142
+ end
143
+
144
+ it "should not call select_all" do
145
+ @connection.should_not_receive(:select_all)
146
+
147
+ ThinkingSphinx.use_group_by_shortcut?
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,67 @@
1
+ require 'rake/rdoctask'
2
+ require 'rake/gempackagetask'
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+ require 'thinking_sphinx'
6
+
7
+ desc 'Generate documentation'
8
+ Rake::RDocTask.new(:rdoc) do |rdoc|
9
+ rdoc.rdoc_dir = 'rdoc'
10
+ rdoc.title = 'Thinking Sphinx - ActiveRecord Sphinx Plugin'
11
+ rdoc.options << '--line-numbers' << '--inline-source'
12
+ rdoc.rdoc_files.include('README')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.name = "thinking-sphinx"
18
+ s.version = ThinkingSphinx::Version::String
19
+ s.summary = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
20
+ s.description = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
21
+ s.author = "Pat Allan"
22
+ s.email = "pat@freelancing-gods.com"
23
+ s.homepage = "http://ts.freelancing-gods.com"
24
+ s.has_rdoc = true
25
+ s.rdoc_options << "--title" << "Thinking Sphinx -- Rails/Merb Sphinx Plugin" <<
26
+ "--line-numbers"
27
+ s.rubyforge_project = "thinking-sphinx"
28
+ s.test_files = FileList["spec/**/*_spec.rb"]
29
+ s.files = FileList[
30
+ "rails/*.rb",
31
+ "lib/**/*.rb",
32
+ "LICENCE",
33
+ "README.textile",
34
+ "tasks/**/*.rb",
35
+ "tasks/**/*.rake",
36
+ "vendor/**/*"
37
+ ]
38
+ s.post_install_message = <<-MESSAGE
39
+ With the release of Thinking Sphinx 1.1.18, there is one important change to
40
+ note: previously, the default morphology for indexing was 'stem_en'. The new
41
+ default is nil, to avoid any unexpected behavior. If you wish to keep the old
42
+ value though, you will need to add the following settings to your
43
+ config/sphinx.yml file:
44
+
45
+ development:
46
+ morphology: stem_en
47
+ test:
48
+ morphology: stem_en
49
+ production:
50
+ morphology: stem_en
51
+
52
+ To understand morphologies/stemmers better, visit the following link:
53
+ http://www.sphinxsearch.com/docs/manual-0.9.8.html#conf-morphology
54
+
55
+ MESSAGE
56
+ end
57
+
58
+ Rake::GemPackageTask.new(spec) do |p|
59
+ p.gem_spec = spec
60
+ p.need_tar = true
61
+ p.need_zip = true
62
+ end
63
+
64
+ desc "Build gemspec file"
65
+ task :build do
66
+ File.open('thinking-sphinx.gemspec', 'w') { |f| f.write spec.to_ruby }
67
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '/../lib/thinking_sphinx/tasks')
@@ -0,0 +1,78 @@
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 = ['--exclude', 'spec', '--exclude', 'gems', '--exclude', 'riddle']
37
+ end
38
+
39
+ namespace :rcov do
40
+ def add_task(name, description)
41
+ Cucumber::Rake::Task.new(name, description) do |t|
42
+ t.cucumber_opts = "--format pretty"
43
+ t.profile = name
44
+ t.rcov = true
45
+ t.rcov_opts = [
46
+ '--exclude', 'spec',
47
+ '--exclude', 'gems',
48
+ '--exclude', 'riddle',
49
+ '--exclude', 'features'
50
+ ]
51
+ end
52
+ end
53
+
54
+ add_task :mysql, "Run feature-set against MySQL with rcov"
55
+ add_task :postgresql, "Run feature-set against PostgreSQL with rcov"
56
+ end
57
+
58
+ desc "Build cucumber.yml file"
59
+ task :cucumber_defaults do
60
+ default_requires = %w(
61
+ --require features/support/env.rb
62
+ --require features/support/db/mysql.rb
63
+ --require features/support/db/active_record.rb
64
+ --require features/support/post_database.rb
65
+ ).join(" ")
66
+
67
+ step_definitions = FileList["features/step_definitions/**.rb"].collect { |path|
68
+ "--require #{path}"
69
+ }.join(" ")
70
+
71
+ features = FileList["features/*.feature"].join(" ")
72
+
73
+ File.open('cucumber.yml', 'w') { |f|
74
+ f.write "default: \"#{default_requires} #{step_definitions}\"\n\n"
75
+ f.write "mysql: \"#{default_requires} #{step_definitions} #{features}\"\n\n"
76
+ f.write "postgresql: \"#{default_requires.gsub(/mysql/, 'postgresql')} #{step_definitions} #{features}\""
77
+ }
78
+ end