activerecord-oracle_enhanced-adapter 5.2.8 → 7.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +390 -21
  3. data/README.md +35 -8
  4. data/VERSION +1 -1
  5. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
  6. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +3 -3
  7. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +42 -37
  8. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +59 -60
  9. data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +5 -10
  10. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +86 -81
  11. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +9 -10
  12. data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +1 -2
  13. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +37 -16
  14. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +1 -1
  15. data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +5 -6
  16. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +58 -49
  17. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +1 -1
  18. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +6 -7
  19. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +75 -51
  20. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +13 -14
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +14 -4
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +27 -24
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +156 -155
  24. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +103 -90
  25. data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +3 -2
  26. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +261 -161
  27. data/lib/active_record/type/oracle_enhanced/boolean.rb +0 -1
  28. data/lib/active_record/type/oracle_enhanced/character_string.rb +36 -0
  29. data/lib/active_record/type/oracle_enhanced/integer.rb +0 -1
  30. data/lib/arel/visitors/oracle.rb +221 -0
  31. data/lib/arel/visitors/oracle12.rb +128 -0
  32. data/spec/active_record/connection_adapters/emulation/oracle_adapter_spec.rb +0 -2
  33. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +78 -26
  34. data/spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb +7 -15
  35. data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +5 -0
  36. data/spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb +17 -17
  37. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +7 -10
  38. data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +0 -15
  39. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +33 -36
  40. data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +77 -258
  41. data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +38 -39
  42. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +273 -85
  43. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +7 -8
  44. data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +2 -4
  45. data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +43 -0
  46. data/spec/active_record/oracle_enhanced/type/custom_spec.rb +90 -0
  47. data/spec/active_record/oracle_enhanced/type/decimal_spec.rb +56 -0
  48. data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +1 -1
  49. data/spec/active_record/oracle_enhanced/type/integer_spec.rb +2 -2
  50. data/spec/active_record/oracle_enhanced/type/json_spec.rb +0 -1
  51. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +6 -5
  52. data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +2 -4
  53. data/spec/spec_config.yaml.template +2 -2
  54. data/spec/spec_helper.rb +13 -2
  55. metadata +52 -30
  56. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +0 -28
@@ -59,7 +59,6 @@ describe "OracleEnhancedAdapter" do
59
59
  end
60
60
 
61
61
  describe "without column caching" do
62
-
63
62
  it "should identify virtual columns as such" do
64
63
  skip "Not supported in this database version" unless @conn.supports_virtual_columns?
65
64
  te = TestEmployee.connection.columns("test_employees").detect(&:virtual?)
@@ -100,64 +99,14 @@ describe "OracleEnhancedAdapter" do
100
99
 
101
100
  it "should get sequence value at next time" do
102
101
  TestEmployee.create!
103
- expect(@logger.logged(:debug).first).not_to match(/SELECT \"TEST_EMPLOYEES_SEQ\".NEXTVAL FROM dual/im)
102
+ expect(@logger.logged(:debug).first).not_to match(/SELECT "TEST_EMPLOYEES_SEQ".NEXTVAL FROM dual/im)
104
103
  @logger.clear(:debug)
105
104
  TestEmployee.create!
106
- expect(@logger.logged(:debug).first).to match(/SELECT \"TEST_EMPLOYEES_SEQ\".NEXTVAL FROM dual/im)
105
+ expect(@logger.logged(:debug).first).to match(/SELECT "TEST_EMPLOYEES_SEQ".NEXTVAL FROM dual/im)
107
106
  end
108
107
  end
109
108
  end
110
109
 
111
- describe "access table over database link" do
112
- before(:all) do
113
- @conn = ActiveRecord::Base.connection
114
- @db_link = "db_link"
115
- @sys_conn = ActiveRecord::Base.oracle_enhanced_connection(SYSTEM_CONNECTION_PARAMS)
116
- @sys_conn.drop_table :test_posts, if_exists: true
117
- @sys_conn.create_table :test_posts do |t|
118
- t.string :title
119
- # cannot update LOBs over database link
120
- t.string :body
121
- t.timestamps null: true
122
- end
123
- @db_link_username = SYSTEM_CONNECTION_PARAMS[:username]
124
- @db_link_password = SYSTEM_CONNECTION_PARAMS[:password]
125
- @db_link_database = SYSTEM_CONNECTION_PARAMS[:database]
126
- @conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
127
- @conn.execute "CREATE DATABASE LINK #{@db_link} CONNECT TO #{@db_link_username} IDENTIFIED BY \"#{@db_link_password}\" USING '#{@db_link_database}'"
128
- @conn.execute "CREATE OR REPLACE SYNONYM test_posts FOR test_posts@#{@db_link}"
129
- @conn.execute "CREATE OR REPLACE SYNONYM test_posts_seq FOR test_posts_seq@#{@db_link}"
130
- class ::TestPost < ActiveRecord::Base
131
- end
132
- TestPost.table_name = "test_posts"
133
- end
134
-
135
- after(:all) do
136
- @conn.execute "DROP SYNONYM test_posts"
137
- @conn.execute "DROP SYNONYM test_posts_seq"
138
- @conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
139
- @sys_conn.drop_table :test_posts, if_exists: true
140
- Object.send(:remove_const, "TestPost") rescue nil
141
- @conn.clear_table_columns_cache(:test_posts)
142
- ActiveRecord::Base.clear_cache!
143
- end
144
-
145
- it "should verify database link" do
146
- @conn.select_value("select * from dual@#{@db_link}") == "X"
147
- end
148
-
149
- it "should get column names" do
150
- expect(TestPost.column_names).to eq(["id", "title", "body", "created_at", "updated_at"])
151
- end
152
-
153
- it "should create record" do
154
- p = TestPost.create(title: "Title", body: "Body")
155
- expect(p.id).not_to be_nil
156
- expect(TestPost.find(p.id)).not_to be_nil
157
- end
158
-
159
- end
160
-
161
110
  describe "session information" do
162
111
  before(:all) do
163
112
  @conn = ActiveRecord::Base.connection
@@ -201,6 +150,45 @@ describe "OracleEnhancedAdapter" do
201
150
  end
202
151
  end
203
152
 
153
+ describe "`has_many` assoc has `dependent: :delete_all` with `order`" do
154
+ before(:all) do
155
+ schema_define do
156
+ create_table :test_posts do |t|
157
+ t.string :title
158
+ end
159
+ create_table :test_comments do |t|
160
+ t.integer :test_post_id
161
+ t.string :description
162
+ end
163
+ add_index :test_comments, :test_post_id
164
+ end
165
+ class ::TestPost < ActiveRecord::Base
166
+ has_many :test_comments, -> { order(:id) }, dependent: :delete_all
167
+ end
168
+ class ::TestComment < ActiveRecord::Base
169
+ belongs_to :test_post
170
+ end
171
+ TestPost.transaction do
172
+ post = TestPost.create!(title: "Title")
173
+ TestComment.create!(test_post_id: post.id, description: "Description")
174
+ end
175
+ end
176
+
177
+ after(:all) do
178
+ schema_define do
179
+ drop_table :test_comments
180
+ drop_table :test_posts
181
+ end
182
+ Object.send(:remove_const, "TestPost")
183
+ Object.send(:remove_const, "TestComment")
184
+ ActiveRecord::Base.clear_cache!
185
+ end
186
+
187
+ it "should not occur `ActiveRecord::StatementInvalid: OCIError: ORA-00907: missing right parenthesis`" do
188
+ expect { TestPost.first.destroy }.not_to raise_error
189
+ end
190
+ end
191
+
204
192
  describe "eager loading" do
205
193
  before(:all) do
206
194
  schema_define do
@@ -242,7 +230,46 @@ describe "OracleEnhancedAdapter" do
242
230
  posts = TestPost.includes(:test_comments).to_a
243
231
  expect(posts.size).to eq(@ids.size)
244
232
  end
233
+ end
234
+
235
+ describe "lists" do
236
+ before(:all) do
237
+ schema_define do
238
+ create_table :test_posts do |t|
239
+ t.string :title
240
+ end
241
+ end
242
+ class ::TestPost < ActiveRecord::Base
243
+ has_many :test_comments
244
+ end
245
+ @ids = (1..1010).to_a
246
+ TestPost.transaction do
247
+ @ids.each do |id|
248
+ TestPost.create!(id: id, title: "Title #{id}")
249
+ end
250
+ end
251
+ end
245
252
 
253
+ after(:all) do
254
+ schema_define do
255
+ drop_table :test_posts
256
+ end
257
+ Object.send(:remove_const, "TestPost")
258
+ ActiveRecord::Base.clear_cache!
259
+ end
260
+
261
+ ##
262
+ # See this GitHub issue for an explanation of homogenous lists.
263
+ # https://github.com/rails/rails/commit/72fd0bae5948c1169411941aeea6fef4c58f34a9
264
+ it "should allow more than 1000 items in a list where the list is homogenous" do
265
+ posts = TestPost.where(id: @ids).to_a
266
+ expect(posts.size).to eq(@ids.size)
267
+ end
268
+
269
+ it "should allow more than 1000 items in a list where the list is non-homogenous" do
270
+ posts = TestPost.where(id: [*@ids, nil]).to_a
271
+ expect(posts.size).to eq(@ids.size)
272
+ end
246
273
  end
247
274
 
248
275
  describe "with statement pool" do
@@ -296,6 +323,14 @@ describe "OracleEnhancedAdapter" do
296
323
  end
297
324
  end
298
325
 
326
+ describe "database_exists?" do
327
+ it "should raise `NotImplementedError`" do
328
+ expect {
329
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.database_exists?(CONNECTION_PARAMS)
330
+ }.to raise_error(NotImplementedError)
331
+ end
332
+ end
333
+
299
334
  describe "explain" do
300
335
  before(:all) do
301
336
  @conn = ActiveRecord::Base.connection
@@ -343,12 +378,11 @@ describe "OracleEnhancedAdapter" do
343
378
  @employee = Class.new(ActiveRecord::Base) do
344
379
  self.table_name = :test_employees
345
380
  end
346
- i = 0
347
- @employee.create!(sort_order: i += 1, first_name: "Peter", last_name: "Parker")
348
- @employee.create!(sort_order: i += 1, first_name: "Tony", last_name: "Stark")
349
- @employee.create!(sort_order: i += 1, first_name: "Steven", last_name: "Rogers")
350
- @employee.create!(sort_order: i += 1, first_name: "Bruce", last_name: "Banner")
351
- @employee.create!(sort_order: i += 1, first_name: "Natasha", last_name: "Romanova")
381
+ @employee.create!(sort_order: 1, first_name: "Peter", last_name: "Parker")
382
+ @employee.create!(sort_order: 2, first_name: "Tony", last_name: "Stark")
383
+ @employee.create!(sort_order: 3, first_name: "Steven", last_name: "Rogers")
384
+ @employee.create!(sort_order: 4, first_name: "Bruce", last_name: "Banner")
385
+ @employee.create!(sort_order: 5, first_name: "Natasha", last_name: "Romanova")
352
386
  end
353
387
 
354
388
  after(:all) do
@@ -445,6 +479,45 @@ describe "OracleEnhancedAdapter" do
445
479
  end
446
480
  end
447
481
 
482
+ describe "Binary lob column" do
483
+ before(:all) do
484
+ schema_define do
485
+ create_table :test_binary_columns do |t|
486
+ t.binary :attachment
487
+ end
488
+ end
489
+ class ::TestBinaryColumn < ActiveRecord::Base
490
+ end
491
+ end
492
+
493
+ after(:all) do
494
+ schema_define do
495
+ drop_table :test_binary_columns
496
+ end
497
+ Object.send(:remove_const, "TestBinaryColumn")
498
+ ActiveRecord::Base.table_name_prefix = nil
499
+ ActiveRecord::Base.clear_cache!
500
+ end
501
+
502
+ before(:each) do
503
+ set_logger
504
+ end
505
+
506
+ after(:each) do
507
+ clear_logger
508
+ end
509
+
510
+ it "should serialize with non UTF-8 data" do
511
+ binary_value = +"Hello \x93\xfa\x96\x7b"
512
+ binary_value.force_encoding "UTF-8"
513
+
514
+ binary_column_object = TestBinaryColumn.new
515
+ binary_column_object.attachment = binary_value
516
+
517
+ expect(binary_column_object.save!).to eq(true)
518
+ end
519
+ end
520
+
448
521
  describe "quoting" do
449
522
  before(:all) do
450
523
  schema_define do
@@ -504,9 +577,29 @@ describe "OracleEnhancedAdapter" do
504
577
  schema_define do
505
578
  drop_table :test_posts, if_exists: true
506
579
  create_table :test_posts
580
+
581
+ drop_table :users, if_exists: true
582
+ create_table :users, force: true do |t|
583
+ t.string :name
584
+ t.integer :group_id
585
+ end
586
+
587
+ drop_table :groups, if_exists: true
588
+ create_table :groups, force: true do |t|
589
+ t.string :name
590
+ end
507
591
  end
592
+
508
593
  class ::TestPost < ActiveRecord::Base
509
594
  end
595
+
596
+ class User < ActiveRecord::Base
597
+ belongs_to :group
598
+ end
599
+
600
+ class Group < ActiveRecord::Base
601
+ has_one :user
602
+ end
510
603
  end
511
604
 
512
605
  before(:each) do
@@ -521,6 +614,8 @@ describe "OracleEnhancedAdapter" do
521
614
  after(:all) do
522
615
  schema_define do
523
616
  drop_table :test_posts
617
+ drop_table :users
618
+ drop_table :groups
524
619
  end
525
620
  Object.send(:remove_const, "TestPost")
526
621
  ActiveRecord::Base.clear_cache!
@@ -532,43 +627,37 @@ describe "OracleEnhancedAdapter" do
532
627
  end
533
628
 
534
629
  it "should return array from indexes with bind usage" do
535
- expect(@conn.indexes("TEST_POSTS").class).to eq Array
536
- expect(@logger.logged(:debug).last).to match(/:owner/)
537
- expect(@logger.logged(:debug).last).to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["owner", "#{DATABASE_USER.upcase}"\], \["table_name", "TEST_POSTS"\]\]/)
538
- end
539
-
540
- it "should not have primary key trigger with bind usage" do
541
- expect(@conn.has_primary_key_trigger?("TEST_POSTS")).to eq false
542
- expect(@logger.logged(:debug).last).to match(/:owner/)
543
- expect(@logger.logged(:debug).last).to match(/:table_name/)
544
- expect(@logger.logged(:debug).last).to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["trigger_name", "TEST_POSTS_PKT"\], \["owner", "#{DATABASE_USER.upcase}"\], \["table_name", "TEST_POSTS"\]\]/)
545
- end
630
+ expect(@conn.indexes("TEST_POSTS").class).to eq Array
631
+ expect(@logger.logged(:debug).last).to match(/:table_name/)
632
+ expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_POSTS"\]/)
633
+ end
546
634
 
547
- it "should return content from columns without bind usage" do
635
+ it "should return content from columns witt bind usage" do
548
636
  expect(@conn.columns("TEST_POSTS").length).to be > 0
549
- expect(@logger.logged(:debug).last).not_to match(/:owner/)
550
- expect(@logger.logged(:debug).last).not_to match(/:table_name/)
551
- expect(@logger.logged(:debug).last).not_to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["table_name", "TEST_POSTS"\]\]/)
637
+ expect(@logger.logged(:debug).last).to match(/:table_name/)
638
+ expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_POSTS"\]/)
552
639
  end
553
640
 
554
- it "should return pk and sequence from pk_and_sequence_for without bind usage" do
641
+ it "should return pk and sequence from pk_and_sequence_for with bind usage" do
555
642
  expect(@conn.pk_and_sequence_for("TEST_POSTS").length).to eq 2
556
- expect(@logger.logged(:debug).last).not_to match(/:owner/)
557
- expect(@logger.logged(:debug).last).not_to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["table_name", "TEST_POSTS"\]\]/)
643
+ expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_POSTS"\]/)
558
644
  end
559
645
 
560
646
  it "should return pk from primary_keys with bind usage" do
561
647
  expect(@conn.primary_keys("TEST_POSTS")).to eq ["id"]
562
- expect(@logger.logged(:debug).last).to match(/:owner/)
563
- expect(@logger.logged(:debug).last).to match(/\[\["owner", "#{DATABASE_USER.upcase}"\], \["table_name", "TEST_POSTS"\]\]/)
648
+ expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_POSTS"\]/)
649
+ end
650
+
651
+ it "should not raise missing IN/OUT parameter like issue 1687 " do
652
+ # "to_sql" enforces unprepared_statement including dictionary access SQLs
653
+ expect { User.joins(:group).to_sql }.not_to raise_exception
564
654
  end
565
655
 
566
656
  it "should return false from temporary_table? with bind usage" do
567
657
  expect(@conn.temporary_table?("TEST_POSTS")).to eq false
568
658
  expect(@logger.logged(:debug).last).to match(/:table_name/)
569
- expect(@logger.logged(:debug).last).to match(/\[\["table_name", "TEST_POSTS"\]\]/)
659
+ expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_POSTS"\]/)
570
660
  end
571
-
572
661
  end
573
662
 
574
663
  describe "Transaction" do
@@ -580,7 +669,7 @@ describe "OracleEnhancedAdapter" do
580
669
  end
581
670
  class ::TestPost < ActiveRecord::Base
582
671
  end
583
- Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception if Thread.respond_to?(:report_on_exception)
672
+ Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception
584
673
  end
585
674
 
586
675
  it "Raises Deadlocked when a deadlock is encountered" do
@@ -595,7 +684,7 @@ describe "OracleEnhancedAdapter" do
595
684
  TestPost.transaction do
596
685
  t1.lock!
597
686
  barrier.wait
598
- t2.update_attributes(title: "one")
687
+ t2.update(title: "one")
599
688
  end
600
689
  end
601
690
 
@@ -603,7 +692,7 @@ describe "OracleEnhancedAdapter" do
603
692
  TestPost.transaction do
604
693
  t2.lock!
605
694
  barrier.wait
606
- t1.update_attributes(title: "two")
695
+ t1.update(title: "two")
607
696
  end
608
697
  ensure
609
698
  thread.join
@@ -617,7 +706,106 @@ describe "OracleEnhancedAdapter" do
617
706
  end
618
707
  Object.send(:remove_const, "TestPost") rescue nil
619
708
  ActiveRecord::Base.clear_cache!
620
- Thread.report_on_exception = @original_report_on_exception if Thread.respond_to?(:report_on_exception)
709
+ Thread.report_on_exception = @original_report_on_exception
710
+ end
711
+ end
712
+
713
+ describe "Sequence" do
714
+ before(:all) do
715
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
716
+ @conn = ActiveRecord::Base.connection
717
+ schema_define do
718
+ create_table :table_with_name_thats_just_ok,
719
+ sequence_name: "suitably_short_seq", force: true do |t|
720
+ t.column :foo, :string, null: false
721
+ end
722
+ end
723
+ end
724
+ after(:all) do
725
+ schema_define do
726
+ drop_table :table_with_name_thats_just_ok,
727
+ sequence_name: "suitably_short_seq" rescue nil
728
+ end
729
+ end
730
+ it "should create table with custom sequence name" do
731
+ expect(@conn.select_value("select suitably_short_seq.nextval from dual")).to eq(1)
732
+ end
733
+ end
734
+
735
+ describe "Hints" do
736
+ before(:all) do
737
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
738
+ @conn = ActiveRecord::Base.connection
739
+ schema_define do
740
+ drop_table :test_posts, if_exists: true
741
+ create_table :test_posts
742
+ end
743
+ class ::TestPost < ActiveRecord::Base
744
+ end
745
+ end
746
+
747
+ before(:each) do
748
+ @conn.clear_cache!
749
+ set_logger
750
+ end
751
+
752
+ after(:each) do
753
+ clear_logger
754
+ end
755
+
756
+ after(:all) do
757
+ schema_define do
758
+ drop_table :test_posts
759
+ end
760
+ Object.send(:remove_const, "TestPost")
761
+ ActiveRecord::Base.clear_cache!
762
+ end
763
+
764
+ it "should explain considers hints" do
765
+ post = TestPost.optimizer_hints("FULL (\"TEST_POSTS\")")
766
+ post = post.where(id: 1)
767
+ expect(post.explain).to include("| TABLE ACCESS FULL| TEST_POSTS |")
768
+ end
769
+
770
+ it "should explain considers hints with /*+ */ " do
771
+ post = TestPost.optimizer_hints("/*+ FULL (\"TEST_POSTS\") */")
772
+ post = post.where(id: 1)
773
+ expect(post.explain).to include("| TABLE ACCESS FULL| TEST_POSTS |")
774
+ end
775
+ end
776
+
777
+ describe "homogeneous in" do
778
+ before(:all) do
779
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
780
+ @conn = ActiveRecord::Base.connection
781
+ schema_define do
782
+ create_table :test_posts, force: true
783
+ create_table :test_comments, force: true do |t|
784
+ t.integer :test_post_id
785
+ end
786
+ end
787
+ class ::TestPost < ActiveRecord::Base
788
+ has_many :test_comments
789
+ end
790
+ class ::TestComment < ActiveRecord::Base
791
+ belongs_to :test_post
792
+ end
793
+ end
794
+
795
+ after(:all) do
796
+ schema_define do
797
+ drop_table :test_posts, if_exists: true
798
+ drop_table :test_comments, if_exists: true
799
+ end
800
+ Object.send(:remove_const, "TestPost")
801
+ Object.send(:remove_const, "TestComment")
802
+ ActiveRecord::Base.clear_cache!
803
+ end
804
+
805
+ it "should not raise undefined method length" do
806
+ post = TestPost.create!
807
+ post.test_comments << TestComment.create!
808
+ expect(TestComment.where(test_post_id: TestPost.select(:id)).size).to eq(1)
621
809
  end
622
810
  end
623
811
  end
@@ -6,7 +6,7 @@ describe "OracleEnhancedAdapter date and datetime type detection based on attrib
6
6
  @conn = ActiveRecord::Base.connection
7
7
  @conn.execute "DROP TABLE test_employees" rescue nil
8
8
  @conn.execute "DROP SEQUENCE test_employees_seq" rescue nil
9
- @conn.execute <<-SQL
9
+ @conn.execute <<~SQL
10
10
  CREATE TABLE test_employees (
11
11
  employee_id NUMBER(6,0) PRIMARY KEY,
12
12
  first_name VARCHAR2(20),
@@ -23,7 +23,7 @@ describe "OracleEnhancedAdapter date and datetime type detection based on attrib
23
23
  updated_at DATE
24
24
  )
25
25
  SQL
26
- @conn.execute <<-SQL
26
+ @conn.execute <<~SQL
27
27
  CREATE SEQUENCE test_employees_seq MINVALUE 1
28
28
  INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
29
29
  SQL
@@ -122,7 +122,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
122
122
  end
123
123
 
124
124
  after(:each) do
125
- ActiveRecord::Base.default_timezone = :utc
125
+ ActiveRecord.default_timezone = :utc
126
126
  end
127
127
 
128
128
  it "should assign ISO string to date column" do
@@ -170,7 +170,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
170
170
  end
171
171
 
172
172
  it "should assign ISO time string to datetime column" do
173
- ActiveRecord::Base.default_timezone = :local
173
+ ActiveRecord.default_timezone = :local
174
174
  @employee = TestEmployee.create(
175
175
  first_name: "First",
176
176
  last_name: "Last",
@@ -182,7 +182,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
182
182
  end
183
183
 
184
184
  it "should assign NLS time string to datetime column" do
185
- ActiveRecord::Base.default_timezone = :local
185
+ ActiveRecord.default_timezone = :local
186
186
  @employee = TestEmployee.create(
187
187
  first_name: "First",
188
188
  last_name: "Last",
@@ -205,7 +205,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
205
205
  end
206
206
 
207
207
  it "should assign ISO date string to datetime column" do
208
- ActiveRecord::Base.default_timezone = :local
208
+ ActiveRecord.default_timezone = :local
209
209
  @employee = TestEmployee.create(
210
210
  first_name: "First",
211
211
  last_name: "Last",
@@ -217,7 +217,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
217
217
  end
218
218
 
219
219
  it "should assign NLS date string to datetime column" do
220
- ActiveRecord::Base.default_timezone = :local
220
+ ActiveRecord.default_timezone = :local
221
221
  @employee = TestEmployee.create(
222
222
  first_name: "First",
223
223
  last_name: "Last",
@@ -227,5 +227,4 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
227
227
  @employee.reload
228
228
  expect(@employee.last_login_at).to eq(@today.to_time)
229
229
  end
230
-
231
230
  end
@@ -4,7 +4,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
4
4
  before(:all) do
5
5
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
6
6
  @conn = ActiveRecord::Base.connection
7
- @conn.execute <<-SQL
7
+ @conn.execute <<~SQL
8
8
  CREATE TABLE test3_employees (
9
9
  id NUMBER PRIMARY KEY,
10
10
  first_name VARCHAR2(20),
@@ -25,7 +25,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
25
25
  test_boolean VARCHAR2(3)
26
26
  )
27
27
  SQL
28
- @conn.execute <<-SQL
28
+ @conn.execute <<~SQL
29
29
  CREATE SEQUENCE test3_employees_seq MINVALUE 1
30
30
  INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
31
31
  SQL
@@ -165,9 +165,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
165
165
  create_employee3
166
166
  expect(@employee3.active_flag.class).to eq(String)
167
167
  end
168
-
169
168
  end
170
-
171
169
  end
172
170
 
173
171
  describe "OracleEnhancedAdapter boolean support when emulate_booleans_from_strings = true" do
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe "OracleEnhancedAdapter processing CHAR column" do
4
+ before(:all) do
5
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
6
+ @conn = ActiveRecord::Base.connection
7
+ @conn.execute <<~SQL
8
+ CREATE TABLE test_items (
9
+ id NUMBER(6,0) PRIMARY KEY,
10
+ padded CHAR(10)
11
+ )
12
+ SQL
13
+ @conn.execute "CREATE SEQUENCE test_items_seq"
14
+ end
15
+
16
+ after(:all) do
17
+ @conn.execute "DROP TABLE test_items"
18
+ @conn.execute "DROP SEQUENCE test_items_seq"
19
+ end
20
+
21
+ before(:each) do
22
+ class ::TestItem < ActiveRecord::Base
23
+ end
24
+ end
25
+
26
+ after(:each) do
27
+ Object.send(:remove_const, "TestItem")
28
+ ActiveRecord::Base.clear_cache!
29
+ end
30
+
31
+ it "should create and find record" do
32
+ str = "ABC"
33
+ TestItem.create!
34
+ item = TestItem.first
35
+ item.padded = str
36
+ item.save
37
+
38
+ expect(TestItem.where(padded: item.padded).count).to eq(1)
39
+
40
+ item_reloaded = TestItem.first
41
+ expect(item_reloaded.padded).to eq(str)
42
+ end
43
+ end