aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-09-13 23:21:14 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-09-13 23:21:14 +0000
commitf7c371dff8021de8e2389580bb96b0cfdca3c9ec (patch)
treed6d698b4129a2ecdc5efee6267bb5332319baad4 /activerecord/test
parent54a6ed148248b31bee5823d4dd55675edf018e34 (diff)
downloadrails-f7c371dff8021de8e2389580bb96b0cfdca3c9ec.tar.gz
rails-f7c371dff8021de8e2389580bb96b0cfdca3c9ec.tar.bz2
rails-f7c371dff8021de8e2389580bb96b0cfdca3c9ec.zip
OpenBase: update for new lib and latest Rails. Support migrations. Closes #8748.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7472 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations/eager_test.rb14
-rw-r--r--activerecord/test/fixtures/db_definitions/openbase.sql59
-rw-r--r--activerecord/test/locking_test.rb6
-rw-r--r--activerecord/test/migration_test.rb30
4 files changed, 71 insertions, 38 deletions
diff --git a/activerecord/test/associations/eager_test.rb b/activerecord/test/associations/eager_test.rb
index 019d361f3d..bbf3edd0c9 100644
--- a/activerecord/test/associations/eager_test.rb
+++ b/activerecord/test/associations/eager_test.rb
@@ -135,13 +135,21 @@ class EagerAssociationTest < Test::Unit::TestCase
end
def test_eager_with_has_many_and_limit_and_conditions
- posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.body = 'hello'", :order => "posts.id")
+ if current_adapter?(:OpenBaseAdapter)
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "FETCHBLOB(posts.body) = 'hello'", :order => "posts.id")
+ else
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.body = 'hello'", :order => "posts.id")
+ end
assert_equal 2, posts.size
assert_equal [4,5], posts.collect { |p| p.id }
end
def test_eager_with_has_many_and_limit_and_conditions_array
- posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id")
+ if current_adapter?(:OpenBaseAdapter)
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "FETCHBLOB(posts.body) = ?", 'hello' ], :order => "posts.id")
+ else
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id")
+ end
assert_equal 2, posts.size
assert_equal [4,5], posts.collect { |p| p.id }
end
@@ -399,6 +407,8 @@ class EagerAssociationTest < Test::Unit::TestCase
def test_count_with_include
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "len(comments.body) > 15")
+ elsif current_adapter?(:OpenBaseAdapter)
+ assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(FETCHBLOB(comments.body)) > 15")
else
assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(comments.body) > 15")
end
diff --git a/activerecord/test/fixtures/db_definitions/openbase.sql b/activerecord/test/fixtures/db_definitions/openbase.sql
index 4f5d27e63d..a177d1688b 100644
--- a/activerecord/test/fixtures/db_definitions/openbase.sql
+++ b/activerecord/test/fixtures/db_definitions/openbase.sql
@@ -1,5 +1,5 @@
CREATE TABLE accounts (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
firm_id integer,
credit_limit integer
)
@@ -8,7 +8,7 @@ CREATE PRIMARY KEY accounts (id)
go
CREATE TABLE funny_jokes (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
name char(50) DEFAULT NULL
)
go
@@ -16,7 +16,7 @@ CREATE PRIMARY KEY funny_jokes (id)
go
CREATE TABLE companies (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
type char(50),
ruby_type char(50),
firm_id integer,
@@ -37,7 +37,7 @@ CREATE TABLE developers_projects (
go
CREATE TABLE developers (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
name char(100),
salary integer DEFAULT 70000,
created_at datetime,
@@ -48,7 +48,7 @@ CREATE PRIMARY KEY developers (id)
go
CREATE TABLE projects (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
name char(100),
type char(255)
)
@@ -57,7 +57,7 @@ CREATE PRIMARY KEY projects (id)
go
CREATE TABLE topics (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
title char(255),
author_name char(255),
author_email_address char(255),
@@ -75,7 +75,7 @@ CREATE PRIMARY KEY topics (id)
go
CREATE TABLE customers (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
name char,
balance integer default 0,
address_street char,
@@ -88,7 +88,7 @@ CREATE PRIMARY KEY customers (id)
go
CREATE TABLE orders (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
name char,
billing_customer_id integer,
shipping_customer_id integer
@@ -98,7 +98,7 @@ CREATE PRIMARY KEY orders (id)
go
CREATE TABLE movies (
- movieid integer UNIQUE INDEX DEFAULT _rowid,
+ movieid integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
name text
)
go
@@ -114,7 +114,7 @@ CREATE PRIMARY KEY subscribers (nick)
go
CREATE TABLE booleantests (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
value boolean
)
go
@@ -131,12 +131,17 @@ CREATE TABLE defaults (
fixed_time timestamp default '2004-01-01 00:00:00.000000-00',
char1 char(1) default 'Y',
char2 char(50) default 'a char field',
- char3 text default 'a text field'
+ char3 text default 'a text field',
+ positive_integer integer default 1,
+ negative_integer integer default -1,
+ decimal_number money default 2.78
)
go
+CREATE PRIMARY KEY defaults (id)
+go
CREATE TABLE auto_id_tests (
- auto_id integer UNIQUE INDEX DEFAULT _rowid,
+ auto_id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
value integer
)
go
@@ -144,20 +149,24 @@ CREATE PRIMARY KEY auto_id_tests (auto_id)
go
CREATE TABLE entrants (
- id integer UNIQUE INDEX ,
- name text,
- course_id integer
+ id integer NOT NULL UNIQUE INDEX,
+ name text NOT NULL,
+ course_id integer NOT NULL
)
go
+CREATE PRIMARY KEY entrants (id)
+go
CREATE TABLE colnametests (
id integer UNIQUE INDEX ,
references integer NOT NULL
)
go
+CREATE PRIMARY KEY colnametests (id)
+go
CREATE TABLE mixins (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
parent_id integer,
type char,
pos integer,
@@ -172,7 +181,7 @@ CREATE PRIMARY KEY mixins (id)
go
CREATE TABLE people (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
first_name text,
lock_version integer default 0
)
@@ -181,7 +190,7 @@ CREATE PRIMARY KEY people (id)
go
CREATE TABLE readers (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
post_id integer NOT NULL,
person_id integer NOT NULL
)
@@ -190,7 +199,7 @@ CREATE PRIMARY KEY readers (id)
go
CREATE TABLE binaries (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
data object
)
go
@@ -228,7 +237,7 @@ CREATE TABLE authors (
go
CREATE TABLE tasks (
- id integer UNIQUE INDEX DEFAULT _rowid,
+ id integer NOT NULL UNIQUE INDEX DEFAULT _rowid,
starting datetime,
ending datetime
)
@@ -283,11 +292,11 @@ go
CREATE TABLE numeric_data (
id INTEGER NOT NULL DEFAULT _rowid,
- bank_balance DECIMAL(10,2),
- big_bank_balance DECIMAL(15,2),
- world_population DECIMAL(10),
- my_house_population DECIMAL(2),
- decimal_number_with_default DECIMAL(3,2) DEFAULT 2.78
+ bank_balance MONEY,
+ big_bank_balance MONEY,
+ world_population longlong,
+ my_house_population longlong,
+ decimal_number_with_default MONEY DEFAULT 2.78
);
go
CREATE PRIMARY KEY numeric_data (id)
diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb
index 3194727822..5b23aab515 100644
--- a/activerecord/test/locking_test.rb
+++ b/activerecord/test/locking_test.rb
@@ -119,6 +119,8 @@ class OptimisticLockingTest < Test::Unit::TestCase
def add_counter_column_to(model)
model.connection.add_column model.table_name, :test_count, :integer, :null => false, :default => 0
model.reset_column_information
+ # OpenBase does not set a value to existing rows when adding a not null default column
+ model.update_all(:test_count => 0) if current_adapter?(:OpenBaseAdapter)
end
def remove_counter_column_from(model)
@@ -146,9 +148,9 @@ end
# blocks, so separate script called by Kernel#system is needed.
# (See exec vs. async_exec in the PostgreSQL adapter.)
-# TODO: The SQL Server and Sybase adapters currently have no support for pessimistic locking
+# TODO: The SQL Server, Sybase, and OpenBase adapters currently have no support for pessimistic locking
-unless current_adapter?(:SQLServerAdapter, :SybaseAdapter)
+unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
class PessimisticLockingTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
fixtures :people, :readers
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index dec126bd45..2d483112d1 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -59,7 +59,8 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
# Orcl nds shrt indx nms. Sybs 2.
- unless current_adapter?(:OracleAdapter, :SybaseAdapter)
+ # OpenBase does not have named indexes. You must specify a single column name
+ unless current_adapter?(:OracleAdapter, :SybaseAdapter, :OpenBaseAdapter)
assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
assert_nothing_raised { Person.connection.remove_index("people", :column => ["last_name", "first_name"]) }
assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
@@ -72,11 +73,15 @@ if ActiveRecord::Base.connection.supports_migrations?
# quoting
# Note: changed index name from "key" to "key_idx" since "key" is a Firebird reserved word
- assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key_idx", :unique => true) }
- assert_nothing_raised { Person.connection.remove_index("people", :name => "key_idx", :unique => true) }
-
+ # OpenBase does not have named indexes. You must specify a single column name
+ unless current_adapter?(:OpenBaseAdapter)
+ assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key_idx", :unique => true) }
+ assert_nothing_raised { Person.connection.remove_index("people", :name => "key_idx", :unique => true) }
+ end
+
# Sybase adapter does not support indexes on :boolean columns
- unless current_adapter?(:SybaseAdapter)
+ # OpenBase does not have named indexes. You must specify a single column
+ unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter)
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
@@ -202,7 +207,12 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_nothing_raised {Person.connection.add_column :testings, :bar, :string, :null => false, :default => "default" }
assert_raises(ActiveRecord::StatementInvalid) do
- Person.connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}, #{con.quote_column_name('bar')}) values (2, 'hello', NULL)"
+ unless current_adapter?(:OpenBaseAdapter)
+ Person.connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}, #{con.quote_column_name('bar')}) values (2, 'hello', NULL)"
+ else
+ Person.connection.insert("INSERT INTO testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}, #{con.quote_column_name('bar')}) VALUES (2, 'hello', NULL)",
+ "Testing Insert","id",2)
+ end
end
ensure
Person.connection.drop_table :testings rescue nil
@@ -221,6 +231,8 @@ if ActiveRecord::Base.connection.supports_migrations?
# Do a manual insertion
if current_adapter?(:OracleAdapter)
Person.connection.execute "insert into people (id, wealth) values (people_seq.nextval, 12345678901234567890.0123456789)"
+ elsif current_adapter?(:OpenBaseAdapter)
+ Person.connection.execute "insert into people (wealth) values ('12345678901234567890.0123456789')"
else
Person.connection.execute "insert into people (wealth) values (12345678901234567890.0123456789)"
end
@@ -514,8 +526,8 @@ if ActiveRecord::Base.connection.supports_migrations?
assert !Reminder.table_exists?
WeNeedReminders.up
-
- assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
+
+ assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
WeNeedReminders.down
@@ -773,7 +785,7 @@ if ActiveRecord::Base.connection.supports_migrations?
assert Person.column_methods_hash.include?(:last_name)
assert_equal 2, ActiveRecord::Migrator.current_version
end
-
+
def test_create_table_with_custom_sequence_name
return unless current_adapter? :OracleAdapter