From ea617708c2ad9a770a1f3950e7a0028e9764d989 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 18 Mar 2006 03:02:32 +0000 Subject: Added migrations support to the Sybase adapter (closes #4293) [John R. Sheets] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3905 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/abstract_unit.rb | 5 +-- activerecord/test/base_test.rb | 14 ++++++-- activerecord/test/binary_test.rb | 2 +- .../test/fixtures/db_definitions/sybase.sql | 42 +++++++++++----------- activerecord/test/migration_test.rb | 15 ++++---- 5 files changed, 46 insertions(+), 32 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/abstract_unit.rb b/activerecord/test/abstract_unit.rb index 6c089f3696..29e4601fee 100755 --- a/activerecord/test/abstract_unit.rb +++ b/activerecord/test/abstract_unit.rb @@ -22,9 +22,10 @@ class Test::Unit::TestCase #:nodoc: def assert_date_from_db(expected, actual, message = nil) # SQL Server doesn't have a separate column type just for dates, # so the time is in the string and incorrectly formatted - - if current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter) + if current_adapter?(:SQLServerAdapter) assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00") + elsif current_adapter?(:SybaseAdapter) + assert_equal expected.to_s, actual.to_date.to_s, message else assert_equal expected.to_s, actual.to_s, message end diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 40782729d9..58dd133aeb 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -569,7 +569,13 @@ class BasicsTest < Test::Unit::TestCase topic = Topic.find(topic.id) assert_nil topic.last_read - assert_nil topic.approved + + # Sybase adapter does not allow nulls in boolean columns + if current_adapter?(:SybaseAdapter) + assert topic.approved == false + else + assert_nil topic.approved + end end def test_equality @@ -1177,7 +1183,11 @@ class BasicsTest < Test::Unit::TestCase assert xml.include?(%(Have a nice day)) assert xml.include?(%(david@loudthinking.com)) assert xml.include?(%()) - assert xml.include?(%(2004-04-15)) + if current_adapter?(:SybaseAdapter) + assert xml.include?(%(2004-04-15T00:00:00-05:00)) + else + assert xml.include?(%(2004-04-15)) + end # Oracle doesn't have true boolean or time-only fields unless current_adapter?(:OracleAdapter) assert xml.include?(%(false)), "Approved should be a boolean" diff --git a/activerecord/test/binary_test.rb b/activerecord/test/binary_test.rb index e7a87a4833..38a5d50935 100644 --- a/activerecord/test/binary_test.rb +++ b/activerecord/test/binary_test.rb @@ -20,7 +20,7 @@ class BinaryTest < Test::Unit::TestCase # Without using prepared statements, it makes no sense to test # BLOB data with DB2 or Firebird, because the length of a statement # is limited to 32KB. - unless %w(SQLServer DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name + unless %w(SQLServer Sybase DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name def test_load_save bin = Binary.new bin.data = @data diff --git a/activerecord/test/fixtures/db_definitions/sybase.sql b/activerecord/test/fixtures/db_definitions/sybase.sql index 28164d8a14..07f670867e 100644 --- a/activerecord/test/fixtures/db_definitions/sybase.sql +++ b/activerecord/test/fixtures/db_definitions/sybase.sql @@ -29,8 +29,8 @@ CREATE TABLE topics ( bonus_time time NULL, last_read datetime NULL, content varchar(255) NULL, - approved tinyint default 1 NULL, - replies_count int default 0 NULL, + approved bit default 1, + replies_count int default 0, parent_id int NULL, type varchar(50) NULL ) @@ -46,7 +46,7 @@ CREATE TABLE developers ( CREATE TABLE projects ( id numeric(9,0) IDENTITY PRIMARY KEY, name varchar(100) NULL, - type VARCHAR(255) NULL + type varchar(255) NULL ) CREATE TABLE developers_projects ( @@ -85,18 +85,18 @@ CREATE TABLE subscribers ( CREATE TABLE booleantests ( id numeric(9,0) IDENTITY PRIMARY KEY, - value integer NULL + value int NULL ) CREATE TABLE auto_id_tests ( auto_id numeric(9,0) IDENTITY PRIMARY KEY, - value integer NULL + value int NULL ) CREATE TABLE entrants ( id numeric(9,0) IDENTITY PRIMARY KEY, - name VARCHAR(255) NOT NULL, - course_id INTEGER NOT NULL + name varchar(255) NOT NULL, + course_id int NOT NULL ) CREATE TABLE colnametests ( @@ -118,8 +118,8 @@ CREATE TABLE mixins ( CREATE TABLE people ( id numeric(9,0) IDENTITY PRIMARY KEY, - first_name VARCHAR(40) NOT NULL, - lock_version INTEGER DEFAULT 0 + first_name varchar(40) NOT NULL, + lock_version int DEFAULT 0 ) CREATE TABLE readers ( @@ -135,28 +135,28 @@ CREATE TABLE binaries ( CREATE TABLE computers ( id numeric(9,0) IDENTITY PRIMARY KEY, - developer INTEGER NOT NULL, - extendedWarranty INTEGER NOT NULL + developer int NOT NULL, + extendedWarranty int NOT NULL ) CREATE TABLE posts ( id numeric(9,0) IDENTITY PRIMARY KEY, - author_id INTEGER NULL, - title VARCHAR(255) NOT NULL, - body VARCHAR(2048) NOT NULL, - type VARCHAR(255) NOT NULL + author_id int NULL, + title varchar(255) NOT NULL, + body varchar(2048) NOT NULL, + type varchar(255) NOT NULL ) CREATE TABLE comments ( id numeric(9,0) IDENTITY PRIMARY KEY, - post_id INTEGER NOT NULL, - body VARCHAR(2048) NOT NULL, - type VARCHAR(255) NOT NULL + post_id int NOT NULL, + body varchar(2048) NOT NULL, + type varchar(255) NOT NULL ) CREATE TABLE authors ( id numeric(9,0) IDENTITY PRIMARY KEY, - name VARCHAR(255) NOT NULL + name varchar(255) NOT NULL ) CREATE TABLE tasks ( @@ -167,8 +167,8 @@ CREATE TABLE tasks ( CREATE TABLE categories ( id numeric(9,0) IDENTITY PRIMARY KEY, - name VARCHAR(255) NOT NULL, - type VARCHAR(255) NOT NULL + name varchar(255) NOT NULL, + type varchar(255) NOT NULL ) CREATE TABLE categories_posts ( diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index f4d6a2b7ef..55eed450c7 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -54,8 +54,11 @@ if ActiveRecord::Base.connection.supports_migrations? assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) } assert_nothing_raised { Person.connection.remove_index("people", "last_name") } - assert_nothing_raised { Person.connection.add_index("people", %w(last_name first_name administrator), :name => "named_admin") } - assert_nothing_raised { Person.connection.remove_index("people", :name => "named_admin") } + # Sybase adapter does not support indexes on :boolean columns + unless current_adapter?(:SybaseAdapter) + assert_nothing_raised { Person.connection.add_index("people", %w(last_name first_name administrator), :name => "named_admin") } + assert_nothing_raised { Person.connection.remove_index("people", :name => "named_admin") } + end end def test_create_table_adds_id @@ -110,10 +113,10 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.drop_table :testings rescue nil end - # SQL Server will not allow you to add a NOT NULL column + # 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) + unless current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter) def test_add_column_not_null_without_default Person.connection.create_table :testings do |t| t.column :foo, :string @@ -165,8 +168,8 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal Fixnum, bob.age.class assert_equal Time, bob.birthday.class - if current_adapter?(:SQLServerAdapter) or current_adapter?(:OracleAdapter) - # SQL Server and Oracle don't differentiate between date/time + if current_adapter?(:SQLServerAdapter) || current_adapter?(:OracleAdapter) || current_adapter?(:SybaseAdapter) + # SQL Server, Sybase, and Oracle don't differentiate between date/time assert_equal Time, bob.favorite_day.class else assert_equal Date, bob.favorite_day.class -- cgit v1.2.3