pmacs-activerecord-oracle_enhanced-adapter 1.5.6.1 → 1.6.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -7
  3. data/History.md +126 -0
  4. data/README.md +285 -178
  5. data/Rakefile +1 -1
  6. data/VERSION +1 -1
  7. data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
  8. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +65 -0
  9. data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
  10. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
  11. data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +257 -0
  13. data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.rb} +0 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
  15. data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +0 -0
  16. data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +0 -0
  17. data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +1 -3
  18. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +34 -35
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +95 -0
  20. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +4 -32
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +548 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +74 -0
  23. data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +28 -6
  24. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +161 -68
  26. data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
  27. data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
  28. data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
  29. data/lib/pmacs-activerecord-oracle_enhanced-adapter.rb +1 -1
  30. data/pmacs-activerecord-oracle_enhanced-adapter.gemspec +35 -31
  31. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +6 -31
  32. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +1 -1
  33. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +2 -2
  34. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +2 -2
  35. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +75 -63
  36. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +1 -1
  37. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +7 -13
  38. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +2 -1
  39. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +25 -178
  40. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +60 -5
  41. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +1 -0
  42. data/spec/spec_helper.rb +21 -10
  43. metadata +32 -28
  44. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
  45. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
  46. data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
  47. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
  48. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -223
  49. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
  50. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -267
  51. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'active_record/connection_adapters/oracle_enhanced_database_tasks'
2
+ require 'active_record/connection_adapters/oracle_enhanced/database_tasks'
3
3
  require 'stringio'
4
4
  require 'tempfile'
5
5
 
@@ -16,7 +16,6 @@ if ActiveRecord::Base.method_defined?(:changed?)
16
16
  last_name VARCHAR2(25),
17
17
  job_id NUMBER(6,0) NULL,
18
18
  salary NUMBER(8,2),
19
- pto_per_hour NUMBER,
20
19
  comments CLOB,
21
20
  hire_date DATE
22
21
  )
@@ -28,7 +27,7 @@ if ActiveRecord::Base.method_defined?(:changed?)
28
27
  class TestEmployee < ActiveRecord::Base
29
28
  end
30
29
  end
31
-
30
+
32
31
  after(:all) do
33
32
  Object.send(:remove_const, "TestEmployee")
34
33
  @conn.execute "DROP TABLE test_employees"
@@ -63,16 +62,6 @@ if ActiveRecord::Base.method_defined?(:changed?)
63
62
  @employee.should_not be_changed
64
63
  end
65
64
 
66
- it "should not mark empty float (stored as NULL) as changed when reassigning it" do
67
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion) { :float }
68
- @employee = TestEmployee.create!(:pto_per_hour => '')
69
- @employee.pto_per_hour = ''
70
- @employee.should_not be_changed
71
- @employee.reload
72
- @employee.pto_per_hour = ''
73
- @employee.should_not be_changed
74
- end
75
-
76
65
  it "should not mark empty text (stored as NULL) as changed when reassigning it" do
77
66
  @employee = TestEmployee.create!(:comments => nil)
78
67
  @employee.comments = nil
@@ -122,7 +111,7 @@ if ActiveRecord::Base.method_defined?(:changed?)
122
111
  @employee = TestEmployee.new
123
112
  @employee.job_id = 0
124
113
  @employee.save!.should be_true
125
-
114
+
126
115
  @employee.should_not be_changed
127
116
 
128
117
  @employee.job_id = '0'
@@ -147,6 +136,11 @@ if ActiveRecord::Base.method_defined?(:changed?)
147
136
  end
148
137
  end
149
138
 
139
+ it "should be able to handle attributes which are not backed by a column" do
140
+ TestEmployee.create!(:comments => "initial")
141
+ @employee = TestEmployee.select("#{TestEmployee.quoted_table_name}.*, 24 ranking").first
142
+ expect { @employee.ranking = 25 }.to_not raise_error
143
+ end
150
144
  end
151
145
 
152
146
  end
@@ -325,7 +325,8 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
325
325
  :last_name => "Last",
326
326
  :hire_date => @today
327
327
  )
328
- @logger.logged(:debug).last.should match(/^TestEmployee Create \(\d+\.\d+(ms)?\) custom create method$/)
328
+ #TODO: dirty workaround to remove sql statement for `table` method
329
+ @logger.logged(:debug)[-2].should match(/^TestEmployee Create \(\d+\.\d+(ms)?\) custom create method$/)
329
330
  clear_logger
330
331
  end
331
332
 
@@ -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
+ pending "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
@@ -376,7 +377,7 @@ describe "OracleEnhancedAdapter schema dump" do
376
377
  t.virtual :full_name, :as => "first_name || ', ' || last_name"
377
378
  t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
378
379
  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.virtual :name_ratio, :as=>'(LENGTH(first_name)*10/LENGTH(last_name)*10)'
380
381
  t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
381
382
  t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
382
383
  end
@@ -402,30 +403,13 @@ describe "OracleEnhancedAdapter schema dump" do
402
403
  end
403
404
  end
404
405
 
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
406
+ it 'should dump correctly' do
407
+ standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
408
+ standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
409
+ standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)as:(.*),(\s*)type: :integer/
410
+ standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*)\"$/ # no :type
411
+ standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
412
+ standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
429
413
  end
430
414
 
431
415
  context 'with column cache' do
@@ -471,160 +455,23 @@ describe "OracleEnhancedAdapter schema dump" do
471
455
  end
472
456
  end
473
457
 
474
- describe "NUMBER columns" do
475
- after(:each) do
458
+ describe ":float datatype" do
459
+ before(:each) do
476
460
  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
490
- end
491
- end
492
-
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
499
- end
500
-
501
- context "when number_datatype_coercion is :decimal" do
502
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
503
-
504
- it "should dump correctly" do
505
- standard_dump.should =~ /t\.decimal "value"$/
461
+ create_table :test_floats, force: true do |t|
462
+ t.float :hourly_rate
506
463
  end
507
464
  end
508
465
  end
509
466
 
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
524
- end
525
-
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!
568
-
569
- number2 = TestNumber.new(value: value_exceeding_max_precision)
570
- number2.save!
571
- end
572
- end
467
+ after(:each) do
468
+ schema_define do
469
+ drop_table :test_floats
573
470
  end
471
+ end
574
472
 
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)
629
-
473
+ it "should dump float type correctly" do
474
+ standard_dump.should =~ /t\.float "hourly_rate"$/
475
+ end
476
+ end
630
477
  end
@@ -627,25 +627,28 @@ end
627
627
  end
628
628
 
629
629
  it "should add foreign key" do
630
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_test_post_id_fk").first(10)}"
631
+
630
632
  schema_define do
631
633
  add_foreign_key :test_comments, :test_posts
632
634
  end
633
635
  lambda do
634
636
  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/}
637
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
636
638
  end
637
639
 
638
640
  context "with table_name_prefix" do
639
641
  let(:table_name_prefix) { 'xxx_' }
640
642
 
641
643
  it "should use table_name_prefix for foreign table" do
644
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("xxx_test_comments_test_post_id_fk").first(10)}"
642
645
  schema_define do
643
646
  add_foreign_key :test_comments, :test_posts
644
647
  end
645
648
 
646
649
  lambda do
647
650
  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/}
651
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
649
652
  end
650
653
  end
651
654
 
@@ -653,13 +656,14 @@ end
653
656
  let(:table_name_suffix) { '_xxx' }
654
657
 
655
658
  it "should use table_name_suffix for foreign table" do
659
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_xxx_test_post_id_fk").first(10)}"
656
660
  schema_define do
657
661
  add_foreign_key :test_comments, :test_posts
658
662
  end
659
663
 
660
664
  lambda do
661
665
  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/}
666
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
663
667
  end
664
668
  end
665
669
 
@@ -678,7 +682,8 @@ end
678
682
  end
679
683
  lambda do
680
684
  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/}
685
+ end.should raise_error() {|e| e.message.should =~
686
+ /ORA-02291.*\.C#{Digest::SHA1.hexdigest("test_comments_test_post_id_foreign_key")[0,29].upcase}/}
682
687
  end
683
688
 
684
689
  it "should add foreign key with very long name which is shortened" do
@@ -692,12 +697,14 @@ end
692
697
  end
693
698
 
694
699
  it "should add foreign key with column" do
700
+ fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_post_id_fk").first(10)}"
701
+
695
702
  schema_define do
696
703
  add_foreign_key :test_comments, :test_posts, :column => "post_id"
697
704
  end
698
705
  lambda do
699
706
  TestComment.create(:body => "test", :post_id => 1)
700
- end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.TEST_COMMENTS_POST_ID_FK/}
707
+ end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
701
708
  end
702
709
 
703
710
  it "should add foreign key with delete dependency" do
@@ -721,6 +728,7 @@ end
721
728
  end
722
729
 
723
730
  it "should add a composite foreign key" do
731
+ pending "Composite foreign keys are not supported in this version"
724
732
  schema_define do
725
733
  add_column :test_posts, :baz_id, :integer
726
734
  add_column :test_posts, :fooz_id, :integer
@@ -743,6 +751,7 @@ end
743
751
  end
744
752
 
745
753
  it "should add a composite foreign key with name" do
754
+ pending "Composite foreign keys are not supported in this version"
746
755
  schema_define do
747
756
  add_column :test_posts, :baz_id, :integer
748
757
  add_column :test_posts, :fooz_id, :integer
@@ -795,6 +804,45 @@ end
795
804
 
796
805
  end
797
806
 
807
+ describe "lob in table definition" do
808
+ before do
809
+ class ::TestPost < ActiveRecord::Base
810
+ end
811
+ end
812
+ it 'should use default tablespace for clobs' do
813
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
814
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = nil
815
+ schema_define do
816
+ create_table :test_posts, :force => true do |t|
817
+ t.text :test_clob
818
+ t.binary :test_blob
819
+ end
820
+ end
821
+ 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
822
+ 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
823
+ end
824
+
825
+ it 'should use default tablespace for blobs' do
826
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = DATABASE_NON_DEFAULT_TABLESPACE
827
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = nil
828
+ schema_define do
829
+ create_table :test_posts, :force => true do |t|
830
+ t.text :test_clob
831
+ t.binary :test_blob
832
+ end
833
+ end
834
+ 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
835
+ 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
836
+ end
837
+
838
+ after do
839
+ Object.send(:remove_const, "TestPost")
840
+ schema_define do
841
+ drop_table :test_posts rescue nil
842
+ end
843
+ end
844
+ end
845
+
798
846
  describe "foreign key in table definition" do
799
847
  before(:each) do
800
848
  schema_define do
@@ -1359,6 +1407,13 @@ end
1359
1407
  @would_execute_sql.should =~ /CREATE +INDEX .* ON .* \(.*\) TABLESPACE #{DATABASE_NON_DEFAULT_TABLESPACE}/
1360
1408
  end
1361
1409
 
1410
+ it "should create unique function index but not create unique constraints" do
1411
+ schema_define do
1412
+ add_index :keyboards, 'lower(name)', unique: true, name: :index_keyboards_on_lower_name
1413
+ end
1414
+ @would_execute_sql.should_not =~ /ALTER +TABLE .* ADD CONSTRAINT .* UNIQUE \(.*\(.*\)\)/
1415
+ end
1416
+
1362
1417
  describe "#initialize_schema_migrations_table" do
1363
1418
  # In Rails 2.3 to 3.2.x the index name for the migrations
1364
1419
  # table is hard-coded. We can modify the index name here