activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.0.beta1

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/Gemfile +20 -11
  4. data/History.md +123 -4
  5. data/RUNNING_TESTS.md +79 -55
  6. data/Rakefile +13 -19
  7. data/VERSION +1 -1
  8. data/activerecord-oracle_enhanced-adapter.gemspec +16 -17
  9. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
  10. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +7 -59
  11. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
  12. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
  13. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
  14. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +30 -23
  15. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
  16. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +48 -70
  17. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +1 -4
  18. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
  19. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
  20. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
  21. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +13 -42
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +146 -159
  25. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +94 -132
  26. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
  27. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +65 -100
  28. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
  29. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +250 -487
  30. data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
  31. data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
  32. data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
  33. data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
  34. data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
  35. data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
  36. data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
  37. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +57 -131
  38. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
  39. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +40 -42
  40. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +83 -85
  41. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +205 -286
  42. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
  43. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
  44. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +42 -49
  45. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -3
  46. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +68 -71
  47. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +51 -92
  48. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +221 -327
  49. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +16 -18
  50. data/spec/spec_helper.rb +59 -57
  51. metadata +10 -10
@@ -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
@@ -78,43 +76,43 @@ describe "OracleEnhancedAdapter schema dump" do
78
76
  drop_test_posts_table
79
77
  @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_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,8 @@ 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\\"!"/
495
- end
496
- end
497
-
498
- describe "table comments" do
499
- before(:each) do
500
- schema_define do
501
- create_table :test_table_comments, :comment => "this is a \"table comment\"!", force: true do |t|
502
- t.string :blah
503
- end
504
- end
505
- end
506
-
507
- after(:each) do
508
- schema_define do
509
- drop_table :test_table_comments
510
- end
511
- end
512
-
513
- it "should dump table comments" do
514
- standard_dump.should =~ /comment: "this is a \\"table comment\\"!"/
492
+ expect(standard_dump).to match(/comment: "this is a \\"column comment\\"!"/)
515
493
  end
516
494
  end
517
495
 
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
528
- schema_define do
529
- drop_table :test_column_comments
530
- end
531
- end
532
-
533
- it "should dump column comments" do
534
- standard_dump.should =~ /comment: "this is a \\"column comment\\"!"/
535
- end
536
- end
537
496
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "OracleEnhancedAdapter schema definition" do
4
2
  include SchemaSpecHelper
5
3
  include LoggerSpecHelper
@@ -10,11 +8,11 @@ describe "OracleEnhancedAdapter schema definition" do
10
8
  "select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
11
9
  end
12
10
 
13
- describe 'option to create sequence when adding a column' do
11
+ describe "option to create sequence when adding a column" do
14
12
  before do
15
13
  @conn = ActiveRecord::Base.connection
16
14
  schema_define do
17
- create_table :keyboards, :force => true, :id => false do |t|
15
+ create_table :keyboards, force: true, id: false do |t|
18
16
  t.string :name
19
17
  end
20
18
  add_column :keyboards, :id, :primary_key
@@ -22,7 +20,7 @@ describe "OracleEnhancedAdapter schema definition" do
22
20
  class ::Keyboard < ActiveRecord::Base; end
23
21
  end
24
22
 
25
- it 'creates a sequence when adding a column with create_sequence = true' do
23
+ it "creates a sequence when adding a column with create_sequence = true" do
26
24
  _, sequence_name = ActiveRecord::Base.connection.pk_and_sequence_for_without_cache(:keyboards)
27
25
 
28
26
  expect(sequence_name).to eq(Keyboard.sequence_name)
@@ -34,11 +32,11 @@ describe "OracleEnhancedAdapter schema definition" do
34
32
  before(:all) do
35
33
  @conn = ActiveRecord::Base.connection
36
34
  schema_define do
37
- create_table :keyboards, :force => true, :id => false do |t|
35
+ create_table :keyboards, force: true, id: false do |t|
38
36
  t.primary_key :key_number
39
37
  t.string :name
40
38
  end
41
- create_table :id_keyboards, :force => true do |t|
39
+ create_table :id_keyboards, force: true do |t|
42
40
  t.string :name
43
41
  end
44
42
  end
@@ -56,7 +54,7 @@ describe "OracleEnhancedAdapter schema definition" do
56
54
  end
57
55
  Object.send(:remove_const, "Keyboard")
58
56
  Object.send(:remove_const, "IdKeyboard")
59
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
57
+ ActiveRecord::Base.clear_cache!
60
58
  end
61
59
 
62
60
  it "should create sequence for non-default primary key" do
@@ -72,7 +70,7 @@ describe "OracleEnhancedAdapter schema definition" do
72
70
 
73
71
  it "should return sequence name without truncating too much" do
74
72
  seq_name_length = ActiveRecord::Base.connection.sequence_name_length
75
- tname = "#{DATABASE_USER}" + "." + "a"*(seq_name_length - DATABASE_USER.length) + "z"*(DATABASE_USER).length
73
+ tname = "#{DATABASE_USER}" + "." + "a" * (seq_name_length - DATABASE_USER.length) + "z" * (DATABASE_USER).length
76
74
  expect(ActiveRecord::Base.connection.default_sequence_name(tname)).to match (/z_seq$/)
77
75
  end
78
76
  end
@@ -81,7 +79,7 @@ describe "OracleEnhancedAdapter schema definition" do
81
79
 
82
80
  def create_test_employees_table(sequence_start_value = nil)
83
81
  schema_define do
84
- create_table :test_employees, sequence_start_value ? {:sequence_start_value => sequence_start_value} : {} do |t|
82
+ create_table :test_employees, sequence_start_value ? { sequence_start_value: sequence_start_value } : {} do |t|
85
83
  t.string :first_name
86
84
  t.string :last_name
87
85
  end
@@ -110,7 +108,7 @@ describe "OracleEnhancedAdapter schema definition" do
110
108
  drop_table :test_employees
111
109
  end
112
110
  Object.send(:remove_const, "TestEmployee")
113
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
111
+ ActiveRecord::Base.clear_cache!
114
112
  end
115
113
 
116
114
  it "should use default sequence start value 10000" do
@@ -155,7 +153,7 @@ describe "OracleEnhancedAdapter schema definition" do
155
153
 
156
154
  describe "create table with primary key trigger" do
157
155
  def create_table_with_trigger(options = {})
158
- options.merge! :primary_key_trigger => true, :force => true
156
+ options.merge! primary_key_trigger: true, force: true
159
157
  schema_define do
160
158
  create_table :test_employees, options do |t|
161
159
  t.string :first_name
@@ -165,7 +163,7 @@ describe "OracleEnhancedAdapter schema definition" do
165
163
  end
166
164
 
167
165
  def create_table_and_separately_trigger(options = {})
168
- options.merge! :force => true
166
+ options.merge! force: true
169
167
  schema_define do
170
168
  create_table :test_employees, options do |t|
171
169
  t.string :first_name
@@ -178,11 +176,11 @@ describe "OracleEnhancedAdapter schema definition" do
178
176
  def drop_table_with_trigger(options = {})
179
177
  seq_name = options[:sequence_name]
180
178
  schema_define do
181
- drop_table :test_employees, (seq_name ? {:sequence_name => seq_name} : {})
179
+ drop_table :test_employees, (seq_name ? { sequence_name: seq_name } : {})
182
180
  end
183
181
  Object.send(:remove_const, "TestEmployee")
184
182
  @conn.clear_prefetch_primary_key
185
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
183
+ ActiveRecord::Base.clear_cache!
186
184
  end
187
185
 
188
186
  describe "with default primary key" do
@@ -209,7 +207,7 @@ describe "OracleEnhancedAdapter schema definition" do
209
207
  end
210
208
 
211
209
  it "should create new record for model" do
212
- e = TestEmployee.create!(:first_name => 'Raimonds')
210
+ e = TestEmployee.create!(first_name: "Raimonds")
213
211
  expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
214
212
  end
215
213
 
@@ -248,7 +246,7 @@ describe "OracleEnhancedAdapter schema definition" do
248
246
  end
249
247
 
250
248
  it "should create new record for model" do
251
- e = TestEmployee.create!(:first_name => 'Raimonds')
249
+ e = TestEmployee.create!(first_name: "Raimonds")
252
250
  expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
253
251
  end
254
252
  end
@@ -259,14 +257,14 @@ describe "OracleEnhancedAdapter schema definition" do
259
257
  @conn = ActiveRecord::Base.connection
260
258
  @primary_key = "employee_id"
261
259
  @sequence_name = "test_employees_s"
262
- create_table_with_trigger(:primary_key => @primary_key, :sequence_name => @sequence_name)
260
+ create_table_with_trigger(primary_key: @primary_key, sequence_name: @sequence_name)
263
261
  class ::TestEmployee < ActiveRecord::Base
264
262
  self.primary_key = "employee_id"
265
263
  end
266
264
  end
267
265
 
268
266
  after(:all) do
269
- drop_table_with_trigger(:sequence_name => @sequence_name)
267
+ drop_table_with_trigger(sequence_name: @sequence_name)
270
268
  end
271
269
 
272
270
  it "should populate primary key using trigger" do
@@ -281,7 +279,7 @@ describe "OracleEnhancedAdapter schema definition" do
281
279
  end
282
280
 
283
281
  it "should create new record for model with autogenerated sequence option" do
284
- e = TestEmployee.create!(:first_name => 'Raimonds')
282
+ e = TestEmployee.create!(first_name: "Raimonds")
285
283
  expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
286
284
  end
287
285
  end
@@ -291,14 +289,14 @@ describe "OracleEnhancedAdapter schema definition" do
291
289
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
292
290
  @conn = ActiveRecord::Base.connection
293
291
  @sequence_name = "test_employees_s"
294
- create_table_with_trigger(:sequence_name => @sequence_name, :trigger_name => "test_employees_t1")
292
+ create_table_with_trigger(sequence_name: @sequence_name, trigger_name: "test_employees_t1")
295
293
  class ::TestEmployee < ActiveRecord::Base
296
294
  self.sequence_name = :autogenerated
297
295
  end
298
296
  end
299
297
 
300
298
  after(:all) do
301
- drop_table_with_trigger(:sequence_name => @sequence_name)
299
+ drop_table_with_trigger(sequence_name: @sequence_name)
302
300
  end
303
301
 
304
302
  it "should populate primary key using trigger" do
@@ -313,7 +311,7 @@ describe "OracleEnhancedAdapter schema definition" do
313
311
  end
314
312
 
315
313
  it "should create new record for model with autogenerated sequence option" do
316
- e = TestEmployee.create!(:first_name => 'Raimonds')
314
+ e = TestEmployee.create!(first_name: "Raimonds")
317
315
  expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
318
316
  end
319
317
  end
@@ -322,11 +320,11 @@ describe "OracleEnhancedAdapter schema definition" do
322
320
 
323
321
  describe "table and column comments" do
324
322
 
325
- def create_test_employees_table(table_comment=nil, column_comments={})
323
+ def create_test_employees_table(table_comment = nil, column_comments = {})
326
324
  schema_define do
327
- create_table :test_employees, :comment => table_comment do |t|
328
- t.string :first_name, :comment => column_comments[:first_name]
329
- t.string :last_name, :comment => column_comments[:last_name]
325
+ create_table :test_employees, comment: table_comment do |t|
326
+ t.string :first_name, comment: column_comments[:first_name]
327
+ t.string :last_name, comment: column_comments[:last_name]
330
328
  end
331
329
  end
332
330
  end
@@ -340,8 +338,8 @@ describe "OracleEnhancedAdapter schema definition" do
340
338
  drop_table :test_employees
341
339
  end
342
340
  Object.send(:remove_const, "TestEmployee")
343
- ActiveRecord::Base.table_name_prefix = ''
344
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
341
+ ActiveRecord::Base.table_name_prefix = ""
342
+ ActiveRecord::Base.clear_cache!
345
343
  end
346
344
 
347
345
  it "should create table with table comment" do
@@ -350,39 +348,35 @@ describe "OracleEnhancedAdapter schema definition" do
350
348
  class ::TestEmployee < ActiveRecord::Base; end
351
349
 
352
350
  expect(@conn.table_comment("test_employees")).to eq(table_comment)
353
- expect(TestEmployee.table_comment).to eq(table_comment)
354
351
  end
355
352
 
356
353
  it "should create table with columns comment" do
357
- column_comments = {:first_name => "Given Name", :last_name => "Surname"}
354
+ column_comments = { first_name: "Given Name", last_name: "Surname" }
358
355
  create_test_employees_table(nil, column_comments)
359
356
  class ::TestEmployee < ActiveRecord::Base; end
360
357
 
361
358
  [:first_name, :last_name].each do |attr|
362
359
  expect(@conn.column_comment("test_employees", attr.to_s)).to eq(column_comments[attr])
363
360
  end
364
- # may drop support this syntax
365
- # [:first_name, :last_name].each do |attr|
366
- # expect(TestEmployee.columns_hash[attr.to_s].comment).to eq(column_comments[attr])
367
- # end
361
+ [:first_name, :last_name].each do |attr|
362
+ expect(TestEmployee.columns_hash[attr.to_s].comment).to eq(column_comments[attr])
363
+ end
368
364
  end
369
365
 
370
366
  it "should create table with table and columns comment and custom table name prefix" do
371
367
  ActiveRecord::Base.table_name_prefix = "xxx_"
372
368
  table_comment = "Test Employees"
373
- column_comments = {:first_name => "Given Name", :last_name => "Surname"}
369
+ column_comments = { first_name: "Given Name", last_name: "Surname" }
374
370
  create_test_employees_table(table_comment, column_comments)
375
371
  class ::TestEmployee < ActiveRecord::Base; end
376
372
 
377
373
  expect(@conn.table_comment(TestEmployee.table_name)).to eq(table_comment)
378
- expect(TestEmployee.table_comment).to eq(table_comment)
379
374
  [:first_name, :last_name].each do |attr|
380
375
  expect(@conn.column_comment(TestEmployee.table_name, attr.to_s)).to eq(column_comments[attr])
381
376
  end
382
- # may drop support this syntax
383
- # [:first_name, :last_name].each do |attr|
384
- # expect(TestEmployee.columns_hash[attr.to_s].comment).to eq(column_comments[attr])
385
- # end
377
+ [:first_name, :last_name].each do |attr|
378
+ expect(TestEmployee.columns_hash[attr.to_s].comment).to eq(column_comments[attr])
379
+ end
386
380
  end
387
381
 
388
382
  end
@@ -402,21 +396,21 @@ describe "OracleEnhancedAdapter schema definition" do
402
396
  describe "rename tables and sequences" do
403
397
  before(:each) do
404
398
  @conn = ActiveRecord::Base.connection
405
- schema_define do
406
- drop_table :test_employees rescue nil
407
- drop_table :new_test_employees rescue nil
408
- drop_table :test_employees_no_primary_key rescue nil
399
+ schema_define do
400
+ drop_table :test_employees rescue nil
401
+ drop_table :new_test_employees rescue nil
402
+ drop_table :test_employees_no_primary_key rescue nil
409
403
 
410
- create_table :test_employees do |t|
411
- t.string :first_name
412
- t.string :last_name
413
- end
404
+ create_table :test_employees do |t|
405
+ t.string :first_name
406
+ t.string :last_name
407
+ end
414
408
 
415
- create_table :test_employees_no_pkey, :id => false do |t|
416
- t.string :first_name
417
- t.string :last_name
418
- end
409
+ create_table :test_employees_no_pkey, id: false do |t|
410
+ t.string :first_name
411
+ t.string :last_name
419
412
  end
413
+ end
420
414
  end
421
415
 
422
416
  after(:each) do
@@ -431,25 +425,25 @@ describe "OracleEnhancedAdapter schema definition" do
431
425
 
432
426
  it "should rename table name with new one" do
433
427
  expect do
434
- @conn.rename_table("test_employees","new_test_employees")
428
+ @conn.rename_table("test_employees", "new_test_employees")
435
429
  end.not_to raise_error
436
430
  end
437
431
 
438
432
  it "should raise error when new table name length is too long" do
439
433
  expect do
440
- @conn.rename_table("test_employees","a"*31)
434
+ @conn.rename_table("test_employees", "a" * 31)
441
435
  end.to raise_error(ArgumentError)
442
436
  end
443
437
 
444
438
  it "should not raise error when new sequence name length is too long" do
445
439
  expect do
446
- @conn.rename_table("test_employees","a"*27)
440
+ @conn.rename_table("test_employees", "a" * 27)
447
441
  end.not_to raise_error
448
442
  end
449
443
 
450
444
  it "should rename table when table has no primary key and sequence" do
451
445
  expect do
452
- @conn.rename_table("test_employees_no_pkey","new_test_employees_no_pkey")
446
+ @conn.rename_table("test_employees_no_pkey", "new_test_employees_no_pkey")
453
447
  end.not_to raise_error
454
448
  end
455
449
 
@@ -473,7 +467,7 @@ describe "OracleEnhancedAdapter schema definition" do
473
467
  drop_table :test_employees
474
468
  end
475
469
  Object.send(:remove_const, "TestEmployee")
476
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
470
+ ActiveRecord::Base.clear_cache!
477
471
  end
478
472
 
479
473
  it "should create table trigger with :new reference" do
@@ -499,69 +493,69 @@ describe "OracleEnhancedAdapter schema definition" do
499
493
  end
500
494
 
501
495
  it "should return default index name if it is not larger than 30 characters" do
502
- expect(@conn.index_name("employees", :column => "first_name")).to eq("index_employees_on_first_name")
496
+ expect(@conn.index_name("employees", column: "first_name")).to eq("index_employees_on_first_name")
503
497
  end
504
498
 
505
499
  it "should return shortened index name by removing 'index', 'on' and 'and' keywords" do
506
- expect(@conn.index_name("employees", :column => ["first_name", "email"])).to eq("i_employees_first_name_email")
500
+ expect(@conn.index_name("employees", column: ["first_name", "email"])).to eq("i_employees_first_name_email")
507
501
  end
508
502
 
509
503
  it "should return shortened index name by shortening table and column names" do
510
- expect(@conn.index_name("employees", :column => ["first_name", "last_name"])).to eq("i_emp_fir_nam_las_nam")
504
+ expect(@conn.index_name("employees", column: ["first_name", "last_name"])).to eq("i_emp_fir_nam_las_nam")
511
505
  end
512
506
 
513
507
  it "should raise error if too large index name cannot be shortened" do
514
- expect(@conn.index_name("test_employees", :column => ["first_name", "middle_name", "last_name"])).to eq(
515
- 'i'+Digest::SHA1.hexdigest("index_test_employees_on_first_name_and_middle_name_and_last_name")[0,29]
508
+ expect(@conn.index_name("test_employees", column: ["first_name", "middle_name", "last_name"])).to eq(
509
+ "i" + Digest::SHA1.hexdigest("index_test_employees_on_first_name_and_middle_name_and_last_name")[0, 29]
516
510
  )
517
511
  end
518
512
 
519
513
  end
520
514
 
521
515
  describe "rename index" do
522
- before(:each) do
523
- @conn = ActiveRecord::Base.connection
524
- schema_define do
525
- create_table :test_employees do |t|
526
- t.string :first_name
527
- t.string :last_name
528
- end
529
- add_index :test_employees, :first_name
516
+ before(:each) do
517
+ @conn = ActiveRecord::Base.connection
518
+ schema_define do
519
+ create_table :test_employees do |t|
520
+ t.string :first_name
521
+ t.string :last_name
530
522
  end
531
- class ::TestEmployee < ActiveRecord::Base; end
523
+ add_index :test_employees, :first_name
532
524
  end
525
+ class ::TestEmployee < ActiveRecord::Base; end
526
+ end
533
527
 
534
- after(:each) do
535
- schema_define do
536
- drop_table :test_employees
537
- end
538
- Object.send(:remove_const, "TestEmployee")
539
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
528
+ after(:each) do
529
+ schema_define do
530
+ drop_table :test_employees
540
531
  end
532
+ Object.send(:remove_const, "TestEmployee")
533
+ ActiveRecord::Base.clear_cache!
534
+ end
541
535
 
542
- it "should raise error when current index name and new index name are identical" do
543
- expect do
544
- @conn.rename_index("test_employees","i_test_employees_first_name","i_test_employees_first_name")
545
- end.to raise_error(ActiveRecord::StatementInvalid)
546
- end
536
+ it "should raise error when current index name and new index name are identical" do
537
+ expect do
538
+ @conn.rename_index("test_employees", "i_test_employees_first_name", "i_test_employees_first_name")
539
+ end.to raise_error(ActiveRecord::StatementInvalid)
540
+ end
547
541
 
548
- it "should raise error when new index name length is too long" do
549
- expect do
550
- @conn.rename_index("test_employees","i_test_employees_first_name","a"*31)
551
- end.to raise_error(ArgumentError)
552
- end
542
+ it "should raise error when new index name length is too long" do
543
+ expect do
544
+ @conn.rename_index("test_employees", "i_test_employees_first_name", "a" * 31)
545
+ end.to raise_error(ArgumentError)
546
+ end
553
547
 
554
- it "should raise error when current index name does not exist" do
555
- expect do
556
- @conn.rename_index("test_employees","nonexist_index_name","new_index_name")
557
- end.to raise_error(ArgumentError)
558
- end
548
+ it "should raise error when current index name does not exist" do
549
+ expect do
550
+ @conn.rename_index("test_employees", "nonexist_index_name", "new_index_name")
551
+ end.to raise_error(ActiveRecord::StatementInvalid)
552
+ end
559
553
 
560
- it "should rename index name with new one" do
561
- expect do
562
- @conn.rename_index("test_employees","i_test_employees_first_name","new_index_name")
563
- end.not_to raise_error
564
- end
554
+ it "should rename index name with new one" do
555
+ expect do
556
+ @conn.rename_index("test_employees", "i_test_employees_first_name", "new_index_name")
557
+ end.not_to raise_error
558
+ end
565
559
  end
566
560
 
567
561
  describe "ignore options for LOB columns" do
@@ -574,8 +568,8 @@ end
574
568
  it "should ignore :limit option for :text column" do
575
569
  expect do
576
570
  schema_define do
577
- create_table :test_posts, :force => true do |t|
578
- t.text :body, :limit => 10000
571
+ create_table :test_posts, force: true do |t|
572
+ t.text :body, limit: 10000
579
573
  end
580
574
  end
581
575
  end.not_to raise_error
@@ -584,8 +578,8 @@ end
584
578
  it "should ignore :limit option for :binary column" do
585
579
  expect do
586
580
  schema_define do
587
- create_table :test_posts, :force => true do |t|
588
- t.binary :picture, :limit => 10000
581
+ create_table :test_posts, force: true do |t|
582
+ t.binary :picture, limit: 10000
589
583
  end
590
584
  end
591
585
  end.not_to raise_error
@@ -594,18 +588,18 @@ end
594
588
  end
595
589
 
596
590
  describe "foreign key constraints" do
597
- let(:table_name_prefix) { '' }
598
- let(:table_name_suffix) { '' }
591
+ let(:table_name_prefix) { "" }
592
+ let(:table_name_suffix) { "" }
599
593
 
600
594
  before(:each) do
601
595
  ActiveRecord::Base.table_name_prefix = table_name_prefix
602
596
  ActiveRecord::Base.table_name_suffix = table_name_suffix
603
597
  schema_define do
604
- create_table :test_posts, :force => true do |t|
598
+ create_table :test_posts, force: true do |t|
605
599
  t.string :title
606
600
  end
607
- create_table :test_comments, :force => true do |t|
608
- t.string :body, :limit => 4000
601
+ create_table :test_comments, force: true do |t|
602
+ t.string :body, limit: 4000
609
603
  t.references :test_post
610
604
  t.integer :post_id
611
605
  end
@@ -625,9 +619,9 @@ end
625
619
  drop_table :test_comments rescue nil
626
620
  drop_table :test_posts rescue nil
627
621
  end
628
- ActiveRecord::Base.table_name_prefix = ''
629
- ActiveRecord::Base.table_name_suffix = ''
630
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
622
+ ActiveRecord::Base.table_name_prefix = ""
623
+ ActiveRecord::Base.table_name_suffix = ""
624
+ ActiveRecord::Base.clear_cache!
631
625
  end
632
626
 
633
627
  it "should add foreign key" do
@@ -637,98 +631,46 @@ end
637
631
  add_foreign_key :test_comments, :test_posts
638
632
  end
639
633
  expect do
640
- TestComment.create(:body => "test", :test_post_id => 1)
641
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
642
- end
643
-
644
- context "with table_name_prefix" do
645
- let(:table_name_prefix) { 'xxx_' }
646
-
647
- it "should use table_name_prefix for foreign table" do
648
- fk_name = "fk_rails_#{Digest::SHA256.hexdigest("xxx_test_comments_test_post_id_fk").first(10)}"
649
- schema_define do
650
- add_foreign_key :test_comments, :test_posts
651
- end
652
-
653
- expect do
654
- TestComment.create(:body => "test", :test_post_id => 1)
655
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
656
- end
657
- end
658
-
659
- context "with table_name_suffix" do
660
- let(:table_name_suffix) { '_xxx' }
661
-
662
- it "should use table_name_suffix for foreign table" do
663
- fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_xxx_test_post_id_fk").first(10)}"
664
- schema_define do
665
- add_foreign_key :test_comments, :test_posts
666
- end
667
-
668
- expect do
669
- TestComment.create(:body => "test", :test_post_id => 1)
670
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
671
- end
634
+ TestComment.create(body: "test", test_post_id: 1)
635
+ end.to raise_error() { |e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i) }
672
636
  end
673
637
 
674
638
  it "should add foreign key with name" do
675
639
  schema_define do
676
- add_foreign_key :test_comments, :test_posts, :name => "comments_posts_fk"
677
- end
678
- expect do
679
- TestComment.create(:body => "test", :test_post_id => 1)
680
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.COMMENTS_POSTS_FK/)}
681
- end
682
-
683
- it "should add foreign key with long name which is shortened" do
684
- schema_define do
685
- add_foreign_key :test_comments, :test_posts, :name => "test_comments_test_post_id_foreign_key"
640
+ add_foreign_key :test_comments, :test_posts, name: "comments_posts_fk"
686
641
  end
687
642
  expect do
688
- TestComment.create(:body => "test", :test_post_id => 1)
689
- end.to raise_error() {|e| expect(e.message).to match(
690
- /ORA-02291.*\.C#{Digest::SHA1.hexdigest("test_comments_test_post_id_foreign_key")[0,29].upcase}/
691
- )}
692
- end
693
-
694
- it "should add foreign key with very long name which is shortened" do
695
- schema_define do
696
- add_foreign_key :test_comments, :test_posts, :name => "long_prefix_test_comments_test_post_id_foreign_key"
697
- end
698
- expect do
699
- TestComment.create(:body => "test", :test_post_id => 1)
700
- end.to raise_error() {|e| expect(e.message).to match(
701
- /ORA-02291.*\.C#{Digest::SHA1.hexdigest("long_prefix_test_comments_test_post_id_foreign_key")[0,29].upcase}/
702
- )}
643
+ TestComment.create(body: "test", test_post_id: 1)
644
+ end.to raise_error() { |e| expect(e.message).to match(/ORA-02291.*\.COMMENTS_POSTS_FK/) }
703
645
  end
704
646
 
705
647
  it "should add foreign key with column" do
706
648
  fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_post_id_fk").first(10)}"
707
649
 
708
650
  schema_define do
709
- add_foreign_key :test_comments, :test_posts, :column => "post_id"
651
+ add_foreign_key :test_comments, :test_posts, column: "post_id"
710
652
  end
711
653
  expect do
712
- TestComment.create(:body => "test", :post_id => 1)
713
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
654
+ TestComment.create(body: "test", post_id: 1)
655
+ end.to raise_error() { |e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i) }
714
656
  end
715
657
 
716
658
  it "should add foreign key with delete dependency" do
717
659
  schema_define do
718
- add_foreign_key :test_comments, :test_posts, :dependent => :delete
660
+ add_foreign_key :test_comments, :test_posts, on_delete: :cascade
719
661
  end
720
- p = TestPost.create(:title => "test")
721
- c = TestComment.create(:body => "test", :test_post => p)
662
+ p = TestPost.create(title: "test")
663
+ c = TestComment.create(body: "test", test_post: p)
722
664
  TestPost.delete(p.id)
723
665
  expect(TestComment.find_by_id(c.id)).to be_nil
724
666
  end
725
667
 
726
668
  it "should add foreign key with nullify dependency" do
727
669
  schema_define do
728
- add_foreign_key :test_comments, :test_posts, :dependent => :nullify
670
+ add_foreign_key :test_comments, :test_posts, on_delete: :nullify
729
671
  end
730
- p = TestPost.create(:title => "test")
731
- c = TestComment.create(:body => "test", :test_post => p)
672
+ p = TestPost.create(title: "test")
673
+ c = TestComment.create(body: "test", test_post: p)
732
674
  TestPost.delete(p.id)
733
675
  expect(TestComment.find_by_id(c.id).test_post_id).to be_nil
734
676
  end
@@ -739,27 +681,27 @@ end
739
681
  remove_foreign_key :test_comments, :test_posts
740
682
  end
741
683
  expect do
742
- TestComment.create(:body => "test", :test_post_id => 1)
684
+ TestComment.create(body: "test", test_post_id: 1)
743
685
  end.not_to raise_error
744
686
  end
745
687
 
746
688
  it "should remove foreign key by constraint name" do
747
689
  schema_define do
748
- add_foreign_key :test_comments, :test_posts, :name => "comments_posts_fk"
749
- remove_foreign_key :test_comments, :name => "comments_posts_fk"
690
+ add_foreign_key :test_comments, :test_posts, name: "comments_posts_fk"
691
+ remove_foreign_key :test_comments, name: "comments_posts_fk"
750
692
  end
751
693
  expect do
752
- TestComment.create(:body => "test", :test_post_id => 1)
694
+ TestComment.create(body: "test", test_post_id: 1)
753
695
  end.not_to raise_error
754
696
  end
755
697
 
756
698
  it "should remove foreign key by column name" do
757
699
  schema_define do
758
700
  add_foreign_key :test_comments, :test_posts
759
- remove_foreign_key :test_comments, :column => "test_post_id"
701
+ remove_foreign_key :test_comments, column: "test_post_id"
760
702
  end
761
703
  expect do
762
- TestComment.create(:body => "test", :test_post_id => 1)
704
+ TestComment.create(body: "test", test_post_id: 1)
763
705
  end.not_to raise_error
764
706
  end
765
707
 
@@ -770,11 +712,11 @@ end
770
712
  class ::TestPost < ActiveRecord::Base
771
713
  end
772
714
  end
773
- it 'should use default tablespace for clobs' do
715
+ it "should use default tablespace for clobs" do
774
716
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
775
717
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = nil
776
718
  schema_define do
777
- create_table :test_posts, :force => true do |t|
719
+ create_table :test_posts, force: true do |t|
778
720
  t.text :test_clob
779
721
  t.binary :test_blob
780
722
  end
@@ -783,11 +725,11 @@ end
783
725
  expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'")).not_to eq(DATABASE_NON_DEFAULT_TABLESPACE)
784
726
  end
785
727
 
786
- it 'should use default tablespace for blobs' do
728
+ it "should use default tablespace for blobs" do
787
729
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:blob] = DATABASE_NON_DEFAULT_TABLESPACE
788
730
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = nil
789
731
  schema_define do
790
- create_table :test_posts, :force => true do |t|
732
+ create_table :test_posts, force: true do |t|
791
733
  t.text :test_clob
792
734
  t.binary :test_blob
793
735
  end
@@ -812,10 +754,10 @@ end
812
754
  end
813
755
  end
814
756
 
815
- it 'should use default tablespace for primary key' do
757
+ it "should use default tablespace for primary key" do
816
758
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = nil
817
759
  schema_define do
818
- create_table :test_posts, :force => true
760
+ create_table :test_posts, force: true
819
761
  end
820
762
 
821
763
  index_name = @conn.select_value(
@@ -824,13 +766,13 @@ end
824
766
  AND constraint_type = 'P'
825
767
  AND owner = SYS_CONTEXT('userenv', 'current_schema')")
826
768
 
827
- expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq('USERS')
769
+ expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq("USERS")
828
770
  end
829
771
 
830
- it 'should use non default tablespace for primary key' do
772
+ it "should use non default tablespace for primary key" do
831
773
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = DATABASE_NON_DEFAULT_TABLESPACE
832
774
  schema_define do
833
- create_table :test_posts, :force => true
775
+ create_table :test_posts, force: true
834
776
  end
835
777
 
836
778
  index_name = @conn.select_value(
@@ -854,7 +796,7 @@ end
854
796
  describe "foreign key in table definition" do
855
797
  before(:each) do
856
798
  schema_define do
857
- create_table :test_posts, :force => true do |t|
799
+ create_table :test_posts, force: true do |t|
858
800
  t.string :title
859
801
  end
860
802
  end
@@ -873,38 +815,38 @@ end
873
815
  drop_table :test_comments rescue nil
874
816
  drop_table :test_posts rescue nil
875
817
  end
876
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
818
+ ActiveRecord::Base.clear_cache!
877
819
  end
878
820
 
879
821
  it "should add foreign key in create_table" do
880
822
  schema_define do
881
- create_table :test_comments, :force => true do |t|
882
- t.string :body, :limit => 4000
823
+ create_table :test_comments, force: true do |t|
824
+ t.string :body, limit: 4000
883
825
  t.references :test_post
884
826
  t.foreign_key :test_posts
885
827
  end
886
828
  end
887
829
  expect do
888
- TestComment.create(:body => "test", :test_post_id => 1)
889
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
830
+ TestComment.create(body: "test", test_post_id: 1)
831
+ end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
890
832
  end
891
833
 
892
834
  it "should add foreign key in create_table references" do
893
835
  schema_define do
894
- create_table :test_comments, :force => true do |t|
895
- t.string :body, :limit => 4000
896
- t.references :test_post, :foreign_key => true
836
+ create_table :test_comments, force: true do |t|
837
+ t.string :body, limit: 4000
838
+ t.references :test_post, foreign_key: true
897
839
  end
898
840
  end
899
841
  expect do
900
- TestComment.create(:body => "test", :test_post_id => 1)
901
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
842
+ TestComment.create(body: "test", test_post_id: 1)
843
+ end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
902
844
  end
903
845
 
904
846
  it "should add foreign key in change_table" do
905
847
  schema_define do
906
- create_table :test_comments, :force => true do |t|
907
- t.string :body, :limit => 4000
848
+ create_table :test_comments, force: true do |t|
849
+ t.string :body, limit: 4000
908
850
  t.references :test_post
909
851
  end
910
852
  change_table :test_comments do |t|
@@ -912,40 +854,22 @@ end
912
854
  end
913
855
  end
914
856
  expect do
915
- TestComment.create(:body => "test", :test_post_id => 1)
916
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
857
+ TestComment.create(body: "test", test_post_id: 1)
858
+ end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
917
859
  end
918
860
 
919
861
  it "should add foreign key in change_table references" do
920
862
  schema_define do
921
- create_table :test_comments, :force => true do |t|
922
- t.string :body, :limit => 4000
923
- end
924
- change_table :test_comments do |t|
925
- t.references :test_post, :foreign_key => true
926
- end
927
- end
928
- expect do
929
- TestComment.create(:body => "test", :test_post_id => 1)
930
- end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
931
- end
932
-
933
- it "should remove foreign key by table name" do
934
- schema_define do
935
- create_table :test_comments, :force => true do |t|
936
- t.string :body, :limit => 4000
937
- t.references :test_post
863
+ create_table :test_comments, force: true do |t|
864
+ t.string :body, limit: 4000
938
865
  end
939
866
  change_table :test_comments do |t|
940
- t.foreign_key :test_posts
941
- end
942
- change_table :test_comments do |t|
943
- t.remove_foreign_key :test_posts
867
+ t.references :test_post, foreign_key: true
944
868
  end
945
869
  end
946
870
  expect do
947
- TestComment.create(:body => "test", :test_post_id => 1)
948
- end.not_to raise_error
871
+ TestComment.create(body: "test", test_post_id: 1)
872
+ end.to raise_error() { |e| expect(e.message).to match(/ORA-02291/) }
949
873
  end
950
874
 
951
875
  end
@@ -957,16 +881,16 @@ end
957
881
 
958
882
  before(:each) do
959
883
  schema_define do
960
- create_table :test_posts, :force => true do |t|
884
+ create_table :test_posts, force: true do |t|
961
885
  t.string :title
962
886
  end
963
- create_table :test_comments, :force => true do |t|
964
- t.string :body, :limit => 4000
965
- t.references :test_post, :foreign_key => true
887
+ create_table :test_comments, force: true do |t|
888
+ t.string :body, limit: 4000
889
+ t.references :test_post, foreign_key: true
966
890
  end
967
- create_table "test_Mixed_Comments", :force => true do |t|
968
- t.string :body, :limit => 4000
969
- t.references :test_post, :foreign_key => true
891
+ create_table "test_Mixed_Comments", force: true do |t|
892
+ t.string :body, limit: 4000
893
+ t.references :test_post, foreign_key: true
970
894
  end
971
895
  end
972
896
  end
@@ -1007,7 +931,7 @@ end
1007
931
  @conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
1008
932
  @conn.execute "CREATE DATABASE LINK #{@db_link} CONNECT TO #{@db_link_username} IDENTIFIED BY \"#{@db_link_password}\" USING '#{@db_link_database}'"
1009
933
  schema_define do
1010
- create_table :test_posts, :force => true do |t|
934
+ create_table :test_posts, force: true do |t|
1011
935
  t.string :title
1012
936
  end
1013
937
  end
@@ -1032,28 +956,28 @@ end
1032
956
  remove_synonym :synonym_to_posts
1033
957
  remove_synonym :synonym_to_posts_seq
1034
958
  end
1035
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
959
+ ActiveRecord::Base.clear_cache!
1036
960
  end
1037
961
 
1038
962
  it "should create synonym to table and sequence" do
1039
963
  schema_name = @username
1040
964
  schema_define do
1041
- add_synonym :synonym_to_posts, "#{schema_name}.test_posts", :force => true
1042
- add_synonym :synonym_to_posts_seq, "#{schema_name}.test_posts_seq", :force => true
965
+ add_synonym :synonym_to_posts, "#{schema_name}.test_posts", force: true
966
+ add_synonym :synonym_to_posts_seq, "#{schema_name}.test_posts_seq", force: true
1043
967
  end
1044
968
  expect do
1045
- TestPost.create(:title => "test")
969
+ TestPost.create(title: "test")
1046
970
  end.not_to raise_error
1047
971
  end
1048
972
 
1049
973
  it "should create synonym to table over database link" do
1050
974
  db_link = @db_link
1051
975
  schema_define do
1052
- add_synonym :synonym_to_posts, "test_posts@#{db_link}", :force => true
1053
- add_synonym :synonym_to_posts_seq, "test_posts_seq@#{db_link}", :force => true
976
+ add_synonym :synonym_to_posts, "test_posts@#{db_link}", force: true
977
+ add_synonym :synonym_to_posts_seq, "test_posts_seq@#{db_link}", force: true
1054
978
  end
1055
979
  expect do
1056
- TestPost.create(:title => "test")
980
+ TestPost.create(title: "test")
1057
981
  end.not_to raise_error
1058
982
  end
1059
983
 
@@ -1076,27 +1000,27 @@ end
1076
1000
 
1077
1001
  before(:each) do
1078
1002
  schema_define do
1079
- create_table :test_posts, :force => true do |t|
1080
- t.string :title, :null => false
1003
+ create_table :test_posts, force: true do |t|
1004
+ t.string :title, null: false
1081
1005
  t.string :content
1082
1006
  end
1083
1007
  end
1084
1008
  class ::TestPost < ActiveRecord::Base; end
1085
- expect(TestPost.columns_hash['title'].null).to be_falsey
1009
+ expect(TestPost.columns_hash["title"].null).to be_falsey
1086
1010
  end
1087
1011
 
1088
1012
  after(:each) do
1089
1013
  Object.send(:remove_const, "TestPost")
1090
1014
  schema_define { drop_table :test_posts }
1091
- ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
1015
+ ActiveRecord::Base.clear_cache!
1092
1016
  end
1093
1017
 
1094
1018
  it "should change column to nullable" do
1095
1019
  schema_define do
1096
- change_column :test_posts, :title, :string, :null => true
1020
+ change_column :test_posts, :title, :string, null: true
1097
1021
  end
1098
1022
  TestPost.reset_column_information
1099
- expect(TestPost.columns_hash['title'].null).to be_truthy
1023
+ expect(TestPost.columns_hash["title"].null).to be_truthy
1100
1024
  end
1101
1025
 
1102
1026
  it "should add column" do
@@ -1104,7 +1028,7 @@ end
1104
1028
  add_column :test_posts, :body, :string
1105
1029
  end
1106
1030
  TestPost.reset_column_information
1107
- expect(TestPost.columns_hash['body']).not_to be_nil
1031
+ expect(TestPost.columns_hash["body"]).not_to be_nil
1108
1032
  end
1109
1033
 
1110
1034
  it "should add lob column with non_default tablespace" do
@@ -1128,8 +1052,8 @@ end
1128
1052
  rename_column :test_posts, :title, :subject
1129
1053
  end
1130
1054
  TestPost.reset_column_information
1131
- expect(TestPost.columns_hash['subject']).not_to be_nil
1132
- expect(TestPost.columns_hash['title']).to be_nil
1055
+ expect(TestPost.columns_hash["subject"]).not_to be_nil
1056
+ expect(TestPost.columns_hash["title"]).to be_nil
1133
1057
  end
1134
1058
 
1135
1059
  it "should remove column" do
@@ -1137,7 +1061,7 @@ end
1137
1061
  remove_column :test_posts, :title
1138
1062
  end
1139
1063
  TestPost.reset_column_information
1140
- expect(TestPost.columns_hash['title']).to be_nil
1064
+ expect(TestPost.columns_hash["title"]).to be_nil
1141
1065
  end
1142
1066
 
1143
1067
  it "should remove column when using change_table" do
@@ -1147,7 +1071,7 @@ end
1147
1071
  end
1148
1072
  end
1149
1073
  TestPost.reset_column_information
1150
- expect(TestPost.columns_hash['title']).to be_nil
1074
+ expect(TestPost.columns_hash["title"]).to be_nil
1151
1075
  end
1152
1076
 
1153
1077
  it "should remove multiple columns when using change_table" do
@@ -1157,8 +1081,8 @@ end
1157
1081
  end
1158
1082
  end
1159
1083
  TestPost.reset_column_information
1160
- expect(TestPost.columns_hash['title']).to be_nil
1161
- expect(TestPost.columns_hash['content']).to be_nil
1084
+ expect(TestPost.columns_hash["title"]).to be_nil
1085
+ expect(TestPost.columns_hash["content"]).to be_nil
1162
1086
  end
1163
1087
 
1164
1088
  it "should ignore type and options parameter and remove column" do
@@ -1166,45 +1090,16 @@ end
1166
1090
  remove_column :test_posts, :title, :string, {}
1167
1091
  end
1168
1092
  TestPost.reset_column_information
1169
- expect(TestPost.columns_hash['title']).to be_nil
1093
+ expect(TestPost.columns_hash["title"]).to be_nil
1170
1094
  end
1171
1095
  end
1172
1096
 
1173
- describe 'virtual columns in create_table' do
1097
+ describe "virtual columns in create_table" do
1174
1098
  before(:each) do
1175
1099
  skip "Not supported in this database version" unless @oracle11g_or_higher
1176
1100
  end
1177
1101
 
1178
- it 'should create virtual column with old syntax' do
1179
- schema_define do
1180
- create_table :test_fractions, :force => true do |t|
1181
- t.integer :field1
1182
- t.virtual :field2, :default => 'field1 + 1'
1183
- end
1184
- end
1185
- class ::TestFraction < ActiveRecord::Base
1186
- self.table_name = "test_fractions"
1187
- end
1188
-
1189
- TestFraction.reset_column_information
1190
- tf = TestFraction.columns.detect { |c| c.virtual? }
1191
- expect(tf).not_to be nil
1192
- expect(tf.name).to eq("field2")
1193
- expect(tf.virtual?).to be true
1194
- expect do
1195
- tf = TestFraction.new(:field1=>10)
1196
- expect(tf.field2).to be nil # not whatever is in DATA_DEFAULT column
1197
- tf.save!
1198
- tf.reload
1199
- end.not_to raise_error
1200
- expect(tf.field2.to_i).to eq(11)
1201
-
1202
- schema_define do
1203
- drop_table :test_fractions
1204
- end
1205
- end
1206
-
1207
- it 'should raise error if column expression is not provided' do
1102
+ it "should raise error if column expression is not provided" do
1208
1103
  expect {
1209
1104
  schema_define do
1210
1105
  create_table :test_fractions do |t|
@@ -1216,15 +1111,15 @@ end
1216
1111
  end
1217
1112
  end
1218
1113
 
1219
- describe 'virtual columns' do
1114
+ describe "virtual columns" do
1220
1115
  before(:each) do
1221
1116
  skip "Not supported in this database version" unless @oracle11g_or_higher
1222
1117
  expr = "( numerator/NULLIF(denominator,0) )*100"
1223
1118
  schema_define do
1224
- create_table :test_fractions, :force => true do |t|
1225
- t.integer :numerator, :default=>0
1226
- t.integer :denominator, :default=>0
1227
- t.virtual :percent, :as => expr
1119
+ create_table :test_fractions, force: true do |t|
1120
+ t.integer :numerator, default: 0
1121
+ t.integer :denominator, default: 0
1122
+ t.virtual :percent, as: expr
1228
1123
  end
1229
1124
  end
1230
1125
  class ::TestFraction < ActiveRecord::Base
@@ -1241,13 +1136,13 @@ end
1241
1136
  end
1242
1137
  end
1243
1138
 
1244
- it 'should include virtual columns and not try to update them' do
1139
+ it "should include virtual columns and not try to update them" do
1245
1140
  tf = TestFraction.columns.detect { |c| c.virtual? }
1246
1141
  expect(tf).not_to be nil
1247
1142
  expect(tf.name).to eq("percent")
1248
1143
  expect(tf.virtual?).to be true
1249
1144
  expect do
1250
- tf = TestFraction.new(:numerator=>20, :denominator=>100)
1145
+ tf = TestFraction.new(numerator: 20, denominator: 100)
1251
1146
  expect(tf.percent).to be nil # not whatever is in DATA_DEFAULT column
1252
1147
  tf.save!
1253
1148
  tf.reload
@@ -1255,16 +1150,16 @@ end
1255
1150
  expect(tf.percent.to_i).to eq(20)
1256
1151
  end
1257
1152
 
1258
- it 'should add virtual column' do
1153
+ it "should add virtual column" do
1259
1154
  schema_define do
1260
- add_column :test_fractions, :rem, :virtual, :as => 'remainder(numerator, NULLIF(denominator,0))'
1155
+ add_column :test_fractions, :rem, :virtual, as: "remainder(numerator, NULLIF(denominator,0))"
1261
1156
  end
1262
1157
  TestFraction.reset_column_information
1263
- tf = TestFraction.columns.detect { |c| c.name == 'rem' }
1158
+ tf = TestFraction.columns.detect { |c| c.name == "rem" }
1264
1159
  expect(tf).not_to be nil
1265
1160
  expect(tf.virtual?).to be true
1266
1161
  expect do
1267
- tf = TestFraction.new(:numerator=>7, :denominator=>5)
1162
+ tf = TestFraction.new(numerator: 7, denominator: 5)
1268
1163
  expect(tf.rem).to be nil
1269
1164
  tf.save!
1270
1165
  tf.reload
@@ -1272,64 +1167,64 @@ end
1272
1167
  expect(tf.rem.to_i).to eq(2)
1273
1168
  end
1274
1169
 
1275
- it 'should add virtual column with explicit type' do
1170
+ it "should add virtual column with explicit type" do
1276
1171
  schema_define do
1277
- add_column :test_fractions, :expression, :virtual, :as => "TO_CHAR(numerator) || '/' || TO_CHAR(denominator)", :type => :string, :limit => 100
1172
+ add_column :test_fractions, :expression, :virtual, as: "TO_CHAR(numerator) || '/' || TO_CHAR(denominator)", type: :string, limit: 100
1278
1173
  end
1279
1174
  TestFraction.reset_column_information
1280
- tf = TestFraction.columns.detect { |c| c.name == 'expression' }
1175
+ tf = TestFraction.columns.detect { |c| c.name == "expression" }
1281
1176
  expect(tf).not_to be nil
1282
1177
  expect(tf.virtual?).to be true
1283
1178
  expect(tf.type).to be :string
1284
1179
  expect(tf.limit).to be 100
1285
1180
  expect do
1286
- tf = TestFraction.new(:numerator=>7, :denominator=>5)
1181
+ tf = TestFraction.new(numerator: 7, denominator: 5)
1287
1182
  expect(tf.expression).to be nil
1288
1183
  tf.save!
1289
1184
  tf.reload
1290
1185
  end.not_to raise_error
1291
- expect(tf.expression).to eq('7/5')
1186
+ expect(tf.expression).to eq("7/5")
1292
1187
  end
1293
1188
 
1294
- it 'should change virtual column definition' do
1189
+ it "should change virtual column definition" do
1295
1190
  schema_define do
1296
1191
  change_column :test_fractions, :percent, :virtual,
1297
- :as => "ROUND((numerator/NULLIF(denominator,0))*100, 2)", :type => :decimal, :precision => 15, :scale => 2
1192
+ as: "ROUND((numerator/NULLIF(denominator,0))*100, 2)", type: :decimal, precision: 15, scale: 2
1298
1193
  end
1299
1194
  TestFraction.reset_column_information
1300
- tf = TestFraction.columns.detect { |c| c.name == 'percent' }
1195
+ tf = TestFraction.columns.detect { |c| c.name == "percent" }
1301
1196
  expect(tf).not_to be nil
1302
1197
  expect(tf.virtual?).to be true
1303
1198
  expect(tf.type).to be :decimal
1304
1199
  expect(tf.precision).to be 15
1305
1200
  expect(tf.scale).to be 2
1306
1201
  expect do
1307
- tf = TestFraction.new(:numerator=>11, :denominator=>17)
1202
+ tf = TestFraction.new(numerator: 11, denominator: 17)
1308
1203
  expect(tf.percent).to be nil
1309
1204
  tf.save!
1310
1205
  tf.reload
1311
1206
  end.not_to raise_error
1312
- expect(tf.percent).to eq('64.71'.to_d)
1207
+ expect(tf.percent).to eq("64.71".to_d)
1313
1208
  end
1314
1209
 
1315
- it 'should change virtual column type' do
1210
+ it "should change virtual column type" do
1316
1211
  schema_define do
1317
- change_column :test_fractions, :percent, :virtual, :type => :decimal, :precision => 12, :scale => 5
1212
+ change_column :test_fractions, :percent, :virtual, type: :decimal, precision: 12, scale: 5
1318
1213
  end
1319
1214
  TestFraction.reset_column_information
1320
- tf = TestFraction.columns.detect { |c| c.name == 'percent' }
1215
+ tf = TestFraction.columns.detect { |c| c.name == "percent" }
1321
1216
  expect(tf).not_to be nil
1322
1217
  expect(tf.virtual?).to be true
1323
1218
  expect(tf.type).to be :decimal
1324
1219
  expect(tf.precision).to be 12
1325
1220
  expect(tf.scale).to be 5
1326
1221
  expect do
1327
- tf = TestFraction.new(:numerator=>11, :denominator=>17)
1222
+ tf = TestFraction.new(numerator: 11, denominator: 17)
1328
1223
  expect(tf.percent).to be nil
1329
1224
  tf.save!
1330
1225
  tf.reload
1331
1226
  end.not_to raise_error
1332
- expect(tf.percent).to eq('64.70588'.to_d)
1227
+ expect(tf.percent).to eq("64.70588".to_d)
1333
1228
  end
1334
1229
  end
1335
1230
 
@@ -1339,10 +1234,9 @@ end
1339
1234
  end
1340
1235
 
1341
1236
  before(:each) do
1342
- @conn.instance_variable_set :@would_execute_sql, @would_execute_sql=''
1237
+ @conn.instance_variable_set :@would_execute_sql, @would_execute_sql = ""
1343
1238
  class <<@conn
1344
- def execute(sql,name=nil); @would_execute_sql << sql << ";\n"; end
1345
- def index_name_exists?(table_name, index_name, default); default; end
1239
+ def execute(sql, name = nil); @would_execute_sql << sql << ";\n"; end
1346
1240
  end
1347
1241
  end
1348
1242
 
@@ -1350,13 +1244,13 @@ end
1350
1244
  class <<@conn
1351
1245
  remove_method :execute
1352
1246
  end
1353
- @conn.instance_eval{ remove_instance_variable :@would_execute_sql }
1247
+ @conn.instance_eval { remove_instance_variable :@would_execute_sql }
1354
1248
  end
1355
1249
 
1356
1250
  it "should support the :options option to create_table" do
1357
1251
  schema_define do
1358
- create_table :test_posts, :options=>'NOLOGGING', :force => true do |t|
1359
- t.string :title, :null => false
1252
+ create_table :test_posts, options: "NOLOGGING", force: true do |t|
1253
+ t.string :title, null: false
1360
1254
  end
1361
1255
  end
1362
1256
  expect(@would_execute_sql).to match(/CREATE +TABLE .* \(.*\) NOLOGGING/)
@@ -1364,8 +1258,8 @@ end
1364
1258
 
1365
1259
  it "should support the :tablespace option to create_table" do
1366
1260
  schema_define do
1367
- create_table :test_posts, :tablespace=>'bogus', :force => true do |t|
1368
- t.string :title, :null => false
1261
+ create_table :test_posts, tablespace: "bogus", force: true do |t|
1262
+ t.string :title, null: false
1369
1263
  end
1370
1264
  end
1371
1265
  expect(@would_execute_sql).to match(/CREATE +TABLE .* \(.*\) TABLESPACE bogus/)
@@ -1391,7 +1285,7 @@ end
1391
1285
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:table)
1392
1286
  end
1393
1287
  it "should use correct tablespace" do
1394
- @conn.create_table :tablespace_tests, :id=>false, :organization=>'INDEX INITRANS 4 COMPRESS 1', :tablespace=>'bogus' do |t|
1288
+ @conn.create_table :tablespace_tests, id: false, organization: "INDEX INITRANS 4 COMPRESS 1", tablespace: "bogus" do |t|
1395
1289
  t.integer :id
1396
1290
  end
1397
1291
  expect(@would_execute_sql).to match(/CREATE +TABLE .*\(.*\)\s+ORGANIZATION INDEX INITRANS 4 COMPRESS 1 TABLESPACE bogus/)
@@ -1400,14 +1294,14 @@ end
1400
1294
 
1401
1295
  it "should support the :options option to add_index" do
1402
1296
  schema_define do
1403
- add_index :keyboards, :name, :options=>'NOLOGGING'
1297
+ add_index :keyboards, :name, options: "NOLOGGING"
1404
1298
  end
1405
1299
  expect(@would_execute_sql).to match(/CREATE +INDEX .* ON .* \(.*\) NOLOGGING/)
1406
1300
  end
1407
1301
 
1408
1302
  it "should support the :tablespace option to add_index" do
1409
1303
  schema_define do
1410
- add_index :keyboards, :name, :tablespace=>'bogus'
1304
+ add_index :keyboards, :name, tablespace: "bogus"
1411
1305
  end
1412
1306
  expect(@would_execute_sql).to match(/CREATE +INDEX .* ON .* \(.*\) TABLESPACE bogus/)
1413
1307
  end
@@ -1423,7 +1317,7 @@ end
1423
1317
 
1424
1318
  it "should create unique function index but not create unique constraints" do
1425
1319
  schema_define do
1426
- add_index :keyboards, 'lower(name)', unique: true, name: :index_keyboards_on_lower_name
1320
+ add_index :keyboards, "lower(name)", unique: true, name: :index_keyboards_on_lower_name
1427
1321
  end
1428
1322
  expect(@would_execute_sql).not_to match(/ALTER +TABLE .* ADD CONSTRAINT .* UNIQUE \(.*\(.*\)\)/)
1429
1323
  end