From a722b480008c0609c08e20d4286dd1c1af00823c Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 12 May 2007 00:44:50 +0000 Subject: Ensure copy table test runs for sqlite and sqlite3. [mislav] Cllosoes #8328 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6721 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/Rakefile | 9 ++-- activerecord/test/copy_table_sqlite.rb | 64 ---------------------------- activerecord/test/copy_table_test_sqlite.rb | 65 +++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 70 deletions(-) delete mode 100644 activerecord/test/copy_table_sqlite.rb create mode 100644 activerecord/test/copy_table_test_sqlite.rb diff --git a/activerecord/Rakefile b/activerecord/Rakefile index f68457b7db..7c9e2fcc44 100755 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -30,11 +30,8 @@ task :default => [ :test_mysql, :test_sqlite, :test_sqlite3, :test_postgresql ] for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oracle sybase openbase frontbase ) Rake::TestTask.new("test_#{adapter}") { |t| t.libs << "test" << "test/connections/native_#{adapter}" - if adapter =~ /^sqlserver/ - t.pattern = "test/**/*_test{,_sqlserver}.rb" - else - t.pattern = "test/**/*_test{,_#{adapter}}.rb" - end + adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/] + t.pattern = "test/**/*_test{,_#{adapter_short}}.rb" t.verbose = true } end @@ -223,4 +220,4 @@ task :release => [ :package ] do rubyforge = RubyForge.new rubyforge.login rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages) -end \ No newline at end of file +end diff --git a/activerecord/test/copy_table_sqlite.rb b/activerecord/test/copy_table_sqlite.rb deleted file mode 100644 index f3f5f1ce46..0000000000 --- a/activerecord/test/copy_table_sqlite.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'abstract_unit' - -class CopyTableTest < Test::Unit::TestCase - fixtures :companies, :comments - - def setup - @connection = ActiveRecord::Base.connection - class << @connection - public :copy_table, :table_structure, :indexes - end - end - - def test_copy_table(from = 'companies', to = 'companies2', options = {}) - assert_nothing_raised {copy_table(from, to, options)} - assert_equal row_count(from), row_count(to) - - if block_given? - yield from, to, options - else - assert_equal column_names(from), column_names(to) - end - - @connection.drop_table(to) rescue nil - end - - def test_copy_table_renaming_column - test_copy_table('companies', 'companies2', - :rename => {'client_of' => 'fan_of'}) do |from, to, options| - assert_equal column_values(from, 'client_of').compact.sort, - column_values(to, 'fan_of').compact.sort - end - end - - def test_copy_table_with_index - test_copy_table('comments', 'comments_with_index') do - @connection.add_index('comments_with_index', ['post_id', 'type']) - test_copy_table('comments_with_index', 'comments_with_index2') do - assert_equal table_indexes_without_name('comments_with_index'), - table_indexes_without_name('comments_with_index2') - end - end - end - -protected - def copy_table(from, to, options = {}) - @connection.copy_table(from, to, {:temporary => true}.merge(options)) - end - - def column_names(table) - @connection.table_structure(table).map {|column| column['name']} - end - - def column_values(table, column) - @connection.select_all("SELECT #{column} FROM #{table}").map {|row| row[column]} - end - - def table_indexes_without_name(table) - @connection.indexes('comments_with_index').delete(:name) - end - - def row_count(table) - @connection.select_one("SELECT COUNT(*) AS count FROM #{table}")['count'] - end -end diff --git a/activerecord/test/copy_table_test_sqlite.rb b/activerecord/test/copy_table_test_sqlite.rb new file mode 100644 index 0000000000..6da041522f --- /dev/null +++ b/activerecord/test/copy_table_test_sqlite.rb @@ -0,0 +1,65 @@ +require 'abstract_unit' + +class CopyTableTest < Test::Unit::TestCase + fixtures :companies, :comments + + def setup + @connection = ActiveRecord::Base.connection + class << @connection + public :copy_table, :table_structure, :indexes + end + end + + def test_copy_table(from = 'companies', to = 'companies2', options = {}) + assert_nothing_raised {copy_table(from, to, options)} + assert_equal row_count(from), row_count(to) + + if block_given? + yield from, to, options + else + assert_equal column_names(from), column_names(to) + end + + @connection.drop_table(to) rescue nil + end + + def test_copy_table_renaming_column + test_copy_table('companies', 'companies2', + :rename => {'client_of' => 'fan_of'}) do |from, to, options| + expected = column_values(from, 'client_of') + assert expected.any?, 'only nils in resultset; real values are needed' + assert_equal expected, column_values(to, 'fan_of') + end + end + + def test_copy_table_with_index + test_copy_table('comments', 'comments_with_index') do + @connection.add_index('comments_with_index', ['post_id', 'type']) + test_copy_table('comments_with_index', 'comments_with_index2') do + assert_equal table_indexes_without_name('comments_with_index'), + table_indexes_without_name('comments_with_index2') + end + end + end + +protected + def copy_table(from, to, options = {}) + @connection.copy_table(from, to, {:temporary => true}.merge(options)) + end + + def column_names(table) + @connection.table_structure(table).map {|column| column['name']} + end + + def column_values(table, column) + @connection.select_all("SELECT #{column} FROM #{table} ORDER BY id").map {|row| row[column]} + end + + def table_indexes_without_name(table) + @connection.indexes('comments_with_index').delete(:name) + end + + def row_count(table) + @connection.select_one("SELECT COUNT(*) AS count FROM #{table}")['count'] + end +end -- cgit v1.2.3