aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-11-05 02:01:31 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-11-05 02:01:31 +0000
commitb6171e71050dda9e3b4ebfccd440a180283667ce (patch)
treed771aa00b002e93f28bb107d9edefd3e217c6188 /activerecord/test
parentceb3859672ddba6257ffc59c2db4fd99d98ffc9b (diff)
downloadrails-b6171e71050dda9e3b4ebfccd440a180283667ce.tar.gz
rails-b6171e71050dda9e3b4ebfccd440a180283667ce.tar.bz2
rails-b6171e71050dda9e3b4ebfccd440a180283667ce.zip
SQLite: count(distinct) queries supported in >= 3.2.6, fix calculations workaround, remove count(distinct) query rewrite, cleanup test connection scripts. Closes #6544.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5426 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/base_test.rb18
-rw-r--r--activerecord/test/connections/native_sqlite/connection.rb17
-rw-r--r--activerecord/test/connections/native_sqlite3/connection.rb17
-rw-r--r--activerecord/test/migration_test.rb7
4 files changed, 21 insertions, 38 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 4afeb52a87..27bfdfb72f 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1219,15 +1219,17 @@ class BasicsTest < Test::Unit::TestCase
assert_equal res4, res5
- res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
- res7 = nil
- assert_nothing_raised do
- res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id",
- :joins => "p, comments co",
- :select => "p.id",
- :distinct => true)
+ unless current_adapter?(:SQLite2Adapter, :DeprecatedSQLiteAdapter)
+ res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
+ res7 = nil
+ assert_nothing_raised do
+ res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id",
+ :joins => "p, comments co",
+ :select => "p.id",
+ :distinct => true)
+ end
+ assert_equal res6, res7
end
- assert_equal res6, res7
end
def test_clear_association_cache_stored
diff --git a/activerecord/test/connections/native_sqlite/connection.rb b/activerecord/test/connections/native_sqlite/connection.rb
index 14ae999023..028ecee4df 100644
--- a/activerecord/test/connections/native_sqlite/connection.rb
+++ b/activerecord/test/connections/native_sqlite/connection.rb
@@ -10,25 +10,16 @@ BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
-def make_connection(clazz, db_file, db_definitions_file)
+def make_connection(clazz, db_file)
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite', :database => db_file } }
unless File.exist?(db_file)
puts "SQLite database not found at #{db_file}. Rebuilding it."
sqlite_command = %Q{sqlite #{db_file} "create table a (a integer); drop table a;"}
puts "Executing '#{sqlite_command}'"
raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
- clazz.establish_connection(clazz.name)
- script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
- # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
- script.split(';').each do
- |command|
- clazz.connection.execute(command) unless command.strip.empty?
- end
- else
- clazz.establish_connection(clazz.name)
end
+ clazz.establish_connection(clazz.name)
end
-make_connection(ActiveRecord::Base, sqlite_test_db, 'sqlite.sql')
-make_connection(Course, sqlite_test_db2, 'sqlite2.sql')
-load(File.join(BASE_DIR, 'db_definitions', 'schema.rb'))
+make_connection(ActiveRecord::Base, sqlite_test_db)
+make_connection(Course, sqlite_test_db2)
diff --git a/activerecord/test/connections/native_sqlite3/connection.rb b/activerecord/test/connections/native_sqlite3/connection.rb
index 6dbb2b98c1..bfb9f560b7 100644
--- a/activerecord/test/connections/native_sqlite3/connection.rb
+++ b/activerecord/test/connections/native_sqlite3/connection.rb
@@ -10,25 +10,16 @@ BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3"
-def make_connection(clazz, db_file, db_definitions_file)
+def make_connection(clazz, db_file)
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => db_file, :timeout => 5000 } }
unless File.exist?(db_file)
puts "SQLite3 database not found at #{db_file}. Rebuilding it."
sqlite_command = %Q{sqlite3 #{db_file} "create table a (a integer); drop table a;"}
puts "Executing '#{sqlite_command}'"
raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
- clazz.establish_connection(clazz.name)
- script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
- # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
- script.split(';').each do
- |command|
- clazz.connection.execute(command) unless command.strip.empty?
- end
- else
- clazz.establish_connection(clazz.name)
end
+ clazz.establish_connection(clazz.name)
end
-make_connection(ActiveRecord::Base, sqlite_test_db, 'sqlite.sql')
-make_connection(Course, sqlite_test_db2, 'sqlite2.sql')
-load(File.join(BASE_DIR, 'db_definitions', 'schema.rb'))
+make_connection(ActiveRecord::Base, sqlite_test_db)
+make_connection(Course, sqlite_test_db2)
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index a28532eed7..3cfbcac82e 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -165,10 +165,9 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.drop_table :testings rescue nil
end
- # SQL Server and Sybase will not allow you to add a NOT NULL column
- # to a table without specifying a default value, so the
- # following test must be skipped
- unless current_adapter?(:SQLServerAdapter, :SybaseAdapter)
+ # SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
+ # column to a table without a default value.
+ unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :SQLiteAdapter)
def test_add_column_not_null_without_default
Person.connection.create_table :testings do |t|
t.column :foo, :string