Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (100 sloc) 3.568 kB
c48b82a @mperham Project cleaning
mperham authored
1 require 'fileutils'
2 include FileUtils::Verbose
3
d96ecb9 @mperham Move to Jeweler
mperham authored
4 require 'rake/testtask'
5 Rake::TestTask.new do |t|
6 t.verbose = true
c48b82a @mperham Project cleaning
mperham authored
7 t.libs << 'test'
d96ecb9 @mperham Move to Jeweler
mperham authored
8 t.test_files = FileList['test/*_test.rb']
9 end
10
11 task :clean do
c48b82a @mperham Project cleaning
mperham authored
12 rm_f Dir['*.gem']
13 rm_f Dir['test/*.db']
14 rm_rf 'coverage'
a483ec7 @mperham Add tasks to help with RubyForge gem publishing
mperham authored
15
c48b82a @mperham Project cleaning
mperham authored
16 puts `cd example23 ; rake app:clean`
a483ec7 @mperham Add tasks to help with RubyForge gem publishing
mperham authored
17 end
18
d96ecb9 @mperham Move to Jeweler
mperham authored
19 task :default => :test
651e6af @mperham Prepare for release
mperham authored
20 task :test => [:pretest]
21
7d7a2ac @mperham Refactor DataFabric to support ActiveRecord 2.0, 2.1 and 2.2.
mperham authored
22 desc "Test all versions of ActiveRecord installed locally"
23 task :test_all do
24 Gem.source_index.search(Gem::Dependency.new('activerecord', '>=2.0')).each do |spec|
25 puts `rake test AR_VERSION=#{spec.version}`
26 end
27 end
28
9b899f1 @mperham Add note and check for allow_concurrency = true.
mperham authored
29 task :pretest do
651b8b1 @mperham Fix Echoe configuration which locked onto RubyGems 1.2.
mperham authored
30 setup(false)
be84520 @mperham Move gem building to Echoe
mperham authored
31 end
32
33 task :create_db do
651b8b1 @mperham Fix Echoe configuration which locked onto RubyGems 1.2.
mperham authored
34 setup(true)
be84520 @mperham Move gem building to Echoe
mperham authored
35 end
36
1d1957d @FooBarWidget The 'create_db' Rake task will now use the connection details in test…
FooBarWidget authored
37 def load_database_yml
38 filename = "test/database.yml"
39 if !File.exist?(filename)
40 STDERR.puts "\n*** ERROR ***:\n" <<
41 "You must have a 'test/database.yml' file in order to create the test database. " <<
64b7cc9 @mperham Support testing in sqlite by default, rather than forcing the user
mperham authored
42 "An example is provided in 'test/database.yml.mysql'.\n\n"
1d1957d @FooBarWidget The 'create_db' Rake task will now use the connection details in test…
FooBarWidget authored
43 exit 1
44 end
45 YAML::load(ERB.new(IO.read(filename)).result)
46 end
47
9b899f1 @mperham Add note and check for allow_concurrency = true.
mperham authored
48 def setup_connection
6d8780b @mperham Update to fix minor issues on Rails 3.0. Dropping support for Rails …
mperham authored
49 require 'erb'
50 require 'logger'
13d819f @mperham Seems to be working somewhat, huzzah!
mperham authored
51 require 'active_record'
1d1957d @FooBarWidget The 'create_db' Rake task will now use the connection details in test…
FooBarWidget authored
52 ActiveRecord::Base.configurations = load_database_yml
53 ActiveRecord::Base.logger = Logger.new(STDOUT)
651e6af @mperham Prepare for release
mperham authored
54 ActiveRecord::Base.logger.level = Logger::INFO
9b899f1 @mperham Add note and check for allow_concurrency = true.
mperham authored
55 end
13d819f @mperham Seems to be working somewhat, huzzah!
mperham authored
56
1d1957d @FooBarWidget The 'create_db' Rake task will now use the connection details in test…
FooBarWidget authored
57 def using_connection(database_identifier, &block)
64b7cc9 @mperham Support testing in sqlite by default, rather than forcing the user
mperham authored
58 ActiveRecord::Base.establish_connection(database_identifier)
753158f @mperham More work on documenting testing and setup
mperham authored
59 ActiveRecord::Base.connection.instance_eval(&block)
9b899f1 @mperham Add note and check for allow_concurrency = true.
mperham authored
60 end
61
be84520 @mperham Move gem building to Echoe
mperham authored
62 def setup(create = false)
753158f @mperham More work on documenting testing and setup
mperham authored
63 setup_connection
1d1957d @FooBarWidget The 'create_db' Rake task will now use the connection details in test…
FooBarWidget authored
64
65 ActiveRecord::Base.configurations.each_pair do |identifier, config|
66 using_connection(identifier) do
64b7cc9 @mperham Support testing in sqlite by default, rather than forcing the user
mperham authored
67 send("create_#{config['adapter']}", create, config['database'])
753158f @mperham More work on documenting testing and setup
mperham authored
68 end
13d819f @mperham Seems to be working somewhat, huzzah!
mperham authored
69 end
70 end
64b7cc9 @mperham Support testing in sqlite by default, rather than forcing the user
mperham authored
71
72 def create_sqlite3(create, db_name)
73 execute "drop table if exists the_whole_burritos"
74 execute "drop table if exists enchiladas"
75 execute "create table enchiladas (id integer not null primary key, name varchar(30) not null)"
76 execute "insert into enchiladas (id, name) values (1, '#{db_name}')"
77 execute "create table the_whole_burritos (id integer not null primary key, name varchar(30) not null)"
78 execute "insert into the_whole_burritos (id, name) values (1, '#{db_name}')"
79 end
80
81 def create_mysql(create, db_name)
82 if create
83 execute "drop database if exists #{db_name}"
84 execute "create database #{db_name}"
85 end
86 execute "use #{db_name}"
87 execute "drop table if exists the_whole_burritos"
88 execute "drop table if exists enchiladas"
89 execute "create table enchiladas (id integer not null auto_increment, name varchar(30) not null, primary key(id))"
90 execute "insert into enchiladas (id, name) values (1, '#{db_name}')"
91 execute "create table the_whole_burritos (id integer not null auto_increment, name varchar(30) not null, primary key(id))"
92 execute "insert into the_whole_burritos (id, name) values (1, '#{db_name}')"
93 end
b2db526 @mperham Add test coverage via rcov
mperham authored
94
95 # Test coverage
96 begin
b37c12c @ss Changed rcov dependency to gemcutter.
ss authored
97 gem 'rcov' rescue nil
b2db526 @mperham Add test coverage via rcov
mperham authored
98 require 'rcov/rcovtask'
99
28881eb @mperham Add 'cover_all' task to generate coverage for all installed AR versions.
mperham authored
100 desc "Generate coverage numbers for all locally installed versions of ActiveRecord"
101 task :cover_all do
102 Gem.source_index.search(Gem::Dependency.new('activerecord', '>=2.0')).each do |spec|
103 puts `rake cover AR_VERSION=#{spec.version}`
104 end
105 end
106
107 task :cover => [:pretest, :rcov_impl]
b2db526 @mperham Add test coverage via rcov
mperham authored
108
28881eb @mperham Add 'cover_all' task to generate coverage for all installed AR versions.
mperham authored
109 Rcov::RcovTask.new('rcov_impl') do |t|
b2db526 @mperham Add test coverage via rcov
mperham authored
110 t.libs << "test"
111 t.test_files = FileList["test/*_test.rb"]
28881eb @mperham Add 'cover_all' task to generate coverage for all installed AR versions.
mperham authored
112 t.output_dir = "coverage/#{ENV['AR_VERSION']}"
b2db526 @mperham Add test coverage via rcov
mperham authored
113 t.verbose = true
114 t.rcov_opts = ['--text-report', '--exclude', "test,Library,#{ENV['GEM_HOME']}", '--sort', 'coverage']
115 end
28881eb @mperham Add 'cover_all' task to generate coverage for all installed AR versions.
mperham authored
116 rescue LoadError => e
4ce6108 @mperham Clean up Rakefile, dependencies and tests with latest gems, best prac…
mperham authored
117 puts 'Test coverage support requires \'gem install rcov\''
b2db526 @mperham Add test coverage via rcov
mperham authored
118 end
Something went wrong with that request. Please try again.