activerecord-oracle_enhanced-adapter 1.5.6 → 1.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.travis/oracle/download.sh +14 -0
  3. data/.travis/oracle/install.sh +31 -0
  4. data/.travis/setup_accounts.sh +9 -0
  5. data/.travis.yml +39 -0
  6. data/Gemfile +8 -8
  7. data/History.md +189 -0
  8. data/README.md +388 -178
  9. data/RUNNING_TESTS.md +11 -6
  10. data/VERSION +1 -1
  11. data/activerecord-oracle_enhanced-adapter.gemspec +29 -26
  12. data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
  13. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +66 -0
  14. data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
  15. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +260 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
  18. data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +13 -4
  19. data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +11 -5
  20. data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +1 -1
  21. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +34 -35
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +95 -0
  23. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +14 -37
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +562 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +65 -0
  26. data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +63 -14
  27. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +171 -73
  29. data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
  30. data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
  31. data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
  32. data/lib/activerecord-oracle_enhanced-adapter.rb +1 -1
  33. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +127 -49
  34. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +46 -5
  35. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +11 -3
  36. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +3 -3
  37. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +151 -78
  38. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +4 -4
  39. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +10 -16
  40. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -1
  41. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +5 -5
  42. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +65 -181
  43. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +114 -11
  44. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +17 -1
  45. data/spec/spec_config.yaml.template +11 -0
  46. data/spec/spec_helper.rb +31 -12
  47. data/spec/support/alter_system_user_password.sql +2 -0
  48. data/spec/support/create_oracle_enhanced_users.sql +31 -0
  49. metadata +37 -27
  50. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
  51. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
  52. data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
  53. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
  54. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -197
  55. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
  56. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
  57. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
  58. /data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
  59. /data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.rb} +0 -0
@@ -22,7 +22,7 @@ describe "OracleEnhancedAdapter schema dump" do
22
22
  schema_define do
23
23
  create_table :test_posts, options do |t|
24
24
  t.string :title
25
- t.timestamps
25
+ t.timestamps null: true
26
26
  end
27
27
  add_index :test_posts, :title
28
28
  end
@@ -180,21 +180,21 @@ describe "OracleEnhancedAdapter schema dump" do
180
180
  schema_define do
181
181
  add_foreign_key :test_comments, :test_posts
182
182
  end
183
- standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", name: "test_comments_test_post_id_fk"/
183
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts"/
184
184
  end
185
185
 
186
186
  it "should include foreign key with delete dependency in schema dump" do
187
187
  schema_define do
188
188
  add_foreign_key :test_comments, :test_posts, dependent: :delete
189
189
  end
190
- standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", name: "test_comments_test_post_id_fk", dependent: :delete/
190
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", on_delete: :cascade/
191
191
  end
192
192
 
193
193
  it "should include foreign key with nullify dependency in schema dump" do
194
194
  schema_define do
195
195
  add_foreign_key :test_comments, :test_posts, dependent: :nullify
196
196
  end
197
- standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", name: "test_comments_test_post_id_fk", dependent: :nullify/
197
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", on_delete: :nullify/
198
198
  end
199
199
 
200
200
  it "should not include foreign keys on ignored table names in schema dump" do
@@ -226,6 +226,7 @@ describe "OracleEnhancedAdapter schema dump" do
226
226
  end
227
227
 
228
228
  it "should include composite foreign keys" do
229
+ skip "Composite foreign keys are not supported in this version"
229
230
  schema_define do
230
231
  add_column :test_posts, :baz_id, :integer
231
232
  add_column :test_posts, :fooz_id, :integer
@@ -340,7 +341,7 @@ describe "OracleEnhancedAdapter schema dump" do
340
341
 
341
342
  it "should specify non-default tablespace in add index" do
342
343
  tablespace_name = @conn.default_tablespace
343
- @conn.stub!(:default_tablespace).and_return('dummy')
344
+ @conn.stub(:default_tablespace).and_return('dummy')
344
345
  create_test_posts_table
345
346
  standard_dump.should =~ /add_index "test_posts", \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/
346
347
  end
@@ -368,21 +369,18 @@ describe "OracleEnhancedAdapter schema dump" do
368
369
 
369
370
  describe 'virtual columns' do
370
371
  before(:all) do
371
- if @oracle11g_or_higher
372
- schema_define do
373
- create_table :test_names, :force => true do |t|
374
- t.string :first_name
375
- t.string :last_name
376
- t.virtual :full_name, :as => "first_name || ', ' || last_name"
377
- t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
378
- t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
379
- t.virtual :name_ratio, :as=>'(LENGTH(first_name)/LENGTH(last_name))'
380
- t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
381
- t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
382
- end
372
+ skip "Not supported in this database version" unless @oracle11g_or_higher
373
+ schema_define do
374
+ create_table :test_names, :force => true do |t|
375
+ t.string :first_name
376
+ t.string :last_name
377
+ t.virtual :full_name, :as => "first_name || ', ' || last_name"
378
+ t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
379
+ t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
380
+ t.virtual :name_ratio, :as => '(LENGTH(first_name)*10/LENGTH(last_name)*10)'
381
+ t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
382
+ t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
383
383
  end
384
- else
385
- pending "Not supported in this database version"
386
384
  end
387
385
  end
388
386
 
@@ -402,30 +400,13 @@ describe "OracleEnhancedAdapter schema dump" do
402
400
  end
403
401
  end
404
402
 
405
- context "when number_datatype_coercion is :float" do
406
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
407
-
408
- it 'should dump correctly' do
409
- standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
410
- standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
411
- standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)scale: 0,(\s*)as:(.*),(\s*)type: :integer/
412
- standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*),(\s*)type: :float$/
413
- standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
414
- standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
415
- end
416
- end
417
-
418
- context "when number_datatype_coercion is :decimal" do
419
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
420
-
421
- it 'should dump correctly' do
422
- standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
423
- standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
424
- standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)scale: 0,(\s*)as:(.*),(\s*)type: :integer/
425
- standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*)\"$/
426
- standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
427
- standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
428
- end
403
+ it 'should dump correctly' do
404
+ standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
405
+ standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
406
+ standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)as:(.*),(\s*)type: :integer/
407
+ standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*)\"$/ # no :type
408
+ standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
409
+ standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
429
410
  end
430
411
 
431
412
  context 'with column cache' do
@@ -471,160 +452,63 @@ describe "OracleEnhancedAdapter schema dump" do
471
452
  end
472
453
  end
473
454
 
474
- describe "NUMBER columns" do
475
- after(:each) do
455
+ describe ":float datatype" do
456
+ before(:each) do
476
457
  schema_define do
477
- drop_table "test_numbers"
478
- end
479
- end
480
-
481
- let(:value_within_max_precision) { (10 ** @conn.class::NUMBER_MAX_PRECISION) - 1 }
482
- let(:value_exceeding_max_precision) { (10 ** @conn.class::NUMBER_MAX_PRECISION) + 1 }
483
-
484
- context "when using ActiveRecord::Schema.define and ActiveRecord::ConnectionAdapters::TableDefinition#float" do
485
- before :each do
486
- schema_define do
487
- create_table :test_numbers, :force => true do |t|
488
- t.float :value
489
- end
458
+ create_table :test_floats, force: true do |t|
459
+ t.float :hourly_rate
490
460
  end
491
461
  end
462
+ end
492
463
 
493
- context "when number_datatype_coercion is :float" do
494
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
495
-
496
- it "should dump correctly" do
497
- standard_dump.should =~ /t\.float "value"$/
498
- end
464
+ after(:each) do
465
+ schema_define do
466
+ drop_table :test_floats
499
467
  end
468
+ end
500
469
 
501
- context "when number_datatype_coercion is :decimal" do
502
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
470
+ it "should dump float type correctly" do
471
+ standard_dump.should =~ /t\.float "hourly_rate"$/
472
+ end
473
+ end
503
474
 
504
- it "should dump correctly" do
505
- standard_dump.should =~ /t\.decimal "value"$/
475
+ describe "table comments" do
476
+ before(:each) do
477
+ schema_define do
478
+ create_table :test_table_comments, :comment => "this is a \"table comment\"!", force: true do |t|
479
+ t.string :blah
506
480
  end
507
481
  end
508
482
  end
509
483
 
510
- context "when using handwritten 'CREATE_TABLE' SQL" do
511
- before :each do
512
- ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
513
- @conn = ActiveRecord::Base.connection
514
- @conn.execute <<-SQL
515
- CREATE TABLE test_numbers (
516
- id NUMBER(#{@conn.class::NUMBER_MAX_PRECISION},0) PRIMARY KEY,
517
- value NUMBER
518
- )
519
- SQL
520
- @conn.execute <<-SQL
521
- CREATE SEQUENCE test_numbers_seq MINVALUE 1
522
- INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
523
- SQL
484
+ after(:each) do
485
+ schema_define do
486
+ drop_table :test_table_comments
524
487
  end
488
+ end
525
489
 
526
- context "when number_datatype_coercion is :float" do
527
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
528
-
529
- it "should dump correctly" do
530
- standard_dump.should =~ /t\.float "value"$/
531
- end
532
-
533
- describe "ActiveRecord saving" do
534
- before :each do
535
- class ::TestNumber < ActiveRecord::Base
536
- self.table_name = "test_numbers"
537
- end
538
- end
539
-
540
- it "should allow saving of values within NUMBER_MAX_PRECISION" do
541
- number = TestNumber.new(value: value_within_max_precision)
542
- number.save!
543
- number.reload
544
- number.value.should eq(value_within_max_precision)
545
- end
546
-
547
- it "should allow saving of values larger than NUMBER_MAX_PRECISION" do
548
- number = TestNumber.new(value: value_exceeding_max_precision)
549
- number.save!
550
- number.reload
551
- number.value.should eq(value_exceeding_max_precision)
552
- end
553
-
554
- it "should be recreatable from dump and have same properties" do
555
- # Simulating db:schema:dump & db:test:load
556
- 2.times do
557
- create_table_dump = standard_dump[/(create_table.+?end)/m]
558
-
559
- schema_define do
560
- drop_table "test_numbers"
561
- end
562
-
563
- schema_define(&eval("-> * { #{create_table_dump} }"))
564
- end
565
-
566
- number = TestNumber.new(value: value_within_max_precision)
567
- number.save!
490
+ it "should dump table comments" do
491
+ standard_dump.should =~ /comment: "this is a \\"table comment\\"!"/
492
+ end
493
+ end
568
494
 
569
- number2 = TestNumber.new(value: value_exceeding_max_precision)
570
- number2.save!
571
- end
495
+ describe "column comments" do
496
+ before(:each) do
497
+ schema_define do
498
+ create_table :test_column_comments, force: true do |t|
499
+ t.string :blah, :comment => "this is a \"column comment\"!"
572
500
  end
573
501
  end
502
+ end
574
503
 
575
- context "when number_datatype_coercion is :decimal" do
576
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
577
-
578
- it "should dump correctly" do
579
- standard_dump.should =~ /t\.decimal "value"$/
580
- end
581
-
582
- describe "ActiveRecord saving" do
583
- before :each do
584
- class ::TestNumber < ActiveRecord::Base
585
- self.table_name = "test_numbers"
586
- end
587
- end
588
-
589
- it "should allow saving of values within NUMBER_MAX_PRECISION" do
590
- number = TestNumber.new(value: value_within_max_precision)
591
- number.save!
592
- number.reload
593
- number.value.should eq(value_within_max_precision)
594
- end
595
-
596
- it "should allow saving of values larger than NUMBER_MAX_PRECISION" do
597
- number = TestNumber.new(value: value_exceeding_max_precision)
598
- number.save!
599
- number.reload
600
- number.value.should eq(value_exceeding_max_precision)
601
- end
602
-
603
- it "should be recreatable from dump and have same properties" do
604
- # Simulating db:schema:dump & db:test:load
605
- 2.times do |i|
606
- create_table_dump = standard_dump[/(create_table.+?end)/m]
607
-
608
- schema_define do
609
- drop_table "test_numbers"
610
- end
611
-
612
- schema_define(&eval("-> * { #{create_table_dump} }"))
613
- end
614
-
615
- number = TestNumber.new(value: value_within_max_precision)
616
- number.save!
617
-
618
- # Raises 'ORA-01438' as :value column type isn't FLOAT'ish
619
- number2 = TestNumber.new(value: value_exceeding_max_precision)
620
- lambda do
621
- number2.save!
622
- end.should raise_error() { |e| e.message.should =~ /ORA-01438/ }
623
- end
624
- end
625
- end # context (:decimal)
626
-
627
- end # context (handwritten)
628
- end # describe (NUMBER columns)
504
+ after(:each) do
505
+ schema_define do
506
+ drop_table :test_column_comments
507
+ end
508
+ end
629
509
 
510
+ it "should dump column comments" do
511
+ standard_dump.should =~ /comment: "this is a \\"column comment\\"!"/
512
+ end
513
+ end
630
514
  end
@@ -423,6 +423,7 @@ describe "OracleEnhancedAdapter schema definition" do
423
423
  drop_table :new_test_employees rescue nil
424
424
  drop_table :test_employees_no_pkey rescue nil
425
425
  drop_table :new_test_employees_no_pkey rescue nil
426
+ drop_table :aaaaaaaaaaaaaaaaaaaaaaaaaaa rescue nil
426
427
  end
427
428
  end
428
429
 
@@ -438,10 +439,10 @@ describe "OracleEnhancedAdapter schema definition" do
438
439
  end.should raise_error
439
440
  end
440
441
 
441
- it "should raise error when new sequence name length is too long" do
442
+ it "should not raise error when new sequence name length is too long" do
442
443
  lambda do
443
444
  @conn.rename_table("test_employees","a"*27)
444
- end.should raise_error
445
+ end.should_not raise_error
445
446
  end
446
447
 
447
448
  it "should rename table when table has no primary key and sequence" do
@@ -627,25 +628,28 @@ end
627
628
  end
628
629
 
629
630
  it "should add foreign key" do
631
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_test_post_id_fk").first(10)}"
632
+
630
633
  schema_define do
631
634
  add_foreign_key :test_comments, :test_posts
632
635
  end
633
636
  lambda do
634
637
  TestComment.create(:body => "test", :test_post_id => 1)
635
- end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.TEST_COMMENTS_TEST_POST_ID_FK/}
638
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
636
639
  end
637
640
 
638
641
  context "with table_name_prefix" do
639
642
  let(:table_name_prefix) { 'xxx_' }
640
643
 
641
644
  it "should use table_name_prefix for foreign table" do
645
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("xxx_test_comments_test_post_id_fk").first(10)}"
642
646
  schema_define do
643
647
  add_foreign_key :test_comments, :test_posts
644
648
  end
645
649
 
646
650
  lambda do
647
651
  TestComment.create(:body => "test", :test_post_id => 1)
648
- end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.XXX_TES_COM_TES_POS_ID_FK/}
652
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
649
653
  end
650
654
  end
651
655
 
@@ -653,13 +657,14 @@ end
653
657
  let(:table_name_suffix) { '_xxx' }
654
658
 
655
659
  it "should use table_name_suffix for foreign table" do
660
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_xxx_test_post_id_fk").first(10)}"
656
661
  schema_define do
657
662
  add_foreign_key :test_comments, :test_posts
658
663
  end
659
664
 
660
665
  lambda do
661
666
  TestComment.create(:body => "test", :test_post_id => 1)
662
- end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.TES_COM_XXX_TES_POS_ID_FK/}
667
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
663
668
  end
664
669
  end
665
670
 
@@ -678,7 +683,8 @@ end
678
683
  end
679
684
  lambda do
680
685
  TestComment.create(:body => "test", :test_post_id => 1)
681
- end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.TES_COM_TES_POS_ID_FOR_KEY/}
686
+ end.should raise_error() {|e| e.message.should =~
687
+ /ORA-02291.*\.C#{Digest::SHA1.hexdigest("test_comments_test_post_id_foreign_key")[0,29].upcase}/}
682
688
  end
683
689
 
684
690
  it "should add foreign key with very long name which is shortened" do
@@ -692,12 +698,14 @@ end
692
698
  end
693
699
 
694
700
  it "should add foreign key with column" do
701
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_post_id_fk").first(10)}"
702
+
695
703
  schema_define do
696
704
  add_foreign_key :test_comments, :test_posts, :column => "post_id"
697
705
  end
698
706
  lambda do
699
707
  TestComment.create(:body => "test", :post_id => 1)
700
- end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.TEST_COMMENTS_POST_ID_FK/}
708
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
701
709
  end
702
710
 
703
711
  it "should add foreign key with delete dependency" do
@@ -721,6 +729,7 @@ end
721
729
  end
722
730
 
723
731
  it "should add a composite foreign key" do
732
+ skip "Composite foreign keys are not supported in this version"
724
733
  schema_define do
725
734
  add_column :test_posts, :baz_id, :integer
726
735
  add_column :test_posts, :fooz_id, :integer
@@ -743,6 +752,7 @@ end
743
752
  end
744
753
 
745
754
  it "should add a composite foreign key with name" do
755
+ skip "Composite foreign keys are not supported in this version"
746
756
  schema_define do
747
757
  add_column :test_posts, :baz_id, :integer
748
758
  add_column :test_posts, :fooz_id, :integer
@@ -795,6 +805,92 @@ end
795
805
 
796
806
  end
797
807
 
808
+ describe "lob in table definition" do
809
+ before do
810
+ class ::TestPost < ActiveRecord::Base
811
+ end
812
+ end
813
+ it 'should use default tablespace for clobs' do
814
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
815
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = nil
816
+ schema_define do
817
+ create_table :test_posts, :force => true do |t|
818
+ t.text :test_clob
819
+ t.binary :test_blob
820
+ end
821
+ end
822
+ TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'").should == DATABASE_NON_DEFAULT_TABLESPACE
823
+ TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'").should_not == DATABASE_NON_DEFAULT_TABLESPACE
824
+ end
825
+
826
+ it 'should use default tablespace for blobs' do
827
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = DATABASE_NON_DEFAULT_TABLESPACE
828
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = nil
829
+ schema_define do
830
+ create_table :test_posts, :force => true do |t|
831
+ t.text :test_clob
832
+ t.binary :test_blob
833
+ end
834
+ end
835
+ TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'").should == DATABASE_NON_DEFAULT_TABLESPACE
836
+ TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'").should_not == DATABASE_NON_DEFAULT_TABLESPACE
837
+ end
838
+
839
+ after do
840
+ Object.send(:remove_const, "TestPost")
841
+ schema_define do
842
+ drop_table :test_posts rescue nil
843
+ end
844
+ end
845
+ end
846
+
847
+ describe "primary key in table definition" do
848
+ before do
849
+ @conn = ActiveRecord::Base.connection
850
+
851
+ class ::TestPost < ActiveRecord::Base
852
+ end
853
+ end
854
+
855
+ it 'should use default tablespace for primary key' do
856
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = nil
857
+ schema_define do
858
+ create_table :test_posts, :force => true
859
+ end
860
+
861
+ index_name = @conn.select_value(
862
+ "SELECT index_name FROM all_constraints
863
+ WHERE table_name = 'TEST_POSTS'
864
+ AND constraint_type = 'P'
865
+ AND owner = SYS_CONTEXT('userenv', 'current_schema')")
866
+
867
+ expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq('USERS')
868
+ end
869
+
870
+ it 'should use non default tablespace for primary key' do
871
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = DATABASE_NON_DEFAULT_TABLESPACE
872
+ schema_define do
873
+ create_table :test_posts, :force => true
874
+ end
875
+
876
+ index_name = @conn.select_value(
877
+ "SELECT index_name FROM all_constraints
878
+ WHERE table_name = 'TEST_POSTS'
879
+ AND constraint_type = 'P'
880
+ AND owner = SYS_CONTEXT('userenv', 'current_schema')")
881
+
882
+ expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
883
+ end
884
+
885
+ after do
886
+ Object.send(:remove_const, "TestPost")
887
+ schema_define do
888
+ drop_table :test_posts rescue nil
889
+ end
890
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = nil
891
+ end
892
+ end
893
+
798
894
  describe "foreign key in table definition" do
799
895
  before(:each) do
800
896
  schema_define do
@@ -1020,7 +1116,7 @@ end
1020
1116
  end
1021
1117
  end
1022
1118
  class ::TestPost < ActiveRecord::Base; end
1023
- TestPost.columns_hash['title'].null.should be_false
1119
+ TestPost.columns_hash['title'].null.should be false
1024
1120
  end
1025
1121
 
1026
1122
  after(:each) do
@@ -1034,7 +1130,7 @@ end
1034
1130
  change_column :test_posts, :title, :string, :null => true
1035
1131
  end
1036
1132
  TestPost.reset_column_information
1037
- TestPost.columns_hash['title'].null.should be_true
1133
+ TestPost.columns_hash['title'].null.should be true
1038
1134
  end
1039
1135
 
1040
1136
  it "should add column" do
@@ -1110,7 +1206,7 @@ end
1110
1206
 
1111
1207
  describe 'virtual columns in create_table' do
1112
1208
  before(:each) do
1113
- pending "Not supported in this database version" unless @oracle11g_or_higher
1209
+ skip "Not supported in this database version" unless @oracle11g_or_higher
1114
1210
  end
1115
1211
 
1116
1212
  it 'should create virtual column with old syntax' do
@@ -1156,7 +1252,7 @@ end
1156
1252
 
1157
1253
  describe 'virtual columns' do
1158
1254
  before(:each) do
1159
- pending "Not supported in this database version" unless @oracle11g_or_higher
1255
+ skip "Not supported in this database version" unless @oracle11g_or_higher
1160
1256
  expr = "( numerator/NULLIF(denominator,0) )*100"
1161
1257
  schema_define do
1162
1258
  create_table :test_fractions, :force => true do |t|
@@ -1359,6 +1455,13 @@ end
1359
1455
  @would_execute_sql.should =~ /CREATE +INDEX .* ON .* \(.*\) TABLESPACE #{DATABASE_NON_DEFAULT_TABLESPACE}/
1360
1456
  end
1361
1457
 
1458
+ it "should create unique function index but not create unique constraints" do
1459
+ schema_define do
1460
+ add_index :keyboards, 'lower(name)', unique: true, name: :index_keyboards_on_lower_name
1461
+ end
1462
+ @would_execute_sql.should_not =~ /ALTER +TABLE .* ADD CONSTRAINT .* UNIQUE \(.*\(.*\)\)/
1463
+ end
1464
+
1362
1465
  describe "#initialize_schema_migrations_table" do
1363
1466
  # In Rails 2.3 to 3.2.x the index name for the migrations
1364
1467
  # table is hard-coded. We can modify the index name here
@@ -92,6 +92,7 @@ describe "OracleEnhancedAdapter structure dump" do
92
92
  end
93
93
 
94
94
  it "should dump composite foreign keys" do
95
+ skip "Composite foreign keys are not supported in this version"
95
96
  @conn.add_column :foos, :fooz_id, :integer
96
97
  @conn.add_column :foos, :baz_id, :integer
97
98
 
@@ -149,7 +150,7 @@ describe "OracleEnhancedAdapter structure dump" do
149
150
  end
150
151
 
151
152
  it "should dump virtual columns" do
152
- pending "Not supported in this database version" unless @oracle11g_or_higher
153
+ skip "Not supported in this database version" unless @oracle11g_or_higher
153
154
  @conn.execute <<-SQL
154
155
  CREATE TABLE bars (
155
156
  id NUMBER(38,0) NOT NULL,
@@ -162,6 +163,7 @@ describe "OracleEnhancedAdapter structure dump" do
162
163
  end
163
164
 
164
165
  it "should dump RAW virtual columns" do
166
+ skip "Not supported in this database version" unless @oracle11g_or_higher
165
167
  @conn.execute <<-SQL
166
168
  CREATE TABLE bars (
167
169
  id NUMBER(38,0) NOT NULL,
@@ -224,6 +226,20 @@ describe "OracleEnhancedAdapter structure dump" do
224
226
  dump.should =~ /CREATE TABLE \"BARS\" \(\n\"ID\" NUMBER\(38,0\) NOT NULL,\n \"SUPER\" RAW\(255\)/
225
227
  end
226
228
 
229
+ it "should dump table comments" do
230
+ comment_sql = %Q(COMMENT ON TABLE "TEST_POSTS" IS 'Test posts with ''some'' "quotes"')
231
+ @conn.execute comment_sql
232
+ dump = ActiveRecord::Base.connection.structure_dump
233
+ dump.should =~ /#{comment_sql}/
234
+ end
235
+
236
+ it "should dump column comments" do
237
+ comment_sql = %Q(COMMENT ON COLUMN "TEST_POSTS"."TITLE" IS 'The title of the post with ''some'' "quotes"')
238
+ @conn.execute comment_sql
239
+ dump = ActiveRecord::Base.connection.structure_dump
240
+ dump.should =~ /#{comment_sql}/
241
+ end
242
+
227
243
  end
228
244
  describe "temporary tables" do
229
245
  after(:all) do
@@ -0,0 +1,11 @@
1
+ # copy this file to spec/config.yaml and set appropriate values
2
+ # you can also use environment variables, see spec_helper.rb
3
+ database:
4
+ name: 'orcl'
5
+ host: '127.0.0.1'
6
+ port: 1521
7
+ user: 'oracle_enhanced'
8
+ password: 'oracle_enhanced'
9
+ sys_password: 'admin'
10
+ non_default_tablespace: 'SYSTEM'
11
+ timezone: 'Europe/Riga'