aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-07 14:06:00 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-07 14:06:00 +0000
commit336c2cbb8f728825139f2ab94b96726935ea18a1 (patch)
tree1943ecb94336aae84d458a97bd376306dac1118d /activerecord/test
parent8382e6e50681fef860fb2856af12fa72853a8488 (diff)
downloadrails-336c2cbb8f728825139f2ab94b96726935ea18a1.tar.gz
rails-336c2cbb8f728825139f2ab94b96726935ea18a1.tar.bz2
rails-336c2cbb8f728825139f2ab94b96726935ea18a1.zip
Added an Oracle adapter that works with the Oracle bindings by Yoshida (http://raa.ruby-lang.org/project/oracle/) #564 [Maik Schmidt]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@522 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/base_test.rb14
-rw-r--r--activerecord/test/binary_test.rb8
-rw-r--r--activerecord/test/column_alias_test.rb11
-rw-r--r--activerecord/test/connections/native_oracle/connection.rb24
-rwxr-xr-xactiverecord/test/finder_test.rb14
-rw-r--r--activerecord/test/fixtures/db_definitions/create_oracle_db.bat5
-rw-r--r--activerecord/test/fixtures/db_definitions/create_oracle_db.sh5
-rw-r--r--activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql35
-rw-r--r--activerecord/test/fixtures/db_definitions/drop_oracle_tables2.sql3
-rw-r--r--activerecord/test/fixtures/db_definitions/oracle.sql149
-rw-r--r--activerecord/test/fixtures/db_definitions/oracle2.sql7
-rw-r--r--activerecord/test/fixtures/topics.yml5
12 files changed, 269 insertions, 11 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 8e69eb01a4..cbccacdbf5 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -176,6 +176,10 @@ class BasicsTest < Test::Unit::TestCase
"The last_read attribute should be of the Date class"
)
+ # Oracle does not have a TIME datatype.
+ if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
+ return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
+ end
assert_kind_of(
Time, Topic.find(1).bonus_time,
"The bonus_time attribute should be of the Time class"
@@ -381,6 +385,11 @@ class BasicsTest < Test::Unit::TestCase
end
def test_utc_as_time_zone
+ # Oracle does not have a TIME datatype.
+ if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
+ return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
+ end
+
Topic.default_timezone = :utc
attributes = { "bonus_time" => "5:42:00AM" }
topic = Topic.find(1)
@@ -506,6 +515,11 @@ class BasicsTest < Test::Unit::TestCase
end
def test_attributes_on_dummy_time
+ # Oracle does not have a TIME datatype.
+ if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
+ return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
+ end
+
attributes = {
"bonus_time" => "5:42:00AM"
}
diff --git a/activerecord/test/binary_test.rb b/activerecord/test/binary_test.rb
index 1e74b023bf..d635621cef 100644
--- a/activerecord/test/binary_test.rb
+++ b/activerecord/test/binary_test.rb
@@ -13,6 +13,10 @@ class BinaryTest < Test::Unit::TestCase
if ActiveRecord::ConnectionAdapters.const_defined? :DB2Adapter
return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::DB2Adapter)
end
+
+ if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
+ return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
+ end
bin = Binary.new
bin.data = @data
@@ -27,10 +31,10 @@ class BinaryTest < Test::Unit::TestCase
db_bin = Binary.find(bin.id)
assert db_bin.data == bin.data,
- "Loaded binary data differes from memory version"
+ "Loaded binary data differs from memory version"
assert db_bin.data == File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read,
- "Loaded binary data differes from file version"
+ "Loaded binary data differs from file version"
end
private
diff --git a/activerecord/test/column_alias_test.rb b/activerecord/test/column_alias_test.rb
index 06a0a7f3b0..1c84e119f3 100644
--- a/activerecord/test/column_alias_test.rb
+++ b/activerecord/test/column_alias_test.rb
@@ -5,8 +5,15 @@ class TestColumnAlias < Test::Unit::TestCase
def test_column_alias
topic = Topic.find(1)
- records = topic.connection.select_all("SELECT id AS pk FROM topics LIMIT 1")
- assert_equal(records[0].keys[0], "pk")
+ if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
+ if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
+ records = topic.connection.select_all("SELECT id AS pk FROM topics WHERE ROWNUM < 2")
+ assert_equal(records[0].keys[0], "pk")
+ end
+ else
+ records = topic.connection.select_all("SELECT id AS pk FROM topics LIMIT 1")
+ assert_equal(records[0].keys[0], "pk")
+ end
end
end
diff --git a/activerecord/test/connections/native_oracle/connection.rb b/activerecord/test/connections/native_oracle/connection.rb
new file mode 100644
index 0000000000..7e4cc5b574
--- /dev/null
+++ b/activerecord/test/connections/native_oracle/connection.rb
@@ -0,0 +1,24 @@
+print "Using native Oracle\n"
+require 'fixtures/course'
+require 'logger'
+
+ActiveRecord::Base.logger = Logger.new("debug.log")
+
+db1 = 'local'
+db2 = 'local'
+
+ActiveRecord::Base.establish_connection(
+ :adapter => "oracle",
+ :host => "localhost",
+ :username => "arunit",
+ :password => "arunit",
+ :database => db1
+)
+
+Course.establish_connection(
+ :adapter => "oracle",
+ :host => "localhost",
+ :username => "arunit2",
+ :password => "arunit2",
+ :database => db2
+)
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index 5944717132..1f6a58dee6 100755
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -34,10 +34,16 @@ class FinderTest < Test::Unit::TestCase
end
def test_find_all_with_prepared_limit_and_offset
- entrants = Entrant.find_all nil, "id ASC", ["? OFFSET ?", 2, 1]
-
- assert_equal(2, entrants.size)
- assert_equal(@entrants["second"]["name"], entrants.first.name)
+ if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
+ if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
+ assert_raises(ArgumentError) { Entrant.find_all nil, "id ASC", ["? OFFSET ?", 2, 1] }
+ end
+ else
+ entrants = Entrant.find_all nil, "id ASC", ["? OFFSET ?", 2, 1]
+
+ assert_equal(2, entrants.size)
+ assert_equal(@entrants["second"]["name"], entrants.first.name)
+ end
end
def test_find_with_entire_select_statement
diff --git a/activerecord/test/fixtures/db_definitions/create_oracle_db.bat b/activerecord/test/fixtures/db_definitions/create_oracle_db.bat
new file mode 100644
index 0000000000..25c7e18856
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/create_oracle_db.bat
@@ -0,0 +1,5 @@
+sqlplus arunit/arunit @ drop_oracle_tables
+sqlplus arunit/arunit @ oracle
+sqlplus arunit2/arunit2 @ drop_oracle_tables2
+sqlplus arunit2/arunit2 @ oracle2
+
diff --git a/activerecord/test/fixtures/db_definitions/create_oracle_db.sh b/activerecord/test/fixtures/db_definitions/create_oracle_db.sh
new file mode 100644
index 0000000000..25c7e18856
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/create_oracle_db.sh
@@ -0,0 +1,5 @@
+sqlplus arunit/arunit @ drop_oracle_tables
+sqlplus arunit/arunit @ oracle
+sqlplus arunit2/arunit2 @ drop_oracle_tables2
+sqlplus arunit2/arunit2 @ oracle2
+
diff --git a/activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql b/activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql
new file mode 100644
index 0000000000..b300d13485
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql
@@ -0,0 +1,35 @@
+DROP TABLE accounts;
+DROP SEQUENCE accounts_id;
+DROP TABLE companies;
+DROP SEQUENCE companies_id;
+DROP TABLE topics;
+DROP SEQUENCE topics_id;
+DROP TABLE developers;
+DROP SEQUENCE developers_id;
+DROP TABLE projects;
+DROP SEQUENCE projects_id;
+DROP TABLE developers_projects;
+DROP SEQUENCE developers_projects_id;
+DROP TABLE customers;
+DROP SEQUENCE customers_id;
+DROP TABLE movies;
+DROP SEQUENCE movies_id;
+DROP TABLE subscribers;
+DROP SEQUENCE subscribers_id;
+DROP TABLE booleantests;
+DROP SEQUENCE booleantests_id;
+DROP TABLE auto_id_tests;
+DROP SEQUENCE auto_id_tests_id;
+DROP TABLE entrants;
+DROP SEQUENCE entrants_id;
+DROP TABLE colnametests;
+DROP SEQUENCE colnametests_id;
+DROP TABLE mixins;
+DROP SEQUENCE mixins_id;
+DROP TABLE people;
+DROP SEQUENCE people_id;
+DROP TABLE binaries;
+DROP SEQUENCE binaries_id;
+DROP TABLE computers;
+DROP SEQUENCE computers_id;
+EXIT;
diff --git a/activerecord/test/fixtures/db_definitions/drop_oracle_tables2.sql b/activerecord/test/fixtures/db_definitions/drop_oracle_tables2.sql
new file mode 100644
index 0000000000..934026dc89
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/drop_oracle_tables2.sql
@@ -0,0 +1,3 @@
+DROP TABLE courses;
+DROP SEQUENCE courses_id;
+EXIT;
diff --git a/activerecord/test/fixtures/db_definitions/oracle.sql b/activerecord/test/fixtures/db_definitions/oracle.sql
new file mode 100644
index 0000000000..31e66e8532
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/oracle.sql
@@ -0,0 +1,149 @@
+CREATE TABLE accounts (
+ id int NOT NULL,
+ firm_id int default NULL,
+ credit_limit int default NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE accounts_id MINVALUE 10000;
+
+CREATE TABLE companies (
+ id int NOT NULL,
+ type varchar(50) default NULL,
+ ruby_type varchar(50) default NULL,
+ firm_id int default NULL,
+ name varchar(50) default NULL,
+ client_of int default NULL,
+ rating int default 1,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE companies_id MINVALUE 10000;
+
+CREATE TABLE topics (
+ id int NOT NULL,
+ title varchar(255) default NULL,
+ author_name varchar(255) default NULL,
+ author_email_address varchar(255) default NULL,
+ written_on timestamp default NULL,
+ bonus_time timestamp default NULL,
+ last_read date default NULL,
+ content varchar(3000),
+ approved smallint default 1,
+ replies_count int default 0,
+ parent_id int default NULL,
+ type varchar(50) default NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE topics_id MINVALUE 10000;
+
+CREATE TABLE developers (
+ id int NOT NULL,
+ name varchar(100) default NULL,
+ salary int default 70000,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE developers_id MINVALUE 10000;
+
+CREATE TABLE projects (
+ id int NOT NULL,
+ name varchar(100) default NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE projects_id MINVALUE 10000;
+
+CREATE TABLE developers_projects (
+ developer_id int NOT NULL,
+ project_id int NOT NULL,
+ joined_on date default NULL
+);
+CREATE SEQUENCE developers_projects_id MINVALUE 10000;
+
+CREATE TABLE customers (
+ id int NOT NULL,
+ name varchar(100) default NULL,
+ balance int default 0,
+ address_street varchar(100) default NULL,
+ address_city varchar(100) default NULL,
+ address_country varchar(100) default NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE customers_id MINVALUE 10000;
+
+CREATE TABLE movies (
+ movieid int NOT NULL,
+ name varchar(100) default NULL,
+ PRIMARY KEY (movieid)
+);
+CREATE SEQUENCE movies_id MINVALUE 10000;
+
+CREATE TABLE subscribers (
+ nick varchar(100) NOT NULL,
+ name varchar(100) default NULL,
+ PRIMARY KEY (nick)
+);
+CREATE SEQUENCE subscribers_id MINVALUE 10000;
+
+CREATE TABLE booleantests (
+ id int NOT NULL,
+ value int default NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE booleantests_id MINVALUE 10000;
+
+CREATE TABLE auto_id_tests (
+ auto_id int NOT NULL,
+ value int default NULL,
+ PRIMARY KEY (auto_id)
+);
+CREATE SEQUENCE auto_id_tests_id MINVALUE 10000;
+
+CREATE TABLE entrants (
+ id int NOT NULL PRIMARY KEY,
+ name varchar(255) NOT NULL,
+ course_id int NOT NULL
+);
+CREATE SEQUENCE entrants_id MINVALUE 10000;
+
+CREATE TABLE colnametests (
+ id int NOT NULL,
+ references int NOT NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE colnametests_id MINVALUE 10000;
+
+CREATE TABLE mixins (
+ id int NOT NULL,
+ parent_id int default NULL,
+ pos int default NULL,
+ created_at timestamp default NULL,
+ updated_at timestamp default NULL,
+ lft int default NULL,
+ rgt int default NULL,
+ root_id int default NULL,
+ type varchar(40) default NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE mixins_id MINVALUE 10000;
+
+CREATE TABLE people (
+ id int NOT NULL,
+ first_name varchar(40) NOT NULL,
+ lock_version int default 0,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE people_id MINVALUE 10000;
+
+CREATE TABLE binaries (
+ id int NOT NULL,
+ data blob,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE binaries_id MINVALUE 10000;
+
+CREATE TABLE computers (
+ id int,
+ developer int NOT NULL,
+ PRIMARY KEY (id)
+);
+CREATE SEQUENCE computers_id MINVALUE 10000;
+
+EXIT;
diff --git a/activerecord/test/fixtures/db_definitions/oracle2.sql b/activerecord/test/fixtures/db_definitions/oracle2.sql
new file mode 100644
index 0000000000..e0bfde022c
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/oracle2.sql
@@ -0,0 +1,7 @@
+CREATE TABLE courses (
+ id int NOT NULL PRIMARY KEY,
+ name varchar(255) NOT NULL
+);
+CREATE SEQUENCE courses_id MINVALUE 10000;
+
+EXIT;
diff --git a/activerecord/test/fixtures/topics.yml b/activerecord/test/fixtures/topics.yml
index d4e5a57291..cd4dfa3638 100644
--- a/activerecord/test/fixtures/topics.yml
+++ b/activerecord/test/fixtures/topics.yml
@@ -3,8 +3,7 @@ first:
title: The First Topic
author_name: David
author_email_address: david@loudthinking.com
- written_on: 2003-07-16 15:28:00
- bonus_time: '12:13:14'
+ written_on: 2003-07-16t15:28:00.00+01:00
last_read: 2004-04-15
content: Have a nice day
approved: 0
@@ -14,7 +13,7 @@ second:
id: 2
title: The Second Topic's of the day
author_name: Mary
- written_on: 2003-07-15 15:28:00
+ written_on: 2003-07-15t15:28:00.00+01:00
content: Have a nice day
approved: 1
replies_count: 2