activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +206 -4
  3. data/README.md +37 -1
  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 +7 -59
  7. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
  8. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
  9. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
  10. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +37 -27
  11. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
  12. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +56 -71
  13. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -7
  14. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
  15. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
  16. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
  17. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +14 -43
  18. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
  20. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +150 -160
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +95 -133
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
  23. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +66 -101
  24. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
  25. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +290 -533
  26. data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
  27. data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
  28. data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
  29. data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
  30. data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
  31. data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
  32. data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
  33. data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
  34. data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
  35. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +55 -162
  36. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
  37. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +44 -42
  38. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +250 -357
  39. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
  40. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
  41. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +115 -124
  42. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -3
  43. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +68 -72
  44. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +64 -80
  45. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +223 -329
  46. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +18 -20
  47. data/spec/spec_config.yaml.template +11 -0
  48. data/spec/spec_helper.rb +59 -59
  49. data/spec/support/alter_system_user_password.sql +2 -0
  50. data/spec/support/create_oracle_enhanced_users.sql +31 -0
  51. metadata +25 -25
  52. data/.rspec +0 -2
  53. data/Gemfile +0 -22
  54. data/RUNNING_TESTS.md +0 -83
  55. data/Rakefile +0 -45
  56. data/activerecord-oracle_enhanced-adapter.gemspec +0 -94
  57. data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -19
  58. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "OracleEnhancedAdapter schema dump" do
4
2
  include SchemaSpecHelper
5
3
 
@@ -12,7 +10,7 @@ describe "OracleEnhancedAdapter schema dump" do
12
10
 
13
11
  def standard_dump(options = {})
14
12
  stream = StringIO.new
15
- ActiveRecord::SchemaDumper.ignore_tables = options[:ignore_tables]||[]
13
+ ActiveRecord::SchemaDumper.ignore_tables = options[:ignore_tables] || []
16
14
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
17
15
  stream.string
18
16
  end
@@ -76,45 +74,45 @@ describe "OracleEnhancedAdapter schema dump" do
76
74
  describe "table prefixes and suffixes" do
77
75
  after(:each) do
78
76
  drop_test_posts_table
79
- @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
77
+ @conn.drop_table(ActiveRecord::SchemaMigration.table_name) if @conn.table_exists?(ActiveRecord::SchemaMigration.table_name)
80
78
  @conn.drop_table(ActiveRecord::InternalMetadata.table_name) if @conn.table_exists?(ActiveRecord::InternalMetadata.table_name)
81
- ActiveRecord::Base.table_name_prefix = ''
82
- ActiveRecord::Base.table_name_suffix = ''
79
+ ActiveRecord::Base.table_name_prefix = ""
80
+ ActiveRecord::Base.table_name_suffix = ""
83
81
  end
84
82
 
85
83
  it "should remove table prefix in schema dump" do
86
- ActiveRecord::Base.table_name_prefix = 'xxx_'
84
+ ActiveRecord::Base.table_name_prefix = "xxx_"
87
85
  create_test_posts_table
88
- expect(standard_dump).to match(/create_table "test_posts".*add_index "test_posts"/m)
86
+ expect(standard_dump).to match(/create_table "test_posts"/m)
89
87
  end
90
88
 
91
89
  it "should remove table prefix with $ sign in schema dump" do
92
- ActiveRecord::Base.table_name_prefix = 'xxx$'
90
+ ActiveRecord::Base.table_name_prefix = "xxx$"
93
91
  create_test_posts_table
94
- expect(standard_dump).to match(/create_table "test_posts".*add_index "test_posts"/m)
92
+ expect(standard_dump).to match(/create_table "test_posts"/m)
95
93
  end
96
94
 
97
95
  it "should remove table suffix in schema dump" do
98
- ActiveRecord::Base.table_name_suffix = '_xxx'
96
+ ActiveRecord::Base.table_name_suffix = "_xxx"
99
97
  create_test_posts_table
100
- expect(standard_dump).to match(/create_table "test_posts".*add_index "test_posts"/m)
98
+ expect(standard_dump).to match(/create_table "test_posts"/m)
101
99
  end
102
100
 
103
101
  it "should remove table suffix with $ sign in schema dump" do
104
- ActiveRecord::Base.table_name_suffix = '$xxx'
102
+ ActiveRecord::Base.table_name_suffix = "$xxx"
105
103
  create_test_posts_table
106
- expect(standard_dump).to match(/create_table "test_posts".*add_index "test_posts"/m)
104
+ expect(standard_dump).to match(/create_table "test_posts"/m)
107
105
  end
108
106
 
109
107
  it "should not include schema_migrations table with prefix in schema dump" do
110
- ActiveRecord::Base.table_name_prefix = 'xxx_'
111
- @conn.initialize_schema_migrations_table
108
+ ActiveRecord::Base.table_name_prefix = "xxx_"
109
+ ActiveRecord::SchemaMigration.create_table
112
110
  expect(standard_dump).not_to match(/schema_migrations/)
113
111
  end
114
112
 
115
113
  it "should not include schema_migrations table with suffix in schema dump" do
116
- ActiveRecord::Base.table_name_suffix = '_xxx'
117
- @conn.initialize_schema_migrations_table
114
+ ActiveRecord::Base.table_name_suffix = "_xxx"
115
+ ActiveRecord::SchemaMigration.create_table
118
116
  expect(standard_dump).not_to match(/schema_migrations/)
119
117
  end
120
118
 
@@ -126,7 +124,7 @@ describe "OracleEnhancedAdapter schema dump" do
126
124
  end
127
125
 
128
126
  it "should include non-default primary key in schema dump" do
129
- create_test_posts_table(primary_key: 'post_id')
127
+ create_test_posts_table(primary_key: "post_id")
130
128
  expect(standard_dump).to match(/create_table "test_posts", primary_key: "post_id"/)
131
129
  end
132
130
 
@@ -145,7 +143,7 @@ describe "OracleEnhancedAdapter schema dump" do
145
143
  end
146
144
 
147
145
  it "should include primary key trigger with non-default primary key in schema dump" do
148
- create_test_posts_table(primary_key_trigger: true, primary_key: 'post_id')
146
+ create_test_posts_table(primary_key_trigger: true, primary_key: "post_id")
149
147
  expect(standard_dump).to match(/create_table "test_posts", primary_key: "post_id".*add_primary_key_trigger "test_posts", primary_key: "post_id"/m)
150
148
  end
151
149
 
@@ -167,7 +165,7 @@ describe "OracleEnhancedAdapter schema dump" do
167
165
  after(:each) do
168
166
  schema_define do
169
167
  remove_foreign_key :test_comments, :test_posts rescue nil
170
- remove_foreign_key :test_comments, name: 'comments_posts_baz_fooz_fk' rescue nil
168
+ remove_foreign_key :test_comments, name: "comments_posts_baz_fooz_fk" rescue nil
171
169
  end
172
170
  end
173
171
  after(:all) do
@@ -186,14 +184,14 @@ describe "OracleEnhancedAdapter schema dump" do
186
184
 
187
185
  it "should include foreign key with delete dependency in schema dump" do
188
186
  schema_define do
189
- add_foreign_key :test_comments, :test_posts, dependent: :delete
187
+ add_foreign_key :test_comments, :test_posts, on_delete: :cascade
190
188
  end
191
189
  expect(standard_dump).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :cascade/)
192
190
  end
193
191
 
194
192
  it "should include foreign key with nullify dependency in schema dump" do
195
193
  schema_define do
196
- add_foreign_key :test_comments, :test_posts, dependent: :nullify
194
+ add_foreign_key :test_comments, :test_posts, on_delete: :nullify
197
195
  end
198
196
  expect(standard_dump).to match(/add_foreign_key "test_comments", "test_posts", on_delete: :nullify/)
199
197
  end
@@ -238,7 +236,7 @@ describe "OracleEnhancedAdapter schema dump" do
238
236
 
239
237
  it "should include primary_key when reference column name is not 'id'" do
240
238
  schema_define do
241
- create_table :test_posts, force: true, :primary_key => 'baz_id' do |t|
239
+ create_table :test_posts, force: true, primary_key: "baz_id" do |t|
242
240
  t.string :title
243
241
  end
244
242
  create_table :test_comments, force: true do |t|
@@ -319,20 +317,20 @@ describe "OracleEnhancedAdapter schema dump" do
319
317
 
320
318
  it "should not specify default tablespace in add index" do
321
319
  create_test_posts_table
322
- expect(standard_dump).to match(/add_index "test_posts", \["title"\], name: "index_test_posts_on_title"$/)
320
+ expect(standard_dump).to match(/t\.index \["title"\], name: "index_test_posts_on_title"$/)
323
321
  end
324
322
 
325
323
  it "should specify non-default tablespace in add index" do
326
324
  tablespace_name = @conn.default_tablespace
327
- allow(@conn).to receive(:default_tablespace).and_return('dummy')
325
+ allow(@conn).to receive(:default_tablespace).and_return("dummy")
328
326
  create_test_posts_table
329
- expect(standard_dump).to match(/add_index "test_posts", \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/)
327
+ expect(standard_dump).to match(/t\.index \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/)
330
328
  end
331
329
 
332
330
  it "should create and dump function-based indexes" do
333
331
  create_test_posts_table
334
332
  @conn.add_index :test_posts, "NVL(created_at, updated_at)", name: "index_test_posts_cr_upd_at"
335
- expect(standard_dump).to match(/add_index "test_posts", \["NVL\(\\"CREATED_AT\\",\\"UPDATED_AT\\"\)"\], name: "index_test_posts_cr_upd_at"$/)
333
+ expect(standard_dump).to match(/t\.index \["NVL\(\\"CREATED_AT\\",\\"UPDATED_AT\\"\)"\], name: "index_test_posts_cr_upd_at"$/)
336
334
  end
337
335
 
338
336
  end
@@ -350,19 +348,19 @@ describe "OracleEnhancedAdapter schema dump" do
350
348
  end
351
349
  end
352
350
 
353
- describe 'virtual columns' do
351
+ describe "virtual columns" do
354
352
  before(:all) do
355
353
  skip "Not supported in this database version" unless @oracle11g_or_higher
356
354
  schema_define do
357
- create_table :test_names, :force => true do |t|
355
+ create_table :test_names, force: true do |t|
358
356
  t.string :first_name
359
357
  t.string :last_name
360
- t.virtual :full_name, :as => "first_name || ', ' || last_name"
361
- t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
362
- t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
363
- t.virtual :name_ratio, :as => '(LENGTH(first_name)*10/LENGTH(last_name)*10)'
364
- t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
365
- t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
358
+ t.virtual :full_name, as: "first_name || ', ' || last_name"
359
+ t.virtual :short_name, as: "COALESCE(first_name, last_name)", type: :string, limit: 300
360
+ t.virtual :abbrev_name, as: "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", type: "VARCHAR(100)"
361
+ t.virtual :name_ratio, as: "(LENGTH(first_name)*10/LENGTH(last_name)*10)"
362
+ t.column :full_name_length, :virtual, as: "length(first_name || ', ' || last_name)", type: :integer
363
+ t.virtual :field_with_leading_space, as: "' ' || first_name || ' '", limit: 300, type: :string
366
364
  end
367
365
  end
368
366
  end
@@ -383,16 +381,16 @@ describe "OracleEnhancedAdapter schema dump" do
383
381
  end
384
382
  end
385
383
 
386
- it 'should dump correctly' do
387
- expect(standard_dump).to match(/t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/)
388
- expect(standard_dump).to match(/t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/)
389
- expect(standard_dump).to match(/t\.virtual "full_name_length",(\s*)precision: 38,(\s*)as:(.*),(\s*)type: :integer/)
384
+ it "should dump correctly" do
385
+ expect(standard_dump).to match(/t\.virtual "full_name",(\s*)type: :string,(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\""/)
386
+ expect(standard_dump).to match(/t\.virtual "short_name",(\s*)type: :string,(\s*)limit: 300,(\s*)as:(.*)/)
387
+ expect(standard_dump).to match(/t\.virtual "full_name_length",(\s*)type: :integer,(\s*)precision: 38,(\s*)as:(.*)/)
390
388
  expect(standard_dump).to match(/t\.virtual "name_ratio",(\s*)as:(.*)\"$/) # no :type
391
- expect(standard_dump).to match(/t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/)
392
- expect(standard_dump).to match(/t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/)
389
+ expect(standard_dump).to match(/t\.virtual "abbrev_name",(\s*)type: :string,(\s*)limit: 100,(\s*)as:(.*)/)
390
+ expect(standard_dump).to match(/t\.virtual "field_with_leading_space",(\s*)type: :string,(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '"/)
393
391
  end
394
392
 
395
- context 'with column cache' do
393
+ context "with column cache" do
396
394
  before(:all) do
397
395
  @old_cache = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns
398
396
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true
@@ -400,8 +398,8 @@ describe "OracleEnhancedAdapter schema dump" do
400
398
  after(:all) do
401
399
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = @old_cache
402
400
  end
403
- it 'should not change column defaults after several dumps' do
404
- col = TestName.columns.detect{|c| c.name == 'full_name'}
401
+ it "should not change column defaults after several dumps" do
402
+ col = TestName.columns.detect { |c| c.name == "full_name" }
405
403
  expect(col).not_to be_nil
406
404
  expect(col.virtual_column_data_default).not_to match(/:as/)
407
405
 
@@ -417,20 +415,20 @@ describe "OracleEnhancedAdapter schema dump" do
417
415
  before(:all) do
418
416
  if @oracle11g_or_higher
419
417
  schema_define do
420
- add_index 'test_names', 'field_with_leading_space', :name => "index_on_virtual_col"
418
+ add_index "test_names", "field_with_leading_space", name: "index_on_virtual_col"
421
419
  end
422
420
  end
423
421
  end
424
422
  after(:all) do
425
423
  if @oracle11g_or_higher
426
424
  schema_define do
427
- remove_index 'test_names', :name => 'index_on_virtual_col'
425
+ remove_index "test_names", name: "index_on_virtual_col"
428
426
  end
429
427
  end
430
428
  end
431
- it 'should dump correctly' do
432
- expect(standard_dump).not_to match(/add_index "test_names".+FIRST_NAME.+$/)
433
- expect(standard_dump).to match(/add_index "test_names".+field_with_leading_space.+$/)
429
+ it "should dump correctly" do
430
+ expect(standard_dump).not_to match(/t\.index .+FIRST_NAME.+$/)
431
+ expect(standard_dump).to match(/t\.index .+field_with_leading_space.+$/)
434
432
  end
435
433
  end
436
434
  end
@@ -458,7 +456,7 @@ describe "OracleEnhancedAdapter schema dump" do
458
456
  describe "table comments" do
459
457
  before(:each) do
460
458
  schema_define do
461
- create_table :test_table_comments, :comment => "this is a \"table comment\"!", force: true do |t|
459
+ create_table :test_table_comments, comment: "this is a \"table comment\"!", force: true do |t|
462
460
  t.string :blah
463
461
  end
464
462
  end
@@ -471,7 +469,7 @@ describe "OracleEnhancedAdapter schema dump" do
471
469
  end
472
470
 
473
471
  it "should dump table comments" do
474
- standard_dump.should =~ /comment: "this is a \\"table comment\\"!"/
472
+ expect(standard_dump).to match(/comment: "this is a \\"table comment\\"!"/)
475
473
  end
476
474
  end
477
475
 
@@ -479,7 +477,7 @@ describe "OracleEnhancedAdapter schema dump" do
479
477
  before(:each) do
480
478
  schema_define do
481
479
  create_table :test_column_comments, force: true do |t|
482
- t.string :blah, :comment => "this is a \"column comment\"!"
480
+ t.string :blah, comment: "this is a \"column comment\"!"
483
481
  end
484
482
  end
485
483
  end
@@ -491,47 +489,33 @@ describe "OracleEnhancedAdapter schema dump" do
491
489
  end
492
490
 
493
491
  it "should dump column comments" do
494
- standard_dump.should =~ /comment: "this is a \\"column comment\\"!"/
492
+ expect(standard_dump).to match(/comment: "this is a \\"column comment\\"!"/)
495
493
  end
496
494
  end
497
495
 
498
- describe "table comments" do
499
- before(:each) do
496
+ describe "schema.rb format" do
497
+ before do
498
+ create_test_posts_table
499
+
500
500
  schema_define do
501
- create_table :test_table_comments, :comment => "this is a \"table comment\"!", force: true do |t|
502
- t.string :blah
501
+ create_table :test_comments, force: true do |t|
502
+ t.string :title
503
503
  end
504
- end
505
- end
506
504
 
507
- after(:each) do
508
- schema_define do
509
- drop_table :test_table_comments
505
+ add_index :test_comments, :title
510
506
  end
511
507
  end
512
508
 
513
- it "should dump table comments" do
514
- standard_dump.should =~ /comment: "this is a \\"table comment\\"!"/
509
+ it "should be only one blank line between create_table methods in schema dump" do
510
+ expect(standard_dump).to match(/end\n\n create_table/)
515
511
  end
516
- end
517
512
 
518
- describe "column comments" do
519
- before(:each) do
520
- schema_define do
521
- create_table :test_column_comments, force: true do |t|
522
- t.string :blah, :comment => "this is a \"column comment\"!"
523
- end
524
- end
525
- end
526
-
527
- after(:each) do
513
+ after do
528
514
  schema_define do
529
- drop_table :test_column_comments
515
+ drop_table :test_comments rescue nil
530
516
  end
531
- end
532
517
 
533
- it "should dump column comments" do
534
- standard_dump.should =~ /comment: "this is a \\"column comment\\"!"/
518
+ drop_test_posts_table
535
519
  end
536
520
  end
537
521
  end