Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 211 lines (167 sloc) 6.527 kb
cb15709 James Tucker Rakefiles are executables, and rake loads rake, not rakefile code
raggi authored
1 #!/usr/bin/env rake
db045db David Heinemeier Hansson Initial
dhh authored
2 require 'rake/testtask'
3 require 'rake/packagetask'
4 require 'rake/gempackagetask'
39814fc Jeremy Kemper Merge branch 'ar-test-cleanup' of git://git.geeksomnia.com/rails
jeremy authored
5
6 require File.expand_path(File.dirname(__FILE__)) + "/test/config"
db045db David Heinemeier Hansson Initial
dhh authored
7
f386676 Steven Soroka Use the rails user when creating and dropping the database rather than f...
ssoroka authored
8 MYSQL_DB_USER = 'rails'
9
c10396b Jeffrey Hardy When running multiple test tasks, don't abort early if one produces fail...
packagethief authored
10 def run_without_aborting(*tasks)
11 errors = []
12
13 tasks.each do |task|
14 begin
15 Rake::Task[task].invoke
16 rescue Exception
17 errors << task
18 end
19 end
20
21 abort "Errors running #{errors.join(', ')}" if errors.any?
22 end
db045db David Heinemeier Hansson Initial
dhh authored
23
21e81da Brian Lopez update tests for mysql2 support
brianmario authored
24 desc 'Run mysql, mysql2, sqlite, and postgresql tests by default'
bfe85ae Jeremy Kemper Add explicit test task
jeremy authored
25 task :default => :test
db045db David Heinemeier Hansson Initial
dhh authored
26
21e81da Brian Lopez update tests for mysql2 support
brianmario authored
27 desc 'Run mysql, mysql2, sqlite, and postgresql tests'
c10396b Jeffrey Hardy When running multiple test tasks, don't abort early if one produces fail...
packagethief authored
28 task :test do
29 tasks = defined?(JRUBY_VERSION) ?
30 %w(test_jdbcmysql test_jdbcsqlite3 test_jdbcpostgresql) :
21e81da Brian Lopez update tests for mysql2 support
brianmario authored
31 %w(test_mysql test_mysql2 test_sqlite3 test_postgresql)
c10396b Jeffrey Hardy When running multiple test tasks, don't abort early if one produces fail...
packagethief authored
32 run_without_aborting(*tasks)
33 end
34
bbb3e5a Jeremy Kemper Unify test:isolated across components and run by default at toplevel
jeremy authored
35 namespace :test do
36 task :isolated do
37 tasks = defined?(JRUBY_VERSION) ?
38 %w(isolated_test_jdbcmysql isolated_test_jdbcsqlite3 isolated_test_jdbcpostgresql) :
21e81da Brian Lopez update tests for mysql2 support
brianmario authored
39 %w(isolated_test_mysql isolated_test_mysql2 isolated_test_sqlite3 isolated_test_postgresql)
bbb3e5a Jeremy Kemper Unify test:isolated across components and run by default at toplevel
jeremy authored
40 run_without_aborting(*tasks)
41 end
c10396b Jeffrey Hardy When running multiple test tasks, don't abort early if one produces fail...
packagethief authored
42 end
db045db David Heinemeier Hansson Initial
dhh authored
43
c47c541 Jon Leighton Have a separate test connection directory for sqlite3 in-memory so that ...
jonleighton authored
44 %w( mysql mysql2 postgresql sqlite3 sqlite3_mem firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
04c7e82 David Heinemeier Hansson Made ready for the release of 0.11.1
dhh authored
45 Rake::TestTask.new("test_#{adapter}") { |t|
fa5da8a Jeremy Kemper isolated_test task
jeremy authored
46 connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}"
21e81da Brian Lopez update tests for mysql2 support
brianmario authored
47 adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
fa5da8a Jeremy Kemper isolated_test task
jeremy authored
48 t.libs << "test" << connection_path
5e2b473 Aaron Patterson reorganizing adapter specific tests. [#4974 state:resolved]
tenderlove authored
49 t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject {
50 |x| x =~ /\/adapters\//
51 } + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")).sort
52
04c7e82 David Heinemeier Hansson Made ready for the release of 0.11.1
dhh authored
53 t.verbose = true
f46dc9b Aaron Patterson clear the rest of the warnings, run with warnings turned on [#4332 state...
tenderlove authored
54 t.warning = true
04c7e82 David Heinemeier Hansson Made ready for the release of 0.11.1
dhh authored
55 }
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
56
fa5da8a Jeremy Kemper isolated_test task
jeremy authored
57 task "isolated_test_#{adapter}" do
58 connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}"
21e81da Brian Lopez update tests for mysql2 support
brianmario authored
59 adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/]
fa5da8a Jeremy Kemper isolated_test task
jeremy authored
60 puts [adapter, adapter_short, connection_path].inspect
61 ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
ab96c71 Santiago Pastorino Add this rule to run common tests and specifics ones from adapters dir
spastorino authored
62 (Dir["test/cases/**/*_test.rb"].reject {
63 |x| x =~ /\/adapters\//
64 } + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file|
9a57a22 Santiago Pastorino sorry, the CI cannot lie to us anymore (Part II)
spastorino authored
65 sh(ruby, "-Ilib:test:#{connection_path}", file)
fa5da8a Jeremy Kemper isolated_test task
jeremy authored
66 end or raise "Failures"
67 end
68
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
69 namespace adapter do
70 task :test => "test_#{adapter}"
fa5da8a Jeremy Kemper isolated_test task
jeremy authored
71 task :isolated_test => "isolated_test_#{adapter}"
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
72 end
04c7e82 David Heinemeier Hansson Made ready for the release of 0.11.1
dhh authored
73 end
336c2cb David Heinemeier Hansson Added an Oracle adapter that works with the Oracle bindings by Yoshida (...
dhh authored
74
2947197 Aaron Patterson use rake to create test databases for us
tenderlove authored
75 rule '.sqlite3' do |t|
76 sh %Q{sqlite3 "#{t.name}" "create table a (a integer); drop table a;"}
77 end
78
79 task :test_sqlite3 => [
80 'test/fixtures/fixture_database.sqlite3',
81 'test/fixtures/fixture_database_2.sqlite3'
82 ]
83
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
84 namespace :mysql do
85 desc 'Build the MySQL test databases'
86 task :build_databases do
3f49456 Greg Hazel remove use of echo [#4410 state:resolved]
ghazel authored
87 %x( mysql --user=#{MYSQL_DB_USER} -e "create DATABASE activerecord_unittest DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
88 %x( mysql --user=#{MYSQL_DB_USER} -e "create DATABASE activerecord_unittest2 DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
89 end
90
91 desc 'Drop the MySQL test databases'
92 task :drop_databases do
f386676 Steven Soroka Use the rails user when creating and dropping the database rather than f...
ssoroka authored
93 %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest )
94 %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest2 )
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
95 end
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test dat...
Marcel Molina authored
96
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
97 desc 'Rebuild the MySQL test databases'
98 task :rebuild_databases => [:drop_databases, :build_databases]
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test dat...
Marcel Molina authored
99 end
100
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
101 task :build_mysql_databases => 'mysql:build_databases'
102 task :drop_mysql_databases => 'mysql:drop_databases'
5d3e724 Jeremy Kemper Add build/drop/rebuild tasks for SQL Server. Closes #9588 [lawrence]
jeremy authored
103 task :rebuild_mysql_databases => 'mysql:rebuild_databases'
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test dat...
Marcel Molina authored
104
105
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
106 namespace :postgresql do
107 desc 'Build the PostgreSQL test databases'
108 task :build_databases do
76335c2 Jeremy Kemper Bump pg gem requirement to 0.8.0. Build psql db with UTF8 encoding.
jeremy authored
109 %x( createdb -E UTF8 activerecord_unittest )
110 %x( createdb -E UTF8 activerecord_unittest2 )
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
111 end
112
113 desc 'Drop the PostgreSQL test databases'
114 task :drop_databases do
921752c Michael Koziarski Remove reference to 'postgres' user in the connection and Rakefiles. Al...
NZKoz authored
115 %x( dropdb activerecord_unittest )
116 %x( dropdb activerecord_unittest2 )
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
117 end
118
119 desc 'Rebuild the PostgreSQL test databases'
120 task :rebuild_databases => [:drop_databases, :build_databases]
f18463f Add tasks to create, drop and rebuild the MySQL and PostgreSQL test dat...
Marcel Molina authored
121 end
122
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
123 task :build_postgresql_databases => 'postgresql:build_databases'
124 task :drop_postgresql_databases => 'postgresql:drop_databases'
5d3e724 Jeremy Kemper Add build/drop/rebuild tasks for SQL Server. Closes #9588 [lawrence]
jeremy authored
125 task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
10d458b David Heinemeier Hansson Added a OCI8-based Oracle adapter that has been verified to work with Or...
dhh authored
126
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adapter...
Marcel Molina authored
127
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
128 namespace :frontbase do
129 desc 'Build the FrontBase test databases'
130 task :build_databases => :rebuild_frontbase_databases
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adapter...
Marcel Molina authored
131
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
132 desc 'Rebuild the FrontBase test databases'
133 task :rebuild_databases do
134 build_frontbase_database = Proc.new do |db_name, sql_definition_file|
135 %(
136 STOP DATABASE #{db_name};
137 DELETE DATABASE #{db_name};
138 CREATE DATABASE #{db_name};
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adapter...
Marcel Molina authored
139
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
140 CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM;
141 SET COMMIT FALSE;
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adapter...
Marcel Molina authored
142
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
143 CREATE USER RAILS;
144 CREATE SCHEMA RAILS AUTHORIZATION RAILS;
145 COMMIT;
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adapter...
Marcel Molina authored
146
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
147 SET SESSION AUTHORIZATION RAILS;
148 SCRIPT '#{sql_definition_file}';
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adapter...
Marcel Molina authored
149
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
150 COMMIT;
151
152 DISCONNECT ALL;
153 )
154 end
39814fc Jeremy Kemper Merge branch 'ar-test-cleanup' of git://git.geeksomnia.com/rails
jeremy authored
155 create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_ROOT, 'frontbase.sql')]
156 create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_ROOT, 'frontbase2.sql')]
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
157 execute_frontbase_sql = Proc.new do |sql|
158 system(<<-SHELL)
159 /Library/FrontBase/bin/sql92 <<-SQL
160 #{sql}
161 SQL
162 SHELL
163 end
164 execute_frontbase_sql[create_activerecord_unittest]
165 execute_frontbase_sql[create_activerecord_unittest2]
b2c0ddf Add support for FrontBase (http://www.frontbase.com/) with a new adapter...
Marcel Molina authored
166 end
167 end
168
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
169 task :build_frontbase_databases => 'frontbase:build_databases'
170 task :rebuild_frontbase_databases => 'frontbase:rebuild_databases'
171
f430d6b Joshua Peek Make gemspecs the authoritative source instead of generating them from t...
josh authored
172 spec = eval(File.read('activerecord.gemspec'))
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
173
db045db David Heinemeier Hansson Initial
dhh authored
174 Rake::GemPackageTask.new(spec) do |p|
175 p.gem_spec = spec
176 end
177
e0a2dab David Heinemeier Hansson Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
178 task :lines do
179 lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
180
181 for file_name in FileList["lib/active_record/**/*.rb"]
182 next if file_name =~ /vendor/
183 f = File.open(file_name)
184
185 while line = f.gets
186 lines += 1
187 next if line =~ /^\s*$/
188 next if line =~ /^\s*#/
189 codelines += 1
190 end
191 puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
192
e0a2dab David Heinemeier Hansson Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
193 total_lines += lines
194 total_codelines += codelines
346d36b Jeremy Kemper Namespace the internal Rakefile tasks. Closes #8850 [drnic]
jeremy authored
195
e0a2dab David Heinemeier Hansson Added KLOC counter for AR and AP. Combined theyre at ~9KLOC
dhh authored
196 lines, codelines = 0, 0
197 end
198
199 puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
200 end
201
db045db David Heinemeier Hansson Initial
dhh authored
202
065cb2a David Heinemeier Hansson Made ready for better release automation
dhh authored
203 # Publishing ------------------------------------------------------
db045db David Heinemeier Hansson Initial
dhh authored
204
c1785f3 Jeremy Kemper Release using gemcutter gem:push tasks
jeremy authored
205 desc "Release to gemcutter"
459ecaf Jeremy Kemper Submarine the rake-gemcutter dep in Rakefiles
jeremy authored
206 task :release => :package do
207 require 'rake/gemcutter'
208 Rake::Gemcutter::Tasks.new(spec).define
209 Rake::Task['gem:push'].invoke
210 end
Something went wrong with that request. Please try again.