public
Rubygem
Fork of mislav/will_paginate
Description: Most awesome pagination solution for Rails
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/chriseppstein/will_paginate.git
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
mislav (author)
Mon Jan 28 18:33:36 -0800 2008
commit  843bf7c164378da3d07059256fa07530862c5ae1
tree    161df6f458d99074cbec8a817c8859aaa2ae4927
parent  e321a367b8dd111c57b573e247e50321324f9414
...
11
12
13
 
 
 
 
 
 
 
 
 
 
 
14
15
 
16
17
18
 
19
20
21
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25
26
...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
26
27
28
 
29
30
31
32
33
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
0
@@ -11,16 +11,43 @@ Rake::TestTask.new(:test) do |t|
0
   t.verbose = true
0
 end
0
 
0
+# I want to specify environment variables at call time
0
+class EnvTestTask < Rake::TestTask
0
+ attr_accessor :env
0
+
0
+ def ruby(*args)
0
+ env.each { |key, value| ENV[key] = value } if env
0
+ super
0
+ env.keys.each { |key| ENV.delete key } if env
0
+ end
0
+end
0
+
0
 for configuration in %w( sqlite3 mysql postgres )
0
- Rake::TestTask.new("test_#{configuration}") do |t|
0
+ EnvTestTask.new("test_#{configuration}") do |t|
0
     t.pattern = 'test/finder_test.rb'
0
     t.verbose = true
0
- t.options = "-- -#{configuration}"
0
+ t.env = { 'DB' => configuration }
0
   end
0
 end
0
 
0
 task :test_databases => %w(test_mysql test_sqlite3 test_postgres)
0
-task :test_all => %w(test test_mysql test_postgres)
0
+
0
+desc %{Test everything on SQLite3, MySQL and PostgreSQL}
0
+task :test_full => %w(test test_mysql test_postgres)
0
+
0
+desc %{Test everything with Rails 1.2.x and 2.0.x gems}
0
+task :test_all do
0
+ all = Rake::Task['test_full']
0
+ ENV['RAILS_VERSION'] = '~>1.2.6'
0
+ all.invoke
0
+ # reset the invoked flag
0
+ %w( test_full test test_mysql test_postgres ).each do |name|
0
+ Rake::Task[name].instance_variable_set '@already_invoked', false
0
+ end
0
+ # do it again
0
+ ENV['RAILS_VERSION'] = '~>2.0.2'
0
+ all.invoke
0
+end
0
 
0
 desc 'Generate RDoc documentation for the will_paginate plugin.'
0
 Rake::RDocTask.new(:rdoc) do |rdoc|
...
27
28
29
30
31
32
33
34
35
 
36
37
38
39
40
41
42
 
43
44
45
...
27
28
29
 
 
 
 
 
 
30
31
32
33
34
35
36
 
37
38
39
40
0
@@ -27,19 +27,14 @@ class ActiveRecordTestConnector
0
   private
0
 
0
   def self.setup_connection
0
- arg = ARGV.last
0
- if arg.index('-') == 0
0
- db = arg.sub('-', '').downcase
0
- else
0
- db, arg = 'sqlite3', nil
0
- end
0
+ db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
0
     
0
     configurations = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'database.yml'))
0
     raise "no configuration for '#{db}'" unless configurations.key? db
0
     configuration = configurations[db]
0
     
0
     ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
0
- puts "using #{configuration['adapter']} adapter" if arg
0
+ puts "using #{configuration['adapter']} adapter" unless ENV['DB'].blank?
0
     
0
     ActiveRecord::Base.establish_connection(configuration)
0
     ActiveRecord::Base.configurations = { db => configuration }

Comments

    No one has commented yet.