Skip to content
Newer
Older
100644 229 lines (184 sloc) 7.24 KB
db045db @dhh Initial
dhh authored
1 require 'rake/testtask'
2 require 'rake/packagetask'
79e9a29 @vijaydev fixes Rake::GemPackageTask deprecation warnings from rake 0.9.0
vijaydev authored
3 require 'rubygems/package_task'
39814fc @jeremy Merge branch 'ar-test-cleanup' of git://git.geeksomnia.com/rails
jeremy authored
4
5 require File.expand_path(File.dirname(__FILE__)) + "/test/config"
499dec0 @jonleighton Make sure that the build/drop database rake tasks take account of the…
jonleighton authored
6 require File.expand_path(File.dirname(__FILE__)) + "/test/support/config"
f386676 @ssoroka Use the rails user when creating and dropping the database rather tha…
ssoroka authored
7
c10396b @packagethief When running multiple test tasks, don't abort early if one produces f…
packagethief authored
8 def run_without_aborting(*tasks)
9 errors = []
10
11 tasks.each do |task|
12 begin
13 Rake::Task[task].invoke
14 rescue Exception
15 errors << task
16 end
17 end
18
19 abort "Errors running #{errors.join(', ')}" if errors.any?
20 end
db045db @dhh Initial
dhh authored
21
21e81da @brianmario update tests for mysql2 support
brianmario authored
22 desc 'Run mysql, mysql2, sqlite, and postgresql tests by default'
bfe85ae @jeremy Add explicit test task
jeremy authored
23 task :default => :test
db045db @dhh Initial
dhh authored
24
21e81da @brianmario update tests for mysql2 support
brianmario authored
25 desc 'Run mysql, mysql2, sqlite, and postgresql tests'
c10396b @packagethief When running multiple test tasks, don't abort early if one produces f…
packagethief authored
26 task :test do
27 tasks = defined?(JRUBY_VERSION) ?
28 %w(test_jdbcmysql test_jdbcsqlite3 test_jdbcpostgresql) :
21e81da @brianmario update tests for mysql2 support
brianmario authored
29 %w(test_mysql test_mysql2 test_sqlite3 test_postgresql)
c10396b @packagethief When running multiple test tasks, don't abort early if one produces f…
packagethief authored
30 run_without_aborting(*tasks)
31 end
32
bbb3e5a @jeremy Unify test:isolated across components and run by default at toplevel
jeremy authored
33 namespace :test do
34 task :isolated do
35 tasks = defined?(JRUBY_VERSION) ?
36 %w(isolated_test_jdbcmysql isolated_test_jdbcsqlite3 isolated_test_jdbcpostgresql) :
21e81da @brianmario update tests for mysql2 support
brianmario authored
37 %w(isolated_test_mysql isolated_test_mysql2 isolated_test_sqlite3 isolated_test_postgresql)
bbb3e5a @jeremy Unify test:isolated across components and run by default at toplevel
jeremy authored
38 run_without_aborting(*tasks)
39 end
c10396b @packagethief When running multiple test tasks, don't abort early if one produces f…
packagethief authored
40 end
db045db @dhh Initial
dhh authored
41
c47c541 @jonleighton Have a separate test connection directory for sqlite3 in-memory so th…
jonleighton authored
42 %w( mysql mysql2 postgresql sqlite3 sqlite3_mem firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
04c7e82 @dhh Made ready for the release of 0.11.1
dhh authored
43 Rake::TestTask.new("test_#{adapter}") { |t|
21e81da @brianmario update tests for mysql2 support
brianmario authored
44 adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
c8d124c @tenderlove add test to the include path
tenderlove authored
45 t.libs << 'test'
5e2b473 @tenderlove reorganizing adapter specific tests. [#4974 state:resolved]
tenderlove authored
46 t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject {
47 |x| x =~ /\/adapters\//
48 } + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")).sort
49
f46dc9b @tenderlove clear the rest of the warnings, run with warnings turned on [#4332 st…
tenderlove authored
50 t.warning = true
bfb84cf @arunagw Verbose output for tests.
arunagw authored
51 t.verbose = true
04c7e82 @dhh Made ready for the release of 0.11.1
dhh authored
52 }
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
53
fa5da8a @jeremy isolated_test task
jeremy authored
54 task "isolated_test_#{adapter}" do
21e81da @brianmario update tests for mysql2 support
brianmario authored
55 adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
253bb6b @jonleighton Refactor Active Record test connection setup. Please see the RUNNING_…
jonleighton authored
56 puts [adapter, adapter_short].inspect
fa5da8a @jeremy isolated_test task
jeremy authored
57 ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
ab96c71 @spastorino Add this rule to run common tests and specifics ones from adapters dir
spastorino authored
58 (Dir["test/cases/**/*_test.rb"].reject {
59 |x| x =~ /\/adapters\//
60 } + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file|
80451a1 @tenderlove make sure AR isolated tests set the environment variable
tenderlove authored
61 sh(ruby, "-Itest", file)
fa5da8a @jeremy isolated_test task
jeremy authored
62 end or raise "Failures"
63 end
64
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
65 namespace adapter do
66 task :test => "test_#{adapter}"
fa5da8a @jeremy isolated_test task
jeremy authored
67 task :isolated_test => "isolated_test_#{adapter}"
8392f10 @tenderlove set the environment variable from the rake file
tenderlove authored
68
69 # Set the connection environment for the adapter
cd27cd5 @tenderlove oops! add parens so the block is properly bound
tenderlove authored
70 task(:env) { ENV['ARCONN'] = adapter }
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
71 end
8392f10 @tenderlove set the environment variable from the rake file
tenderlove authored
72
73 # Make sure the adapter test evaluates the env setting task
74 task "test_#{adapter}" => "#{adapter}:env"
80451a1 @tenderlove make sure AR isolated tests set the environment variable
tenderlove authored
75 task "isolated_test_#{adapter}" => "#{adapter}:env"
04c7e82 @dhh Made ready for the release of 0.11.1
dhh authored
76 end
336c2cb @dhh Added an Oracle adapter that works with the Oracle bindings by Yoshida (
dhh authored
77
2947197 @tenderlove use rake to create test databases for us
tenderlove authored
78 rule '.sqlite3' do |t|
79 sh %Q{sqlite3 "#{t.name}" "create table a (a integer); drop table a;"}
80 end
81
82 task :test_sqlite3 => [
83 'test/fixtures/fixture_database.sqlite3',
84 'test/fixtures/fixture_database_2.sqlite3'
85 ]
86
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
87 namespace :mysql do
88 desc 'Build the MySQL test databases'
89 task :build_databases do
499dec0 @jonleighton Make sure that the build/drop database rake tasks take account of the…
jonleighton authored
90 config = ARTest.config['connections']['mysql']
91 %x( mysql --user=#{config['arunit']['username']} -e "create DATABASE #{config['arunit']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
92 %x( mysql --user=#{config['arunit2']['username']} -e "create DATABASE #{config['arunit2']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
93 end
94
95 desc 'Drop the MySQL test databases'
96 task :drop_databases do
499dec0 @jonleighton Make sure that the build/drop database rake tasks take account of the…
jonleighton authored
97 config = ARTest.config['connections']['mysql']
98 %x( mysqladmin --user=#{config['arunit']['username']} -f drop #{config['arunit']['database']} )
99 %x( mysqladmin --user=#{config['arunit2']['username']} -f drop #{config['arunit2']['database']} )
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
100 end
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test d…
Marcel Molina authored
101
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
102 desc 'Rebuild the MySQL test databases'
103 task :rebuild_databases => [:drop_databases, :build_databases]
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test d…
Marcel Molina authored
104 end
105
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
106 task :build_mysql_databases => 'mysql:build_databases'
107 task :drop_mysql_databases => 'mysql:drop_databases'
5d3e724 @jeremy Add build/drop/rebuild tasks for SQL Server. Closes #9588 [lawrence]
jeremy authored
108 task :rebuild_mysql_databases => 'mysql:rebuild_databases'
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test d…
Marcel Molina authored
109
110
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
111 namespace :postgresql do
112 desc 'Build the PostgreSQL test databases'
113 task :build_databases do
499dec0 @jonleighton Make sure that the build/drop database rake tasks take account of the…
jonleighton authored
114 config = ARTest.config['connections']['postgresql']
bd77fff @bobbywilson0 use template0 option for creating activerecord test databases in post…
bobbywilson0 authored
115 %x( createdb -E UTF8 -T template0 #{config['arunit']['database']} )
116 %x( createdb -E UTF8 -T template0 #{config['arunit2']['database']} )
34492af @kennyj Create hstore extension when building PostgreSQL databases.
kennyj authored
117
118 # prepare hstore
119 version = %x( createdb --version ).strip.gsub(/(.*)(\d\.\d\.\d)$/, "\\2")
120 %w(arunit arunit2).each do |db|
121 if version < "9.1.0"
122 puts "Please prepare hstore data type. See http://www.postgresql.org/docs/9.0/static/hstore.html"
123 else
124 %x( psql #{config[db]['database']} -c "CREATE EXTENSION hstore;" )
125 end
126 end
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
127 end
128
129 desc 'Drop the PostgreSQL test databases'
130 task :drop_databases do
499dec0 @jonleighton Make sure that the build/drop database rake tasks take account of the…
jonleighton authored
131 config = ARTest.config['connections']['postgresql']
132 %x( dropdb #{config['arunit']['database']} )
133 %x( dropdb #{config['arunit2']['database']} )
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
134 end
135
136 desc 'Rebuild the PostgreSQL test databases'
137 task :rebuild_databases => [:drop_databases, :build_databases]
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test d…
Marcel Molina authored
138 end
139
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
140 task :build_postgresql_databases => 'postgresql:build_databases'
141 task :drop_postgresql_databases => 'postgresql:drop_databases'
5d3e724 @jeremy Add build/drop/rebuild tasks for SQL Server. Closes #9588 [lawrence]
jeremy authored
142 task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
10d458b @dhh Added a OCI8-based Oracle adapter that has been verified to work with…
dhh authored
143
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adap…
Marcel Molina authored
144
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
145 namespace :frontbase do
146 desc 'Build the FrontBase test databases'
147 task :build_databases => :rebuild_frontbase_databases
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adap…
Marcel Molina authored
148
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
149 desc 'Rebuild the FrontBase test databases'
150 task :rebuild_databases do
151 build_frontbase_database = Proc.new do |db_name, sql_definition_file|
152 %(
153 STOP DATABASE #{db_name};
154 DELETE DATABASE #{db_name};
155 CREATE DATABASE #{db_name};
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adap…
Marcel Molina authored
156
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
157 CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM;
158 SET COMMIT FALSE;
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adap…
Marcel Molina authored
159
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
160 CREATE USER RAILS;
161 CREATE SCHEMA RAILS AUTHORIZATION RAILS;
162 COMMIT;
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adap…
Marcel Molina authored
163
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
164 SET SESSION AUTHORIZATION RAILS;
165 SCRIPT '#{sql_definition_file}';
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adap…
Marcel Molina authored
166
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
167 COMMIT;
168
169 DISCONNECT ALL;
170 )
171 end
499dec0 @jonleighton Make sure that the build/drop database rake tasks take account of the…
jonleighton authored
172 config = ARTest.config['connections']['frontbase']
173 create_activerecord_unittest = build_frontbase_database[config['arunit']['database'], File.join(SCHEMA_ROOT, 'frontbase.sql')]
174 create_activerecord_unittest2 = build_frontbase_database[config['arunit2']['database'], File.join(SCHEMA_ROOT, 'frontbase2.sql')]
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
175 execute_frontbase_sql = Proc.new do |sql|
176 system(<<-SHELL)
177 /Library/FrontBase/bin/sql92 <<-SQL
178 #{sql}
179 SQL
180 SHELL
181 end
182 execute_frontbase_sql[create_activerecord_unittest]
183 execute_frontbase_sql[create_activerecord_unittest2]
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adap…
Marcel Molina authored
184 end
185 end
186
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
187 task :build_frontbase_databases => 'frontbase:build_databases'
188 task :rebuild_frontbase_databases => 'frontbase:rebuild_databases'
189
f430d6b @josh Make gemspecs the authoritative source instead of generating them fro…
josh authored
190 spec = eval(File.read('activerecord.gemspec'))
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
191
79e9a29 @vijaydev fixes Rake::GemPackageTask deprecation warnings from rake 0.9.0
vijaydev authored
192 Gem::PackageTask.new(spec) do |p|
db045db @dhh Initial
dhh authored
193 p.gem_spec = spec
194 end
195
e0a2dab @dhh Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
196 task :lines do
197 lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
198
b31eac5 @ndbroadbent Replaced all 'for' loops with Enumerable#each
ndbroadbent authored
199 FileList["lib/active_record/**/*.rb"].each do |file_name|
e0a2dab @dhh Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
200 next if file_name =~ /vendor/
bf928bc @ndbroadbent Use block form of 'File.open' so that File object is auto closed at end
ndbroadbent authored
201 File.open(file_name, 'r') do |f|
202 while line = f.gets
203 lines += 1
204 next if line =~ /^\s*$/
205 next if line =~ /^\s*#/
206 codelines += 1
207 end
e0a2dab @dhh Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
208 end
209 puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
210
e0a2dab @dhh Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
211 total_lines += lines
212 total_codelines += codelines
346d36b @jeremy Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
213
e0a2dab @dhh Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
214 lines, codelines = 0, 0
215 end
216
217 puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
218 end
219
db045db @dhh Initial
dhh authored
220
065cb2a @dhh Made ready for better release automation
dhh authored
221 # Publishing ------------------------------------------------------
db045db @dhh Initial
dhh authored
222
c1785f3 @jeremy Release using gemcutter gem:push tasks
jeremy authored
223 desc "Release to gemcutter"
459ecaf @jeremy Submarine the rake-gemcutter dep in Rakefiles
jeremy authored
224 task :release => :package do
225 require 'rake/gemcutter'
226 Rake::Gemcutter::Tasks.new(spec).define
227 Rake::Task['gem:push'].invoke
228 end
Something went wrong with that request. Please try again.