From e3103441114b1c5e7b67b71efa9c0b44e03645e6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Jan 2007 00:34:43 +0000 Subject: Oracle: create_table takes a :sequence_name option to override the 'tablename_seq' default. Closes #7000. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5933 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/defaults_test.rb | 2 +- .../test/fixtures/db_definitions/oracle.sql | 17 ++++++++++ activerecord/test/migration_test.rb | 39 +++++++++++++++++++++- 3 files changed, 56 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/defaults_test.rb b/activerecord/test/defaults_test.rb index cf99978f9e..39dcc82b49 100644 --- a/activerecord/test/defaults_test.rb +++ b/activerecord/test/defaults_test.rb @@ -46,7 +46,7 @@ class DefaultTest < Test::Unit::TestCase end end - if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter) + if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter, :OracleAdapter) def test_default_integers default = Default.new assert_instance_of Fixnum, default.positive_integer diff --git a/activerecord/test/fixtures/db_definitions/oracle.sql b/activerecord/test/fixtures/db_definitions/oracle.sql index ccf472c905..869c59fb75 100644 --- a/activerecord/test/fixtures/db_definitions/oracle.sql +++ b/activerecord/test/fixtures/db_definitions/oracle.sql @@ -137,6 +137,23 @@ create table booleantests ( ); create sequence booleantests_seq minvalue 10000; +CREATE TABLE defaults ( + id integer not null, + modified_date date default sysdate, + modified_date_function date default sysdate, + fixed_date date default to_date('2004-01-01', 'YYYY-MM-DD'), + modified_time date default sysdate, + modified_time_function date default sysdate, + fixed_time date default TO_DATE('2004-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), + char1 varchar2(1) default 'Y', + char2 varchar2(50) default 'a varchar field', + char3 clob default 'a text field', + positive_integer integer default 1, + negative_integer integer default -1, + decimal_number number(3,2) default 2.78 +); +create sequence defaults_seq minvalue 10000; + create table auto_id_tests ( auto_id integer not null, value integer default null, diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index ce79ffc80e..355c459818 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -700,6 +700,43 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal 2, ActiveRecord::Migrator.current_version end - + def test_create_table_with_custom_sequence_name + return unless current_adapter? :OracleAdapter + + # table name is 29 chars, the standard sequence name will + # be 33 chars and fail + assert_raises(ActiveRecord::StatementInvalid) do + begin + Person.connection.create_table :table_with_name_thats_just_ok do |t| + t.column :foo, :string, :null => false + end + ensure + Person.connection.drop_table :table_with_name_thats_just_ok rescue nil + end + end + + # should be all good w/ a custom sequence name + assert_nothing_raised do + begin + Person.connection.create_table :table_with_name_thats_just_ok, + :sequence_name => 'suitably_short_seq' do |t| + t.column :foo, :string, :null => false + end + + Person.connection.execute("select suitably_short_seq.nextval from dual") + + ensure + Person.connection.drop_table :table_with_name_thats_just_ok, + :sequence_name => 'suitably_short_seq' rescue nil + end + end + + # confirm the custom sequence got dropped + assert_raises(ActiveRecord::StatementInvalid) do + Person.connection.execute("select suitably_short_seq.nextval from dual") + end + end + end end + -- cgit v1.2.3