activerecord-oracle_enhanced-adapter 1.6.9 → 1.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -11
- data/History.md +126 -14
- data/README.md +9 -6
- data/RUNNING_TESTS.md +1 -1
- data/Rakefile +1 -16
- data/VERSION +1 -1
- data/activerecord-oracle_enhanced-adapter.gemspec +15 -52
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +8 -22
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +53 -45
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +6 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +23 -62
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +46 -56
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +35 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +34 -21
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +36 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +174 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +17 -8
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +17 -11
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +160 -178
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +42 -94
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +50 -54
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +15 -11
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +197 -301
- data/lib/active_record/oracle_enhanced/type/integer.rb +3 -2
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +25 -0
- data/lib/active_record/oracle_enhanced/type/raw.rb +14 -2
- data/lib/active_record/oracle_enhanced/type/string.rb +28 -0
- data/lib/active_record/oracle_enhanced/type/text.rb +32 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +12 -17
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +113 -135
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +51 -59
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +40 -41
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +6 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +281 -233
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +7 -7
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +10 -10
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +22 -22
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +36 -37
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +86 -46
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +194 -294
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +53 -39
- data/spec/spec_helper.rb +0 -6
- metadata +42 -143
- data/.travis.yml +0 -39
- data/.travis/oracle/download.sh +0 -14
- data/.travis/oracle/install.sh +0 -31
- data/.travis/setup_accounts.sh +0 -9
- data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +0 -40
- data/lib/active_record/oracle_enhanced/type/timestamp.rb +0 -11
- data/spec/spec_config.yaml.template +0 -11
- data/spec/support/alter_system_user_password.sql +0 -2
- data/spec/support/create_oracle_enhanced_users.sql +0 -31
@@ -25,7 +25,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
25
25
|
it 'creates a sequence when adding a column with create_sequence = true' do
|
26
26
|
_, sequence_name = ActiveRecord::Base.connection.pk_and_sequence_for_without_cache(:keyboards)
|
27
27
|
|
28
|
-
sequence_name.
|
28
|
+
expect(sequence_name).to eq(Keyboard.sequence_name)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -60,11 +60,11 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should create sequence for non-default primary key" do
|
63
|
-
ActiveRecord::Base.connection.next_sequence_value(Keyboard.sequence_name).
|
63
|
+
expect(ActiveRecord::Base.connection.next_sequence_value(Keyboard.sequence_name)).not_to be_nil
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should create sequence for default primary key" do
|
67
|
-
ActiveRecord::Base.connection.next_sequence_value(IdKeyboard.sequence_name).
|
67
|
+
expect(ActiveRecord::Base.connection.next_sequence_value(IdKeyboard.sequence_name)).not_to be_nil
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -73,7 +73,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
73
73
|
it "should return sequence name without truncating too much" do
|
74
74
|
seq_name_length = ActiveRecord::Base.connection.sequence_name_length
|
75
75
|
tname = "#{DATABASE_USER}" + "." +"a"*(seq_name_length - DATABASE_USER.length) + "z"*(DATABASE_USER).length
|
76
|
-
ActiveRecord::Base.connection.default_sequence_name(tname).
|
76
|
+
expect(ActiveRecord::Base.connection.default_sequence_name(tname)).to match (/z_seq$/)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -114,13 +114,13 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should use default sequence start value 10000" do
|
117
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value.
|
117
|
+
expect(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value).to eq(10000)
|
118
118
|
|
119
119
|
create_test_employees_table
|
120
120
|
class ::TestEmployee < ActiveRecord::Base; end
|
121
121
|
|
122
122
|
employee = TestEmployee.create!
|
123
|
-
employee.id.
|
123
|
+
expect(employee.id).to eq(10000)
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should use specified default sequence start value" do
|
@@ -130,7 +130,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
130
130
|
class ::TestEmployee < ActiveRecord::Base; end
|
131
131
|
|
132
132
|
employee = TestEmployee.create!
|
133
|
-
employee.id.
|
133
|
+
expect(employee.id).to eq(1)
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should use sequence start value from table definition" do
|
@@ -138,7 +138,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
138
138
|
class ::TestEmployee < ActiveRecord::Base; end
|
139
139
|
|
140
140
|
employee = TestEmployee.create!
|
141
|
-
employee.id.
|
141
|
+
expect(employee.id).to eq(10)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should use sequence start value and other options from table definition" do
|
@@ -146,9 +146,9 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
146
146
|
class ::TestEmployee < ActiveRecord::Base; end
|
147
147
|
|
148
148
|
employee = TestEmployee.create!
|
149
|
-
employee.id.
|
149
|
+
expect(employee.id).to eq(100)
|
150
150
|
employee = TestEmployee.create!
|
151
|
-
employee.id.
|
151
|
+
expect(employee.id).to eq(110)
|
152
152
|
end
|
153
153
|
|
154
154
|
end
|
@@ -198,26 +198,26 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should populate primary key using trigger" do
|
201
|
-
|
201
|
+
expect do
|
202
202
|
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
203
|
-
end.
|
203
|
+
end.not_to raise_error
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should return new key value using connection insert method" do
|
207
207
|
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, "id")
|
208
|
-
@conn.select_value("SELECT test_employees_seq.currval FROM dual").
|
208
|
+
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(insert_id)
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should create new record for model" do
|
212
212
|
e = TestEmployee.create!(:first_name => 'Raimonds')
|
213
|
-
@conn.select_value("SELECT test_employees_seq.currval FROM dual").
|
213
|
+
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should not generate NoMethodError for :returning_id:Symbol" do
|
217
217
|
set_logger
|
218
218
|
@conn.reconnect! unless @conn.active?
|
219
219
|
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Yasuo')", nil, "id")
|
220
|
-
@logger.output(:error).
|
220
|
+
expect(@logger.output(:error)).not_to match(/^Could not log "sql.active_record" event. NoMethodError: undefined method `name' for :returning_id:Symbol/)
|
221
221
|
clear_logger
|
222
222
|
end
|
223
223
|
|
@@ -237,19 +237,19 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
237
237
|
end
|
238
238
|
|
239
239
|
it "should populate primary key using trigger" do
|
240
|
-
|
240
|
+
expect do
|
241
241
|
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
242
|
-
end.
|
242
|
+
end.not_to raise_error
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should return new key value using connection insert method" do
|
246
246
|
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, "id")
|
247
|
-
@conn.select_value("SELECT test_employees_seq.currval FROM dual").
|
247
|
+
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(insert_id)
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should create new record for model" do
|
251
251
|
e = TestEmployee.create!(:first_name => 'Raimonds')
|
252
|
-
@conn.select_value("SELECT test_employees_seq.currval FROM dual").
|
252
|
+
expect(@conn.select_value("SELECT test_employees_seq.currval FROM dual")).to eq(e.id)
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
@@ -270,19 +270,19 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should populate primary key using trigger" do
|
273
|
-
|
273
|
+
expect do
|
274
274
|
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
275
|
-
end.
|
275
|
+
end.not_to raise_error
|
276
276
|
end
|
277
277
|
|
278
278
|
it "should return new key value using connection insert method" do
|
279
279
|
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, @primary_key)
|
280
|
-
@conn.select_value("SELECT #{@sequence_name}.currval FROM dual").
|
280
|
+
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(insert_id)
|
281
281
|
end
|
282
282
|
|
283
283
|
it "should create new record for model with autogenerated sequence option" do
|
284
284
|
e = TestEmployee.create!(:first_name => 'Raimonds')
|
285
|
-
@conn.select_value("SELECT #{@sequence_name}.currval FROM dual").
|
285
|
+
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
@@ -302,19 +302,19 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
302
302
|
end
|
303
303
|
|
304
304
|
it "should populate primary key using trigger" do
|
305
|
-
|
305
|
+
expect do
|
306
306
|
@conn.execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
|
307
|
-
end.
|
307
|
+
end.not_to raise_error
|
308
308
|
end
|
309
309
|
|
310
310
|
it "should return new key value using connection insert method" do
|
311
311
|
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Raimonds')", nil, "id")
|
312
|
-
@conn.select_value("SELECT #{@sequence_name}.currval FROM dual").
|
312
|
+
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(insert_id)
|
313
313
|
end
|
314
314
|
|
315
315
|
it "should create new record for model with autogenerated sequence option" do
|
316
316
|
e = TestEmployee.create!(:first_name => 'Raimonds')
|
317
|
-
@conn.select_value("SELECT #{@sequence_name}.currval FROM dual").
|
317
|
+
expect(@conn.select_value("SELECT #{@sequence_name}.currval FROM dual")).to eq(e.id)
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
@@ -349,8 +349,8 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
349
349
|
create_test_employees_table(table_comment)
|
350
350
|
class ::TestEmployee < ActiveRecord::Base; end
|
351
351
|
|
352
|
-
@conn.table_comment("test_employees").
|
353
|
-
TestEmployee.table_comment.
|
352
|
+
expect(@conn.table_comment("test_employees")).to eq(table_comment)
|
353
|
+
expect(TestEmployee.table_comment).to eq(table_comment)
|
354
354
|
end
|
355
355
|
|
356
356
|
it "should create table with columns comment" do
|
@@ -359,11 +359,12 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
359
359
|
class ::TestEmployee < ActiveRecord::Base; end
|
360
360
|
|
361
361
|
[:first_name, :last_name].each do |attr|
|
362
|
-
@conn.column_comment("test_employees", attr.to_s).
|
363
|
-
end
|
364
|
-
[:first_name, :last_name].each do |attr|
|
365
|
-
TestEmployee.columns_hash[attr.to_s].comment.should == column_comments[attr]
|
362
|
+
expect(@conn.column_comment("test_employees", attr.to_s)).to eq(column_comments[attr])
|
366
363
|
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
|
367
368
|
end
|
368
369
|
|
369
370
|
it "should create table with table and columns comment and custom table name prefix" do
|
@@ -373,14 +374,15 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
373
374
|
create_test_employees_table(table_comment, column_comments)
|
374
375
|
class ::TestEmployee < ActiveRecord::Base; end
|
375
376
|
|
376
|
-
@conn.table_comment(TestEmployee.table_name).
|
377
|
-
TestEmployee.table_comment.
|
378
|
-
[:first_name, :last_name].each do |attr|
|
379
|
-
@conn.column_comment(TestEmployee.table_name, attr.to_s).should == column_comments[attr]
|
380
|
-
end
|
377
|
+
expect(@conn.table_comment(TestEmployee.table_name)).to eq(table_comment)
|
378
|
+
expect(TestEmployee.table_comment).to eq(table_comment)
|
381
379
|
[:first_name, :last_name].each do |attr|
|
382
|
-
TestEmployee.
|
380
|
+
expect(@conn.column_comment(TestEmployee.table_name, attr.to_s)).to eq(column_comments[attr])
|
383
381
|
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
|
384
386
|
end
|
385
387
|
|
386
388
|
end
|
@@ -391,9 +393,9 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
391
393
|
end
|
392
394
|
|
393
395
|
it "should drop table with :if_exists option no raise error" do
|
394
|
-
|
396
|
+
expect do
|
395
397
|
@conn.drop_table("nonexistent_table", if_exists: true)
|
396
|
-
end.
|
398
|
+
end.not_to raise_error
|
397
399
|
end
|
398
400
|
end
|
399
401
|
|
@@ -428,27 +430,27 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
428
430
|
end
|
429
431
|
|
430
432
|
it "should rename table name with new one" do
|
431
|
-
|
433
|
+
expect do
|
432
434
|
@conn.rename_table("test_employees","new_test_employees")
|
433
|
-
end.
|
435
|
+
end.not_to raise_error
|
434
436
|
end
|
435
437
|
|
436
438
|
it "should raise error when new table name length is too long" do
|
437
|
-
|
439
|
+
expect do
|
438
440
|
@conn.rename_table("test_employees","a"*31)
|
439
|
-
end.
|
441
|
+
end.to raise_error
|
440
442
|
end
|
441
443
|
|
442
444
|
it "should not raise error when new sequence name length is too long" do
|
443
|
-
|
445
|
+
expect do
|
444
446
|
@conn.rename_table("test_employees","a"*27)
|
445
|
-
end.
|
447
|
+
end.not_to raise_error
|
446
448
|
end
|
447
449
|
|
448
450
|
it "should rename table when table has no primary key and sequence" do
|
449
|
-
|
451
|
+
expect do
|
450
452
|
@conn.rename_table("test_employees_no_pkey","new_test_employees_no_pkey")
|
451
|
-
end.
|
453
|
+
end.not_to raise_error
|
452
454
|
end
|
453
455
|
|
454
456
|
end
|
@@ -475,7 +477,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
475
477
|
end
|
476
478
|
|
477
479
|
it "should create table trigger with :new reference" do
|
478
|
-
|
480
|
+
expect do
|
479
481
|
@conn.execute <<-SQL
|
480
482
|
CREATE OR REPLACE TRIGGER test_employees_pkt
|
481
483
|
BEFORE INSERT ON test_employees FOR EACH ROW
|
@@ -487,7 +489,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
487
489
|
END IF;
|
488
490
|
END;
|
489
491
|
SQL
|
490
|
-
end.
|
492
|
+
end.not_to raise_error
|
491
493
|
end
|
492
494
|
end
|
493
495
|
|
@@ -497,20 +499,21 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
497
499
|
end
|
498
500
|
|
499
501
|
it "should return default index name if it is not larger than 30 characters" do
|
500
|
-
@conn.index_name("employees", :column => "first_name").
|
502
|
+
expect(@conn.index_name("employees", :column => "first_name")).to eq("index_employees_on_first_name")
|
501
503
|
end
|
502
504
|
|
503
505
|
it "should return shortened index name by removing 'index', 'on' and 'and' keywords" do
|
504
|
-
@conn.index_name("employees", :column => ["first_name", "email"]).
|
506
|
+
expect(@conn.index_name("employees", :column => ["first_name", "email"])).to eq("i_employees_first_name_email")
|
505
507
|
end
|
506
508
|
|
507
509
|
it "should return shortened index name by shortening table and column names" do
|
508
|
-
@conn.index_name("employees", :column => ["first_name", "last_name"]).
|
510
|
+
expect(@conn.index_name("employees", :column => ["first_name", "last_name"])).to eq("i_emp_fir_nam_las_nam")
|
509
511
|
end
|
510
512
|
|
511
513
|
it "should raise error if too large index name cannot be shortened" do
|
512
|
-
@conn.index_name("test_employees", :column => ["first_name", "middle_name", "last_name"]).
|
514
|
+
expect(@conn.index_name("test_employees", :column => ["first_name", "middle_name", "last_name"])).to eq(
|
513
515
|
'i'+Digest::SHA1.hexdigest("index_test_employees_on_first_name_and_middle_name_and_last_name")[0,29]
|
516
|
+
)
|
514
517
|
end
|
515
518
|
|
516
519
|
end
|
@@ -537,27 +540,27 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
537
540
|
end
|
538
541
|
|
539
542
|
it "should raise error when current index name and new index name are identical" do
|
540
|
-
|
543
|
+
expect do
|
541
544
|
@conn.rename_index("test_employees","i_test_employees_first_name","i_test_employees_first_name")
|
542
|
-
end.
|
545
|
+
end.to raise_error
|
543
546
|
end
|
544
547
|
|
545
548
|
it "should raise error when new index name length is too long" do
|
546
|
-
|
549
|
+
expect do
|
547
550
|
@conn.rename_index("test_employees","i_test_employees_first_name","a"*31)
|
548
|
-
end.
|
551
|
+
end.to raise_error
|
549
552
|
end
|
550
553
|
|
551
554
|
it "should raise error when current index name does not exist" do
|
552
|
-
|
555
|
+
expect do
|
553
556
|
@conn.rename_index("test_employees","nonexist_index_name","new_index_name")
|
554
|
-
end.
|
557
|
+
end.to raise_error
|
555
558
|
end
|
556
559
|
|
557
560
|
it "should rename index name with new one" do
|
558
|
-
|
561
|
+
expect do
|
559
562
|
@conn.rename_index("test_employees","i_test_employees_first_name","new_index_name")
|
560
|
-
end.
|
563
|
+
end.not_to raise_error
|
561
564
|
end
|
562
565
|
end
|
563
566
|
|
@@ -569,23 +572,23 @@ end
|
|
569
572
|
end
|
570
573
|
|
571
574
|
it "should ignore :limit option for :text column" do
|
572
|
-
|
575
|
+
expect do
|
573
576
|
schema_define do
|
574
577
|
create_table :test_posts, :force => true do |t|
|
575
578
|
t.text :body, :limit => 10000
|
576
579
|
end
|
577
580
|
end
|
578
|
-
end.
|
581
|
+
end.not_to raise_error
|
579
582
|
end
|
580
583
|
|
581
584
|
it "should ignore :limit option for :binary column" do
|
582
|
-
|
585
|
+
expect do
|
583
586
|
schema_define do
|
584
587
|
create_table :test_posts, :force => true do |t|
|
585
588
|
t.binary :picture, :limit => 10000
|
586
589
|
end
|
587
590
|
end
|
588
|
-
end.
|
591
|
+
end.not_to raise_error
|
589
592
|
end
|
590
593
|
|
591
594
|
end
|
@@ -633,9 +636,9 @@ end
|
|
633
636
|
schema_define do
|
634
637
|
add_foreign_key :test_comments, :test_posts
|
635
638
|
end
|
636
|
-
|
639
|
+
expect do
|
637
640
|
TestComment.create(:body => "test", :test_post_id => 1)
|
638
|
-
end.
|
641
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
639
642
|
end
|
640
643
|
|
641
644
|
context "with table_name_prefix" do
|
@@ -647,9 +650,9 @@ end
|
|
647
650
|
add_foreign_key :test_comments, :test_posts
|
648
651
|
end
|
649
652
|
|
650
|
-
|
653
|
+
expect do
|
651
654
|
TestComment.create(:body => "test", :test_post_id => 1)
|
652
|
-
end.
|
655
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
653
656
|
end
|
654
657
|
end
|
655
658
|
|
@@ -662,9 +665,9 @@ end
|
|
662
665
|
add_foreign_key :test_comments, :test_posts
|
663
666
|
end
|
664
667
|
|
665
|
-
|
668
|
+
expect do
|
666
669
|
TestComment.create(:body => "test", :test_post_id => 1)
|
667
|
-
end.
|
670
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
668
671
|
end
|
669
672
|
end
|
670
673
|
|
@@ -672,29 +675,31 @@ end
|
|
672
675
|
schema_define do
|
673
676
|
add_foreign_key :test_comments, :test_posts, :name => "comments_posts_fk"
|
674
677
|
end
|
675
|
-
|
678
|
+
expect do
|
676
679
|
TestComment.create(:body => "test", :test_post_id => 1)
|
677
|
-
end.
|
680
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.COMMENTS_POSTS_FK/)}
|
678
681
|
end
|
679
682
|
|
680
683
|
it "should add foreign key with long name which is shortened" do
|
681
684
|
schema_define do
|
682
685
|
add_foreign_key :test_comments, :test_posts, :name => "test_comments_test_post_id_foreign_key"
|
683
686
|
end
|
684
|
-
|
687
|
+
expect do
|
685
688
|
TestComment.create(:body => "test", :test_post_id => 1)
|
686
|
-
end.
|
687
|
-
/ORA-02291.*\.C#{Digest::SHA1.hexdigest("test_comments_test_post_id_foreign_key")[0,29].upcase}/
|
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
|
+
)}
|
688
692
|
end
|
689
693
|
|
690
694
|
it "should add foreign key with very long name which is shortened" do
|
691
695
|
schema_define do
|
692
696
|
add_foreign_key :test_comments, :test_posts, :name => "long_prefix_test_comments_test_post_id_foreign_key"
|
693
697
|
end
|
694
|
-
|
698
|
+
expect do
|
695
699
|
TestComment.create(:body => "test", :test_post_id => 1)
|
696
|
-
end.
|
697
|
-
/ORA-02291.*\.C#{Digest::SHA1.hexdigest("long_prefix_test_comments_test_post_id_foreign_key")[0,29].upcase}/
|
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
|
+
)}
|
698
703
|
end
|
699
704
|
|
700
705
|
it "should add foreign key with column" do
|
@@ -703,9 +708,9 @@ end
|
|
703
708
|
schema_define do
|
704
709
|
add_foreign_key :test_comments, :test_posts, :column => "post_id"
|
705
710
|
end
|
706
|
-
|
711
|
+
expect do
|
707
712
|
TestComment.create(:body => "test", :post_id => 1)
|
708
|
-
end.
|
713
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.#{fk_name}/i)}
|
709
714
|
end
|
710
715
|
|
711
716
|
it "should add foreign key with delete dependency" do
|
@@ -715,7 +720,7 @@ end
|
|
715
720
|
p = TestPost.create(:title => "test")
|
716
721
|
c = TestComment.create(:body => "test", :test_post => p)
|
717
722
|
TestPost.delete(p.id)
|
718
|
-
TestComment.find_by_id(c.id).
|
723
|
+
expect(TestComment.find_by_id(c.id)).to be_nil
|
719
724
|
end
|
720
725
|
|
721
726
|
it "should add foreign key with nullify dependency" do
|
@@ -725,7 +730,7 @@ end
|
|
725
730
|
p = TestPost.create(:title => "test")
|
726
731
|
c = TestComment.create(:body => "test", :test_post => p)
|
727
732
|
TestPost.delete(p.id)
|
728
|
-
TestComment.find_by_id(c.id).test_post_id.
|
733
|
+
expect(TestComment.find_by_id(c.id).test_post_id).to be_nil
|
729
734
|
end
|
730
735
|
|
731
736
|
it "should add a composite foreign key" do
|
@@ -745,10 +750,11 @@ end
|
|
745
750
|
add_foreign_key :test_comments, :test_posts, :columns => ["baz_id", "fooz_id"]
|
746
751
|
end
|
747
752
|
|
748
|
-
|
753
|
+
expect do
|
749
754
|
TestComment.create(:body => "test", :fooz_id => 1, :baz_id => 1)
|
750
|
-
end.
|
751
|
-
/ORA-02291.*\.TES_COM_BAZ_ID_FOO_ID_FK/
|
755
|
+
end.to raise_error() {|e| expect(e.message).to match(
|
756
|
+
/ORA-02291.*\.TES_COM_BAZ_ID_FOO_ID_FK/
|
757
|
+
)}
|
752
758
|
end
|
753
759
|
|
754
760
|
it "should add a composite foreign key with name" do
|
@@ -768,9 +774,9 @@ end
|
|
768
774
|
add_foreign_key :test_comments, :test_posts, :columns => ["baz_id", "fooz_id"], :name => 'comments_posts_baz_fooz_fk'
|
769
775
|
end
|
770
776
|
|
771
|
-
|
777
|
+
expect do
|
772
778
|
TestComment.create(:body => "test", :baz_id => 1, :fooz_id => 1)
|
773
|
-
end.
|
779
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291.*\.COMMENTS_POSTS_BAZ_FOOZ_FK/)}
|
774
780
|
end
|
775
781
|
|
776
782
|
it "should remove foreign key by table name" do
|
@@ -778,9 +784,9 @@ end
|
|
778
784
|
add_foreign_key :test_comments, :test_posts
|
779
785
|
remove_foreign_key :test_comments, :test_posts
|
780
786
|
end
|
781
|
-
|
787
|
+
expect do
|
782
788
|
TestComment.create(:body => "test", :test_post_id => 1)
|
783
|
-
end.
|
789
|
+
end.not_to raise_error
|
784
790
|
end
|
785
791
|
|
786
792
|
it "should remove foreign key by constraint name" do
|
@@ -788,9 +794,9 @@ end
|
|
788
794
|
add_foreign_key :test_comments, :test_posts, :name => "comments_posts_fk"
|
789
795
|
remove_foreign_key :test_comments, :name => "comments_posts_fk"
|
790
796
|
end
|
791
|
-
|
797
|
+
expect do
|
792
798
|
TestComment.create(:body => "test", :test_post_id => 1)
|
793
|
-
end.
|
799
|
+
end.not_to raise_error
|
794
800
|
end
|
795
801
|
|
796
802
|
it "should remove foreign key by column name" do
|
@@ -798,9 +804,9 @@ end
|
|
798
804
|
add_foreign_key :test_comments, :test_posts
|
799
805
|
remove_foreign_key :test_comments, :column => "test_post_id"
|
800
806
|
end
|
801
|
-
|
807
|
+
expect do
|
802
808
|
TestComment.create(:body => "test", :test_post_id => 1)
|
803
|
-
end.
|
809
|
+
end.not_to raise_error
|
804
810
|
end
|
805
811
|
|
806
812
|
end
|
@@ -819,8 +825,8 @@ end
|
|
819
825
|
t.binary :test_blob
|
820
826
|
end
|
821
827
|
end
|
822
|
-
TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'").
|
823
|
-
TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'").
|
828
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
829
|
+
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)
|
824
830
|
end
|
825
831
|
|
826
832
|
it 'should use default tablespace for blobs' do
|
@@ -832,8 +838,8 @@ end
|
|
832
838
|
t.binary :test_blob
|
833
839
|
end
|
834
840
|
end
|
835
|
-
TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'").
|
836
|
-
TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'").
|
841
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_BLOB'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
842
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'TEST_CLOB'")).not_to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
837
843
|
end
|
838
844
|
|
839
845
|
after do
|
@@ -844,53 +850,6 @@ end
|
|
844
850
|
end
|
845
851
|
end
|
846
852
|
|
847
|
-
describe "primary key in table definition" do
|
848
|
-
before do
|
849
|
-
@conn = ActiveRecord::Base.connection
|
850
|
-
|
851
|
-
class ::TestPost < ActiveRecord::Base
|
852
|
-
end
|
853
|
-
end
|
854
|
-
|
855
|
-
it 'should use default tablespace for primary key' do
|
856
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = nil
|
857
|
-
schema_define do
|
858
|
-
create_table :test_posts, :force => true
|
859
|
-
end
|
860
|
-
|
861
|
-
index_name = @conn.select_value(
|
862
|
-
"SELECT index_name FROM all_constraints
|
863
|
-
WHERE table_name = 'TEST_POSTS'
|
864
|
-
AND constraint_type = 'P'
|
865
|
-
AND owner = SYS_CONTEXT('userenv', 'current_schema')")
|
866
|
-
|
867
|
-
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq('USERS')
|
868
|
-
end
|
869
|
-
|
870
|
-
it 'should use non default tablespace for primary key' do
|
871
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = DATABASE_NON_DEFAULT_TABLESPACE
|
872
|
-
schema_define do
|
873
|
-
create_table :test_posts, :force => true
|
874
|
-
end
|
875
|
-
|
876
|
-
index_name = @conn.select_value(
|
877
|
-
"SELECT index_name FROM all_constraints
|
878
|
-
WHERE table_name = 'TEST_POSTS'
|
879
|
-
AND constraint_type = 'P'
|
880
|
-
AND owner = SYS_CONTEXT('userenv', 'current_schema')")
|
881
|
-
|
882
|
-
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_indexes WHERE index_name = '#{index_name}'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
883
|
-
end
|
884
|
-
|
885
|
-
after do
|
886
|
-
Object.send(:remove_const, "TestPost")
|
887
|
-
schema_define do
|
888
|
-
drop_table :test_posts rescue nil
|
889
|
-
end
|
890
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:index] = nil
|
891
|
-
end
|
892
|
-
end
|
893
|
-
|
894
853
|
describe "foreign key in table definition" do
|
895
854
|
before(:each) do
|
896
855
|
schema_define do
|
@@ -924,9 +883,9 @@ end
|
|
924
883
|
t.foreign_key :test_posts
|
925
884
|
end
|
926
885
|
end
|
927
|
-
|
886
|
+
expect do
|
928
887
|
TestComment.create(:body => "test", :test_post_id => 1)
|
929
|
-
end.
|
888
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
930
889
|
end
|
931
890
|
|
932
891
|
it "should add foreign key in create_table references" do
|
@@ -936,9 +895,9 @@ end
|
|
936
895
|
t.references :test_post, :foreign_key => true
|
937
896
|
end
|
938
897
|
end
|
939
|
-
|
898
|
+
expect do
|
940
899
|
TestComment.create(:body => "test", :test_post_id => 1)
|
941
|
-
end.
|
900
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
942
901
|
end
|
943
902
|
|
944
903
|
it "should add foreign key in change_table" do
|
@@ -951,9 +910,9 @@ end
|
|
951
910
|
t.foreign_key :test_posts
|
952
911
|
end
|
953
912
|
end
|
954
|
-
|
913
|
+
expect do
|
955
914
|
TestComment.create(:body => "test", :test_post_id => 1)
|
956
|
-
end.
|
915
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
957
916
|
end
|
958
917
|
|
959
918
|
it "should add foreign key in change_table references" do
|
@@ -965,9 +924,9 @@ end
|
|
965
924
|
t.references :test_post, :foreign_key => true
|
966
925
|
end
|
967
926
|
end
|
968
|
-
|
927
|
+
expect do
|
969
928
|
TestComment.create(:body => "test", :test_post_id => 1)
|
970
|
-
end.
|
929
|
+
end.to raise_error() {|e| expect(e.message).to match(/ORA-02291/)}
|
971
930
|
end
|
972
931
|
|
973
932
|
it "should remove foreign key by table name" do
|
@@ -983,9 +942,9 @@ end
|
|
983
942
|
t.remove_foreign_key :test_posts
|
984
943
|
end
|
985
944
|
end
|
986
|
-
|
945
|
+
expect do
|
987
946
|
TestComment.create(:body => "test", :test_post_id => 1)
|
988
|
-
end.
|
947
|
+
end.not_to raise_error
|
989
948
|
end
|
990
949
|
|
991
950
|
end
|
@@ -1015,18 +974,18 @@ end
|
|
1015
974
|
end
|
1016
975
|
|
1017
976
|
it "should disable all foreign keys" do
|
1018
|
-
|
977
|
+
expect do
|
1019
978
|
@conn.execute "INSERT INTO test_comments (id, body, test_post_id) VALUES (1, 'test', 1)"
|
1020
|
-
end.
|
979
|
+
end.to raise_error
|
1021
980
|
@conn.disable_referential_integrity do
|
1022
|
-
|
981
|
+
expect do
|
1023
982
|
@conn.execute "INSERT INTO test_comments (id, body, test_post_id) VALUES (2, 'test', 2)"
|
1024
983
|
@conn.execute "INSERT INTO test_posts (id, title) VALUES (2, 'test')"
|
1025
|
-
end.
|
984
|
+
end.not_to raise_error
|
1026
985
|
end
|
1027
|
-
|
986
|
+
expect do
|
1028
987
|
@conn.execute "INSERT INTO test_comments (id, body, test_post_id) VALUES (3, 'test', 3)"
|
1029
|
-
end.
|
988
|
+
end.to raise_error
|
1030
989
|
end
|
1031
990
|
|
1032
991
|
end
|
@@ -1075,9 +1034,9 @@ end
|
|
1075
1034
|
add_synonym :synonym_to_posts, "#{schema_name}.test_posts", :force => true
|
1076
1035
|
add_synonym :synonym_to_posts_seq, "#{schema_name}.test_posts_seq", :force => true
|
1077
1036
|
end
|
1078
|
-
|
1037
|
+
expect do
|
1079
1038
|
TestPost.create(:title => "test")
|
1080
|
-
end.
|
1039
|
+
end.not_to raise_error
|
1081
1040
|
end
|
1082
1041
|
|
1083
1042
|
it "should create synonym to table over database link" do
|
@@ -1086,9 +1045,9 @@ end
|
|
1086
1045
|
add_synonym :synonym_to_posts, "test_posts@#{db_link}", :force => true
|
1087
1046
|
add_synonym :synonym_to_posts_seq, "test_posts_seq@#{db_link}", :force => true
|
1088
1047
|
end
|
1089
|
-
|
1048
|
+
expect do
|
1090
1049
|
TestPost.create(:title => "test")
|
1091
|
-
end.
|
1050
|
+
end.not_to raise_error
|
1092
1051
|
end
|
1093
1052
|
|
1094
1053
|
end
|
@@ -1116,7 +1075,7 @@ end
|
|
1116
1075
|
end
|
1117
1076
|
end
|
1118
1077
|
class ::TestPost < ActiveRecord::Base; end
|
1119
|
-
TestPost.columns_hash['title'].null.
|
1078
|
+
expect(TestPost.columns_hash['title'].null).to be_falsey
|
1120
1079
|
end
|
1121
1080
|
|
1122
1081
|
after(:each) do
|
@@ -1130,7 +1089,7 @@ end
|
|
1130
1089
|
change_column :test_posts, :title, :string, :null => true
|
1131
1090
|
end
|
1132
1091
|
TestPost.reset_column_information
|
1133
|
-
TestPost.columns_hash['title'].null.
|
1092
|
+
expect(TestPost.columns_hash['title'].null).to be_truthy
|
1134
1093
|
end
|
1135
1094
|
|
1136
1095
|
it "should add column" do
|
@@ -1138,7 +1097,7 @@ end
|
|
1138
1097
|
add_column :test_posts, :body, :string
|
1139
1098
|
end
|
1140
1099
|
TestPost.reset_column_information
|
1141
|
-
TestPost.columns_hash['body'].
|
1100
|
+
expect(TestPost.columns_hash['body']).not_to be_nil
|
1142
1101
|
end
|
1143
1102
|
|
1144
1103
|
it "should add lob column with non_default tablespace" do
|
@@ -1146,7 +1105,7 @@ end
|
|
1146
1105
|
schema_define do
|
1147
1106
|
add_column :test_posts, :body, :text
|
1148
1107
|
end
|
1149
|
-
TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'BODY'").
|
1108
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'BODY'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
1150
1109
|
end
|
1151
1110
|
|
1152
1111
|
it "should add blob column with non_default tablespace" do
|
@@ -1154,7 +1113,7 @@ end
|
|
1154
1113
|
schema_define do
|
1155
1114
|
add_column :test_posts, :attachment, :binary
|
1156
1115
|
end
|
1157
|
-
TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'ATTACHMENT'").
|
1116
|
+
expect(TestPost.connection.select_value("SELECT tablespace_name FROM user_lobs WHERE table_name='TEST_POSTS' and column_name = 'ATTACHMENT'")).to eq(DATABASE_NON_DEFAULT_TABLESPACE)
|
1158
1117
|
end
|
1159
1118
|
|
1160
1119
|
it "should rename column" do
|
@@ -1162,8 +1121,8 @@ end
|
|
1162
1121
|
rename_column :test_posts, :title, :subject
|
1163
1122
|
end
|
1164
1123
|
TestPost.reset_column_information
|
1165
|
-
TestPost.columns_hash['subject'].
|
1166
|
-
TestPost.columns_hash['title'].
|
1124
|
+
expect(TestPost.columns_hash['subject']).not_to be_nil
|
1125
|
+
expect(TestPost.columns_hash['title']).to be_nil
|
1167
1126
|
end
|
1168
1127
|
|
1169
1128
|
it "should remove column" do
|
@@ -1171,7 +1130,7 @@ end
|
|
1171
1130
|
remove_column :test_posts, :title
|
1172
1131
|
end
|
1173
1132
|
TestPost.reset_column_information
|
1174
|
-
TestPost.columns_hash['title'].
|
1133
|
+
expect(TestPost.columns_hash['title']).to be_nil
|
1175
1134
|
end
|
1176
1135
|
|
1177
1136
|
it "should remove column when using change_table" do
|
@@ -1181,7 +1140,7 @@ end
|
|
1181
1140
|
end
|
1182
1141
|
end
|
1183
1142
|
TestPost.reset_column_information
|
1184
|
-
TestPost.columns_hash['title'].
|
1143
|
+
expect(TestPost.columns_hash['title']).to be_nil
|
1185
1144
|
end
|
1186
1145
|
|
1187
1146
|
it "should remove multiple columns when using change_table" do
|
@@ -1191,8 +1150,8 @@ end
|
|
1191
1150
|
end
|
1192
1151
|
end
|
1193
1152
|
TestPost.reset_column_information
|
1194
|
-
TestPost.columns_hash['title'].
|
1195
|
-
TestPost.columns_hash['content'].
|
1153
|
+
expect(TestPost.columns_hash['title']).to be_nil
|
1154
|
+
expect(TestPost.columns_hash['content']).to be_nil
|
1196
1155
|
end
|
1197
1156
|
|
1198
1157
|
it "should ignore type and options parameter and remove column" do
|
@@ -1200,7 +1159,7 @@ end
|
|
1200
1159
|
remove_column :test_posts, :title, :string, {}
|
1201
1160
|
end
|
1202
1161
|
TestPost.reset_column_information
|
1203
|
-
TestPost.columns_hash['title'].
|
1162
|
+
expect(TestPost.columns_hash['title']).to be_nil
|
1204
1163
|
end
|
1205
1164
|
end
|
1206
1165
|
|
@@ -1222,16 +1181,16 @@ end
|
|
1222
1181
|
|
1223
1182
|
TestFraction.reset_column_information
|
1224
1183
|
tf = TestFraction.columns.detect { |c| c.virtual? }
|
1225
|
-
tf.
|
1226
|
-
tf.name.
|
1227
|
-
tf.virtual
|
1228
|
-
|
1184
|
+
expect(tf).not_to be nil
|
1185
|
+
expect(tf.name).to eq("field2")
|
1186
|
+
expect(tf.virtual?).to be true
|
1187
|
+
expect do
|
1229
1188
|
tf = TestFraction.new(:field1=>10)
|
1230
|
-
tf.field2.
|
1189
|
+
expect(tf.field2).to be nil # not whatever is in DATA_DEFAULT column
|
1231
1190
|
tf.save!
|
1232
1191
|
tf.reload
|
1233
|
-
end.
|
1234
|
-
tf.field2.to_i.
|
1192
|
+
end.not_to raise_error
|
1193
|
+
expect(tf.field2.to_i).to eq(11)
|
1235
1194
|
|
1236
1195
|
schema_define do
|
1237
1196
|
drop_table :test_fractions
|
@@ -1239,14 +1198,14 @@ end
|
|
1239
1198
|
end
|
1240
1199
|
|
1241
1200
|
it 'should raise error if column expression is not provided' do
|
1242
|
-
|
1201
|
+
expect {
|
1243
1202
|
schema_define do
|
1244
1203
|
create_table :test_fractions do |t|
|
1245
1204
|
t.integer :field1
|
1246
1205
|
t.virtual :field2
|
1247
1206
|
end
|
1248
1207
|
end
|
1249
|
-
}.
|
1208
|
+
}.to raise_error
|
1250
1209
|
end
|
1251
1210
|
end
|
1252
1211
|
|
@@ -1277,16 +1236,16 @@ end
|
|
1277
1236
|
|
1278
1237
|
it 'should include virtual columns and not try to update them' do
|
1279
1238
|
tf = TestFraction.columns.detect { |c| c.virtual? }
|
1280
|
-
tf.
|
1281
|
-
tf.name.
|
1282
|
-
tf.virtual
|
1283
|
-
|
1239
|
+
expect(tf).not_to be nil
|
1240
|
+
expect(tf.name).to eq("percent")
|
1241
|
+
expect(tf.virtual?).to be true
|
1242
|
+
expect do
|
1284
1243
|
tf = TestFraction.new(:numerator=>20, :denominator=>100)
|
1285
|
-
tf.percent.
|
1244
|
+
expect(tf.percent).to be nil # not whatever is in DATA_DEFAULT column
|
1286
1245
|
tf.save!
|
1287
1246
|
tf.reload
|
1288
|
-
end.
|
1289
|
-
tf.percent.to_i.
|
1247
|
+
end.not_to raise_error
|
1248
|
+
expect(tf.percent.to_i).to eq(20)
|
1290
1249
|
end
|
1291
1250
|
|
1292
1251
|
it 'should add virtual column' do
|
@@ -1295,15 +1254,15 @@ end
|
|
1295
1254
|
end
|
1296
1255
|
TestFraction.reset_column_information
|
1297
1256
|
tf = TestFraction.columns.detect { |c| c.name == 'rem' }
|
1298
|
-
tf.
|
1299
|
-
tf.virtual
|
1300
|
-
|
1257
|
+
expect(tf).not_to be nil
|
1258
|
+
expect(tf.virtual?).to be true
|
1259
|
+
expect do
|
1301
1260
|
tf = TestFraction.new(:numerator=>7, :denominator=>5)
|
1302
|
-
tf.rem.
|
1261
|
+
expect(tf.rem).to be nil
|
1303
1262
|
tf.save!
|
1304
1263
|
tf.reload
|
1305
|
-
end.
|
1306
|
-
tf.rem.to_i.
|
1264
|
+
end.not_to raise_error
|
1265
|
+
expect(tf.rem.to_i).to eq(2)
|
1307
1266
|
end
|
1308
1267
|
|
1309
1268
|
it 'should add virtual column with explicit type' do
|
@@ -1312,17 +1271,17 @@ end
|
|
1312
1271
|
end
|
1313
1272
|
TestFraction.reset_column_information
|
1314
1273
|
tf = TestFraction.columns.detect { |c| c.name == 'expression' }
|
1315
|
-
tf.
|
1316
|
-
tf.virtual
|
1317
|
-
tf.type.
|
1318
|
-
tf.limit.
|
1319
|
-
|
1274
|
+
expect(tf).not_to be nil
|
1275
|
+
expect(tf.virtual?).to be true
|
1276
|
+
expect(tf.type).to be :string
|
1277
|
+
expect(tf.limit).to be 100
|
1278
|
+
expect do
|
1320
1279
|
tf = TestFraction.new(:numerator=>7, :denominator=>5)
|
1321
|
-
tf.expression.
|
1280
|
+
expect(tf.expression).to be nil
|
1322
1281
|
tf.save!
|
1323
1282
|
tf.reload
|
1324
|
-
end.
|
1325
|
-
tf.expression.
|
1283
|
+
end.not_to raise_error
|
1284
|
+
expect(tf.expression).to eq('7/5')
|
1326
1285
|
end
|
1327
1286
|
|
1328
1287
|
it 'should change virtual column definition' do
|
@@ -1332,18 +1291,18 @@ end
|
|
1332
1291
|
end
|
1333
1292
|
TestFraction.reset_column_information
|
1334
1293
|
tf = TestFraction.columns.detect { |c| c.name == 'percent' }
|
1335
|
-
tf.
|
1336
|
-
tf.virtual
|
1337
|
-
tf.type.
|
1338
|
-
tf.precision.
|
1339
|
-
tf.scale.
|
1340
|
-
|
1294
|
+
expect(tf).not_to be nil
|
1295
|
+
expect(tf.virtual?).to be true
|
1296
|
+
expect(tf.type).to be :decimal
|
1297
|
+
expect(tf.precision).to be 15
|
1298
|
+
expect(tf.scale).to be 2
|
1299
|
+
expect do
|
1341
1300
|
tf = TestFraction.new(:numerator=>11, :denominator=>17)
|
1342
|
-
tf.percent.
|
1301
|
+
expect(tf.percent).to be nil
|
1343
1302
|
tf.save!
|
1344
1303
|
tf.reload
|
1345
|
-
end.
|
1346
|
-
tf.percent.
|
1304
|
+
end.not_to raise_error
|
1305
|
+
expect(tf.percent).to eq('64.71'.to_d)
|
1347
1306
|
end
|
1348
1307
|
|
1349
1308
|
it 'should change virtual column type' do
|
@@ -1352,18 +1311,18 @@ end
|
|
1352
1311
|
end
|
1353
1312
|
TestFraction.reset_column_information
|
1354
1313
|
tf = TestFraction.columns.detect { |c| c.name == 'percent' }
|
1355
|
-
tf.
|
1356
|
-
tf.virtual
|
1357
|
-
tf.type.
|
1358
|
-
tf.precision.
|
1359
|
-
tf.scale.
|
1360
|
-
|
1314
|
+
expect(tf).not_to be nil
|
1315
|
+
expect(tf.virtual?).to be true
|
1316
|
+
expect(tf.type).to be :decimal
|
1317
|
+
expect(tf.precision).to be 12
|
1318
|
+
expect(tf.scale).to be 5
|
1319
|
+
expect do
|
1361
1320
|
tf = TestFraction.new(:numerator=>11, :denominator=>17)
|
1362
|
-
tf.percent.
|
1321
|
+
expect(tf.percent).to be nil
|
1363
1322
|
tf.save!
|
1364
1323
|
tf.reload
|
1365
|
-
end.
|
1366
|
-
tf.percent.
|
1324
|
+
end.not_to raise_error
|
1325
|
+
expect(tf.percent).to eq('64.70588'.to_d)
|
1367
1326
|
end
|
1368
1327
|
end
|
1369
1328
|
|
@@ -1393,7 +1352,7 @@ end
|
|
1393
1352
|
t.string :title, :null => false
|
1394
1353
|
end
|
1395
1354
|
end
|
1396
|
-
@would_execute_sql.
|
1355
|
+
expect(@would_execute_sql).to match(/CREATE +TABLE .* \(.*\) NOLOGGING/)
|
1397
1356
|
end
|
1398
1357
|
|
1399
1358
|
it "should support the :tablespace option to create_table" do
|
@@ -1402,7 +1361,7 @@ end
|
|
1402
1361
|
t.string :title, :null => false
|
1403
1362
|
end
|
1404
1363
|
end
|
1405
|
-
@would_execute_sql.
|
1364
|
+
expect(@would_execute_sql).to match(/CREATE +TABLE .* \(.*\) TABLESPACE bogus/)
|
1406
1365
|
end
|
1407
1366
|
|
1408
1367
|
describe "creating a table with a tablespace defaults set" do
|
@@ -1415,7 +1374,7 @@ end
|
|
1415
1374
|
@conn.create_table :tablespace_tests do |t|
|
1416
1375
|
t.string :foo
|
1417
1376
|
end
|
1418
|
-
@would_execute_sql.
|
1377
|
+
expect(@would_execute_sql).to match(/CREATE +TABLE .* \(.*\) TABLESPACE #{DATABASE_NON_DEFAULT_TABLESPACE}/)
|
1419
1378
|
end
|
1420
1379
|
end
|
1421
1380
|
|
@@ -1428,7 +1387,7 @@ end
|
|
1428
1387
|
@conn.create_table :tablespace_tests, :id=>false, :organization=>'INDEX INITRANS 4 COMPRESS 1', :tablespace=>'bogus' do |t|
|
1429
1388
|
t.integer :id
|
1430
1389
|
end
|
1431
|
-
@would_execute_sql.
|
1390
|
+
expect(@would_execute_sql).to match(/CREATE +TABLE .*\(.*\)\s+ORGANIZATION INDEX INITRANS 4 COMPRESS 1 TABLESPACE bogus/)
|
1432
1391
|
end
|
1433
1392
|
end
|
1434
1393
|
|
@@ -1436,14 +1395,14 @@ end
|
|
1436
1395
|
schema_define do
|
1437
1396
|
add_index :keyboards, :name, :options=>'NOLOGGING'
|
1438
1397
|
end
|
1439
|
-
@would_execute_sql.
|
1398
|
+
expect(@would_execute_sql).to match(/CREATE +INDEX .* ON .* \(.*\) NOLOGGING/)
|
1440
1399
|
end
|
1441
1400
|
|
1442
1401
|
it "should support the :tablespace option to add_index" do
|
1443
1402
|
schema_define do
|
1444
1403
|
add_index :keyboards, :name, :tablespace=>'bogus'
|
1445
1404
|
end
|
1446
|
-
@would_execute_sql.
|
1405
|
+
expect(@would_execute_sql).to match(/CREATE +INDEX .* ON .* \(.*\) TABLESPACE bogus/)
|
1447
1406
|
end
|
1448
1407
|
|
1449
1408
|
it "should use default_tablespaces in add_index" do
|
@@ -1452,74 +1411,15 @@ end
|
|
1452
1411
|
add_index :keyboards, :name
|
1453
1412
|
end
|
1454
1413
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:index)
|
1455
|
-
@would_execute_sql.
|
1414
|
+
expect(@would_execute_sql).to match(/CREATE +INDEX .* ON .* \(.*\) TABLESPACE #{DATABASE_NON_DEFAULT_TABLESPACE}/)
|
1456
1415
|
end
|
1457
1416
|
|
1458
1417
|
it "should create unique function index but not create unique constraints" do
|
1459
1418
|
schema_define do
|
1460
1419
|
add_index :keyboards, 'lower(name)', unique: true, name: :index_keyboards_on_lower_name
|
1461
1420
|
end
|
1462
|
-
@would_execute_sql.
|
1421
|
+
expect(@would_execute_sql).not_to match(/ALTER +TABLE .* ADD CONSTRAINT .* UNIQUE \(.*\(.*\)\)/)
|
1463
1422
|
end
|
1464
1423
|
|
1465
|
-
describe "#initialize_schema_migrations_table" do
|
1466
|
-
# In Rails 2.3 to 3.2.x the index name for the migrations
|
1467
|
-
# table is hard-coded. We can modify the index name here
|
1468
|
-
# so we can support prefixes/suffixes that would
|
1469
|
-
# cause the index to be too long.
|
1470
|
-
#
|
1471
|
-
# Rails 4 can use this solution as well.
|
1472
|
-
after(:each) do
|
1473
|
-
ActiveRecord::Base.table_name_prefix = ''
|
1474
|
-
ActiveRecord::Base.table_name_suffix = ''
|
1475
|
-
end
|
1476
|
-
|
1477
|
-
def add_schema_migrations_index
|
1478
|
-
schema_define do
|
1479
|
-
initialize_schema_migrations_table
|
1480
|
-
end
|
1481
|
-
end
|
1482
|
-
|
1483
|
-
context "without prefix or suffix" do
|
1484
|
-
it "should not truncate the index name" do
|
1485
|
-
add_schema_migrations_index
|
1486
|
-
|
1487
|
-
@would_execute_sql.should include('CREATE UNIQUE INDEX "UNIQUE_SCHEMA_MIGRATIONS" ON "SCHEMA_MIGRATIONS" ("VERSION")')
|
1488
|
-
end
|
1489
|
-
end
|
1490
|
-
|
1491
|
-
context "with prefix" do
|
1492
|
-
before { ActiveRecord::Base.table_name_prefix = 'toolong_' }
|
1493
|
-
|
1494
|
-
it "should truncate the 'unique_schema_migrations' portion of the index name to fit the prefix within the limit" do
|
1495
|
-
add_schema_migrations_index
|
1496
|
-
|
1497
|
-
@would_execute_sql.should include('CREATE UNIQUE INDEX "TOOLONG_UNIQUE_SCHEMA_MIGRATIO" ON "TOOLONG_SCHEMA_MIGRATIONS" ("VERSION")')
|
1498
|
-
end
|
1499
|
-
end
|
1500
|
-
|
1501
|
-
context "with suffix" do
|
1502
|
-
before { ActiveRecord::Base.table_name_suffix = '_toolong' }
|
1503
|
-
|
1504
|
-
it "should truncate the 'unique_schema_migrations' portion of the index name to fit the suffix within the limit" do
|
1505
|
-
add_schema_migrations_index
|
1506
|
-
|
1507
|
-
@would_execute_sql.should include('CREATE UNIQUE INDEX "UNIQUE_SCHEMA_MIGRATIO_TOOLONG" ON "SCHEMA_MIGRATIONS_TOOLONG" ("VERSION")')
|
1508
|
-
end
|
1509
|
-
end
|
1510
|
-
|
1511
|
-
context "with prefix and suffix" do
|
1512
|
-
before do
|
1513
|
-
ActiveRecord::Base.table_name_prefix = 'begin_'
|
1514
|
-
ActiveRecord::Base.table_name_suffix = '_end'
|
1515
|
-
end
|
1516
|
-
|
1517
|
-
it "should truncate the 'unique_schema_migrations' portion of the index name to fit the suffix within the limit" do
|
1518
|
-
add_schema_migrations_index
|
1519
|
-
|
1520
|
-
@would_execute_sql.should include('CREATE UNIQUE INDEX "BEGIN_UNIQUE_SCHEMA_MIGRAT_END" ON "BEGIN_SCHEMA_MIGRATIONS_END" ("VERSION")')
|
1521
|
-
end
|
1522
|
-
end
|
1523
|
-
end
|
1524
1424
|
end
|
1525
1425
|
end
|