diff --git a/.gitignore b/.gitignore index 5f8525c..233f6fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ activerecord-2.3.5.gem activerecord-2.3.8.gem /activerecord-2.3.8.gem +/activerecord-3.0.3.gem +/activerecord-tests.tgz diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..c2d63cd --- /dev/null +++ b/Rakefile @@ -0,0 +1,201 @@ +require 'rake' +require 'rake/testtask' +require 'rake/packagetask' +require 'rake/gempackagetask' + +require File.expand_path(File.dirname(__FILE__)) + "/test/config" + +MYSQL_DB_USER = 'rails' + +def run_without_aborting(*tasks) + errors = [] + + tasks.each do |task| + begin + Rake::Task[task].invoke + rescue Exception + errors << task + end + end + + abort "Errors running #{errors.join(', ')}" if errors.any? +end + +desc 'Run mysql, mysql2, sqlite, and postgresql tests by default' +task :default => :test + +desc 'Run mysql, mysql2, sqlite, and postgresql tests' +task :test do + tasks = defined?(JRUBY_VERSION) ? + %w(test_jdbcmysql test_jdbcsqlite3 test_jdbcpostgresql) : + %w(test_mysql test_mysql2 test_sqlite3 test_postgresql) + run_without_aborting(*tasks) +end + +namespace :test do + task :isolated do + tasks = defined?(JRUBY_VERSION) ? + %w(isolated_test_jdbcmysql isolated_test_jdbcsqlite3 isolated_test_jdbcpostgresql) : + %w(isolated_test_mysql isolated_test_mysql2 isolated_test_sqlite3 isolated_test_postgresql) + run_without_aborting(*tasks) + end +end + +%w( mysql mysql2 postgresql sqlite3 firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter| + Rake::TestTask.new("test_#{adapter}") { |t| + connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}" + adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] + t.libs << "test" << connection_path + t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject { + |x| x =~ /\/adapters\// + } + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")).sort + + t.verbose = true + t.warning = true + } + + task "isolated_test_#{adapter}" do + connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}" + adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] + puts [adapter, adapter_short, connection_path].inspect + ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) + (Dir["test/cases/**/*_test.rb"].reject { + |x| x =~ /\/adapters\// + } + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file| + system(ruby, "-Ilib:test:#{connection_path}", file) + end or raise "Failures" + end + + namespace adapter do + task :test => "test_#{adapter}" + task :isolated_test => "isolated_test_#{adapter}" + end +end + +namespace :mysql do + desc 'Build the MySQL test databases' + task :build_databases do + %x( echo "create DATABASE activerecord_unittest DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{MYSQL_DB_USER}) + %x( echo "create DATABASE activerecord_unittest2 DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{MYSQL_DB_USER}) + end + + desc 'Drop the MySQL test databases' + task :drop_databases do + %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest ) + %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest2 ) + end + + desc 'Rebuild the MySQL test databases' + task :rebuild_databases => [:drop_databases, :build_databases] +end + +task :build_mysql_databases => 'mysql:build_databases' +task :drop_mysql_databases => 'mysql:drop_databases' +task :rebuild_mysql_databases => 'mysql:rebuild_databases' + + +namespace :postgresql do + desc 'Build the PostgreSQL test databases' + task :build_databases do + %x( createdb -E UTF8 activerecord_unittest ) + %x( createdb -E UTF8 activerecord_unittest2 ) + end + + desc 'Drop the PostgreSQL test databases' + task :drop_databases do + %x( dropdb activerecord_unittest ) + %x( dropdb activerecord_unittest2 ) + end + + desc 'Rebuild the PostgreSQL test databases' + task :rebuild_databases => [:drop_databases, :build_databases] +end + +task :build_postgresql_databases => 'postgresql:build_databases' +task :drop_postgresql_databases => 'postgresql:drop_databases' +task :rebuild_postgresql_databases => 'postgresql:rebuild_databases' + + +namespace :frontbase do + desc 'Build the FrontBase test databases' + task :build_databases => :rebuild_frontbase_databases + + desc 'Rebuild the FrontBase test databases' + task :rebuild_databases do + build_frontbase_database = Proc.new do |db_name, sql_definition_file| + %( + STOP DATABASE #{db_name}; + DELETE DATABASE #{db_name}; + CREATE DATABASE #{db_name}; + + CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM; + SET COMMIT FALSE; + + CREATE USER RAILS; + CREATE SCHEMA RAILS AUTHORIZATION RAILS; + COMMIT; + + SET SESSION AUTHORIZATION RAILS; + SCRIPT '#{sql_definition_file}'; + + COMMIT; + + DISCONNECT ALL; + ) + end + create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_ROOT, 'frontbase.sql')] + create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_ROOT, 'frontbase2.sql')] + execute_frontbase_sql = Proc.new do |sql| + system(<<-SHELL) + /Library/FrontBase/bin/sql92 <<-SQL + #{sql} + SQL + SHELL + end + execute_frontbase_sql[create_activerecord_unittest] + execute_frontbase_sql[create_activerecord_unittest2] + end +end + +task :build_frontbase_databases => 'frontbase:build_databases' +task :rebuild_frontbase_databases => 'frontbase:rebuild_databases' + +spec = eval(File.read('activerecord.gemspec')) + +Rake::GemPackageTask.new(spec) do |p| + p.gem_spec = spec +end + +task :lines do + lines, codelines, total_lines, total_codelines = 0, 0, 0, 0 + + for file_name in FileList["lib/active_record/**/*.rb"] + next if file_name =~ /vendor/ + f = File.open(file_name) + + while line = f.gets + lines += 1 + next if line =~ /^\s*$/ + next if line =~ /^\s*#/ + codelines += 1 + end + puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}" + + total_lines += lines + total_codelines += codelines + + lines, codelines = 0, 0 + end + + puts "Total: Lines #{total_lines}, LOC #{total_codelines}" +end + + +# Publishing ------------------------------------------------------ + +desc "Release to gemcutter" +task :release => :package do + require 'rake/gemcutter' + Rake::Gemcutter::Tasks.new(spec).define + Rake::Task['gem:push'].invoke +end diff --git a/activerecord-2.3.8-postgres-fix.patch b/activerecord-2.3.8-postgres-fix.patch deleted file mode 100644 index 3dbaee2..0000000 --- a/activerecord-2.3.8-postgres-fix.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- activerecord-2.3.8/lib/active_record/connection_adapters/postgresql_adapter.rb.orig 2010-09-08 13:41:46.000000000 -0400 -+++ activerecord-2.3.8/lib/active_record/connection_adapters/postgresql_adapter.rb 2010-09-08 13:42:39.000000000 -0400 -@@ -407,6 +407,9 @@ module ActiveRecord - - # Quotes column names for use in SQL queries. - def quote_column_name(name) #:nodoc: -+ unless PGconn.respond_to?(:quote_ident) -+ raise 'Your PostgreSQL connection does not support quote_ident. Try upgrading pg.' -+ end - PGconn.quote_ident(name.to_s) - end - diff --git a/activerecord-2.3.8-sqlite3-compat.patch b/activerecord-2.3.8-sqlite3-compat.patch deleted file mode 100644 index 3ac2c9d..0000000 --- a/activerecord-2.3.8-sqlite3-compat.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- activerecord-2.3.8/test/cases/query_cache_test.rb.orig 2010-06-29 14:39:50.000000000 -0400 -+++ activerecord-2.3.8/test/cases/query_cache_test.rb 2010-06-29 14:39:57.000000000 -0400 -@@ -52,7 +52,7 @@ class QueryCacheTest < ActiveRecord::Tes - require 'sqlite3/version' if current_adapter?(:SQLite3Adapter) - - Task.cache do -- if current_adapter?(:SQLite3Adapter) && SQLite3::Version::VERSION > '1.2.5' -+ if current_adapter?(:SQLite3Adapter) && defined?(SQLite3::Version::VERSION) && SQLite3::Version::VERSION > '1.2.5' - assert_instance_of Fixnum, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") - else - assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") diff --git a/activerecord-3.0.3-postgres-fix.patch b/activerecord-3.0.3-postgres-fix.patch new file mode 100644 index 0000000..a911e12 --- /dev/null +++ b/activerecord-3.0.3-postgres-fix.patch @@ -0,0 +1,12 @@ +--- lib/active_record/connection_adapters/postgresql_adapter.rb.orig 2011-01-18 00:45:58.997405001 -0500 ++++ lib/active_record/connection_adapters/postgresql_adapter.rb 2011-01-18 00:47:17.553405015 -0500 +@@ -362,6 +362,9 @@ module ActiveRecord + + # Quotes column names for use in SQL queries. + def quote_column_name(name) #:nodoc: ++ unless PGconn.respond_to?(:quote_ident) ++ raise 'Your PostgreSQL connection does not support quote_ident. Try upgrading pg.' ++ end + PGconn.quote_ident(name.to_s) + end + diff --git a/activerecord-3.0.3-sqlite3-compat.patch b/activerecord-3.0.3-sqlite3-compat.patch new file mode 100644 index 0000000..0410820 --- /dev/null +++ b/activerecord-3.0.3-sqlite3-compat.patch @@ -0,0 +1,11 @@ +--- test/cases/query_cache_test.rb.orig 2011-01-18 00:43:16.443404999 -0500 ++++ test/cases/query_cache_test.rb 2011-01-18 00:51:08.929405005 -0500 +@@ -57,7 +57,7 @@ class QueryCacheTest < ActiveRecord::Tes + # Oracle adapter returns count() as Fixnum or Float + if current_adapter?(:OracleAdapter) + assert_kind_of Numeric, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") +- elsif current_adapter?(:SQLite3Adapter) && SQLite3::Version::VERSION > '1.2.5' or current_adapter?(:Mysql2Adapter) ++ elsif current_adapter?(:SQLite3Adapter) && defined?(SQLite3::Version::VERSION) && SQLite3::Version::VERSION > '1.2.5' or current_adapter?(:Mysql2Adapter) + # Future versions of the sqlite3 adapter will return numeric + assert_instance_of Fixnum, + Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") diff --git a/activerecord-rakefile-fix.patch b/activerecord-rakefile-fix.patch new file mode 100644 index 0000000..a74481b --- /dev/null +++ b/activerecord-rakefile-fix.patch @@ -0,0 +1,15 @@ +--- Rakefile.orig 2011-01-10 20:41:24.492457355 -0500 ++++ Rakefile 2011-01-10 20:41:27.112458000 -0500 +@@ -160,12 +160,6 @@ end + task :build_frontbase_databases => 'frontbase:build_databases' + task :rebuild_frontbase_databases => 'frontbase:rebuild_databases' + +-spec = eval(File.read('activerecord.gemspec')) +- +-Rake::GemPackageTask.new(spec) do |p| +- p.gem_spec = spec +-end +- + task :lines do + lines, codelines, total_lines, total_codelines = 0, 0, 0, 0 + diff --git a/activerecord-tests-fix.patch b/activerecord-tests-fix.patch new file mode 100644 index 0000000..38cb39d --- /dev/null +++ b/activerecord-tests-fix.patch @@ -0,0 +1,8 @@ +--- test/cases/helper.rb.orig 2011-01-10 21:00:27.597458002 -0500 ++++ test/cases/helper.rb 2011-01-10 21:00:34.439458125 -0500 +@@ -1,4 +1,4 @@ +-require File.expand_path('../../../../load_paths', __FILE__) ++require 'rubygems' + + lib = File.expand_path("#{File.dirname(__FILE__)}/../../lib") + $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) diff --git a/rubygem-activerecord.spec b/rubygem-activerecord.spec index e493fb3..c13c7ec 100644 --- a/rubygem-activerecord.spec +++ b/rubygem-activerecord.spec @@ -1,5 +1,4 @@ # Generated from activerecord-1.15.5.gem by gem2rpm -*- rpm-spec -*- -%define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']") %define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null) %define gemname activerecord %define geminstdir %{gemdir}/gems/%{gemname}-%{version} @@ -9,28 +8,54 @@ Summary: Implements the ActiveRecord pattern for ORM Name: rubygem-%{gemname} Epoch: 1 -Version: 2.3.8 -Release: 4%{?dist} +Version: 3.0.3 +Release: 1%{?dist} Group: Development/Languages License: MIT URL: http://www.rubyonrails.org -Source0: http://gems.rubyforge.org/gems/%{gemname}-%{version}.gem +Source0: http://rubygems.org/downloads/activerecord-%{version}.gem + +# The activerecord gem doesn't ship with the upstream Rakefile +Source1: http://github.com/rails/rails/raw/v%{version}/%{gemname}/Rakefile + +# Also the activerecord gem doesn't ship with the test suite. +# You may check it out like so +# git clone http://github.com/rails/rails.git +# cd rails/activerecord/ +# git checkout v3.0.3 +# tar czvf activerecord-tests.tgz test/ +Source2: activerecord-tests.tgz + +# Remove a task which breaks the Rakefile due to the gemspec +# not being present in the gem +Patch0: activerecord-rakefile-fix.patch + +# Removes code which breaks the test suite due to a +# dependency on a file in the greater rails proj +Patch1: activerecord-tests-fix.patch # patch0 needed to make ar tests compatable w/ current sqlite3 version in fedora -Patch0: activerecord-2.3.8-sqlite3-compat.patch +Patch2: activerecord-3.0.3-sqlite3-compat.patch # patch1 https://rails.lighthouseapp.com/projects/8994/tickets/3210-rails-postgres-issue -Patch1: activerecord-2.3.8-postgres-fix.patch +Patch3: activerecord-3.0.3-postgres-fix.patch -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires: ruby(abi) = %{rubyabi} Requires: rubygems Requires: rubygem(activesupport) = %{version} +Requires: rubygem(activemodel) = %{version} +Requires: rubygem(arel) +Requires: rubygem(tzinfo) >= 0.3.23 +Requires: rubygem(i18n) BuildRequires: rubygems -BuildRequires(check): rubygem(rake) -BuildRequires(check): rubygem(activesupport) = %{version} -BuildRequires(check): rubygem(sqlite3-ruby) -BuildRequires(check): rubygem(mocha) +BuildRequires: rubygem(rake) +BuildRequires: rubygem(activesupport) = %{version} +BuildRequires: rubygem(activemodel) = %{version} +BuildRequires: rubygem(sqlite3) +BuildRequires: rubygem(mocha) +BuildRequires: rubygem(i18n) +BuildRequires: rubygem(arel) +BuildRequires: rubygem(tzinfo) >= 0.3.23 BuildArch: noarch Provides: rubygem(%{gemname}) = %{version} @@ -50,9 +75,17 @@ mkdir -p ./%{gemdir} gem install --local --install-dir ./%{gemdir} \ --force --rdoc %{SOURCE0} +# move the Rakefile in place +cp %{SOURCE1} .%{geminstdir} + +# move the tests into place +tar xzvf %{SOURCE2} -C .%{geminstdir} + pushd ./%{geminstdir} -%patch0 -p1 -%patch1 -p1 +%patch0 -p0 +%patch1 -p0 +%patch2 -p0 +%patch3 -p0 popd # Remove backup files @@ -80,7 +113,6 @@ chmod 0644 ./%{geminstdir}/examples/performance.rb %build %install -rm -rf %{buildroot} mkdir -p %{buildroot}%{gemdir} cp -a .%{gemdir}/* %{buildroot}%{gemdir} @@ -88,8 +120,13 @@ cp -a .%{gemdir}/* %{buildroot}%{gemdir} rm -rf %{buildroot} %check -# Only test sqlite3 backend pushd .%{geminstdir} + +# to prevent a circular dependency w/ actionpack +mv test/cases/session_store/session_test.rb \ + test/cases/session_store/session_test.rb.norun + +# Only test sqlite3 backend rake test_sqlite3 --trace %files @@ -97,11 +134,9 @@ rake test_sqlite3 --trace %dir %{geminstdir} %doc %{geminstdir}/CHANGELOG %doc %{geminstdir}/examples -%{geminstdir}/install.rb %{geminstdir}/lib %{geminstdir}/Rakefile -%doc %{geminstdir}/README -%doc %{geminstdir}/RUNNING_UNIT_TESTS +%doc %{geminstdir}/README.rdoc %{geminstdir}/test %doc %{gemdir}/doc/%{gemname}-%{version} @@ -109,6 +144,9 @@ rake test_sqlite3 --trace %{gemdir}/specifications/%{gemname}-%{version}.gemspec %changelog +* Mon Jan 10 2011 Mohammed Morsi - 1:3.0.3-1 +- Update to rails 3 + * Wed Sep 08 2010 Mohammed Morsi - 1:2.3.8-4 - Updated postgres fix to resolve security issue diff --git a/sources b/sources index 4244fa6..3a4b92c 100644 --- a/sources +++ b/sources @@ -1 +1,2 @@ -16311c40a988bd9f8ffeb44799d9f488 activerecord-2.3.8.gem +4dfaec6d511ad50ede13092f1abadff0 activerecord-3.0.3.gem +40716267a33a5e0b1acd577f16073fca activerecord-tests.tgz