Permalink
Browse files

Use DB and RAILS_VERSION environment variables in tests. Provide test…

…_full

and test_all Rake tasks that set up these variables and run the test suite
with all the variations.


git-svn-id: svn://errtheblog.com/svn/plugins/will_paginate@443 1eaa51fe-a21a-0410-9c2e-ae7a00a434c4
  • Loading branch information...
1 parent e321a36 commit 843bf7c164378da3d07059256fa07530862c5ae1 mislav committed Jan 29, 2008
Showing with 32 additions and 10 deletions.
  1. +30 −3 Rakefile
  2. +2 −7 test/lib/activerecord_test_connector.rb
View
@@ -11,16 +11,43 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end
+# I want to specify environment variables at call time
+class EnvTestTask < Rake::TestTask
+ attr_accessor :env
+
+ def ruby(*args)
+ env.each { |key, value| ENV[key] = value } if env
+ super
+ env.keys.each { |key| ENV.delete key } if env
+ end
+end
+
for configuration in %w( sqlite3 mysql postgres )
- Rake::TestTask.new("test_#{configuration}") do |t|
+ EnvTestTask.new("test_#{configuration}") do |t|
t.pattern = 'test/finder_test.rb'
t.verbose = true
- t.options = "-- -#{configuration}"
+ t.env = { 'DB' => configuration }
end
end
task :test_databases => %w(test_mysql test_sqlite3 test_postgres)
-task :test_all => %w(test test_mysql test_postgres)
+
+desc %{Test everything on SQLite3, MySQL and PostgreSQL}
+task :test_full => %w(test test_mysql test_postgres)
+
+desc %{Test everything with Rails 1.2.x and 2.0.x gems}
+task :test_all do
+ all = Rake::Task['test_full']
+ ENV['RAILS_VERSION'] = '~>1.2.6'
+ all.invoke
+ # reset the invoked flag
+ %w( test_full test test_mysql test_postgres ).each do |name|
+ Rake::Task[name].instance_variable_set '@already_invoked', false
+ end
+ # do it again
+ ENV['RAILS_VERSION'] = '~>2.0.2'
+ all.invoke
+end
desc 'Generate RDoc documentation for the will_paginate plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -27,19 +27,14 @@ def self.setup
private
def self.setup_connection
- arg = ARGV.last
- if arg.index('-') == 0
- db = arg.sub('-', '').downcase
- else
- db, arg = 'sqlite3', nil
- end
+ db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
configurations = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'database.yml'))
raise "no configuration for '#{db}'" unless configurations.key? db
configuration = configurations[db]
ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
- puts "using #{configuration['adapter']} adapter" if arg
+ puts "using #{configuration['adapter']} adapter" unless ENV['DB'].blank?
ActiveRecord::Base.establish_connection(configuration)
ActiveRecord::Base.configurations = { db => configuration }

0 comments on commit 843bf7c

Please sign in to comment.