pmacs-activerecord-oracle_enhanced-adapter 1.4.2.rc1 → 1.5.5.1
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.
- checksums.yaml +7 -0
- data/Gemfile +11 -40
- data/History.md +170 -0
- data/README.md +61 -5
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +330 -161
- data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +48 -8
- data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +77 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +8 -24
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +4 -13
- data/lib/active_record/connection_adapters/oracle_enhanced_database_tasks.rb +61 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +13 -12
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +42 -19
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +28 -74
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +165 -231
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_creation.rb +89 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +16 -24
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +29 -38
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +93 -42
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +5 -3
- data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +7 -7
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -1
- data/lib/pmacs-activerecord-oracle_enhanced-adapter.rb +2 -2
- data/pmacs-activerecord-oracle_enhanced-adapter.gemspec +19 -17
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +35 -99
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +17 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +105 -98
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +74 -44
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +89 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +13 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +11 -12
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +252 -60
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +170 -40
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +14 -8
- data/spec/spec_helper.rb +25 -54
- metadata +41 -72
- data/lib/active_record/connection_adapters/oracle_enhanced.rake +0 -105
- data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
- data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -118
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +0 -25
- data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +0 -19
@@ -2,10 +2,31 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "OracleEnhancedAdapter schema definition" do
|
4
4
|
include SchemaSpecHelper
|
5
|
+
include LoggerSpecHelper
|
5
6
|
|
6
7
|
before(:all) do
|
7
8
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
8
|
-
@
|
9
|
+
@oracle11g_or_higher = !! !! ActiveRecord::Base.connection.select_value(
|
10
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'option to create sequence when adding a column' do
|
14
|
+
before do
|
15
|
+
@conn = ActiveRecord::Base.connection
|
16
|
+
schema_define do
|
17
|
+
create_table :keyboards, :force => true, :id => false do |t|
|
18
|
+
t.string :name
|
19
|
+
end
|
20
|
+
add_column :keyboards, :id, :primary_key
|
21
|
+
end
|
22
|
+
class ::Keyboard < ActiveRecord::Base; end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'creates a sequence when adding a column with create_sequence = true' do
|
26
|
+
_, sequence_name = ActiveRecord::Base.connection.pk_and_sequence_for_without_cache(:keyboards)
|
27
|
+
|
28
|
+
sequence_name.should == Keyboard.sequence_name
|
29
|
+
end
|
9
30
|
end
|
10
31
|
|
11
32
|
describe "table and sequence creation with non-default primary key" do
|
@@ -22,11 +43,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
22
43
|
end
|
23
44
|
end
|
24
45
|
class ::Keyboard < ActiveRecord::Base
|
25
|
-
|
26
|
-
self.primary_key = :key_number
|
27
|
-
else
|
28
|
-
set_primary_key :key_number
|
29
|
-
end
|
46
|
+
self.primary_key = :key_number
|
30
47
|
end
|
31
48
|
class ::IdKeyboard < ActiveRecord::Base
|
32
49
|
end
|
@@ -51,6 +68,15 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
51
68
|
end
|
52
69
|
end
|
53
70
|
|
71
|
+
describe "default sequence name" do
|
72
|
+
|
73
|
+
it "should return sequence name without truncating too much" do
|
74
|
+
seq_name_length = ActiveRecord::Base.connection.sequence_name_length
|
75
|
+
tname = "#{DATABASE_USER}" + "." +"a"*(seq_name_length - DATABASE_USER.length) + "z"*(DATABASE_USER).length
|
76
|
+
ActiveRecord::Base.connection.default_sequence_name(tname).should match (/z_seq$/)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
54
80
|
describe "sequence creation parameters" do
|
55
81
|
|
56
82
|
def create_test_employees_table(sequence_start_value = nil)
|
@@ -186,6 +212,15 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
186
212
|
e = TestEmployee.create!(:first_name => 'Raimonds')
|
187
213
|
@conn.select_value("SELECT test_employees_seq.currval FROM dual").should == e.id
|
188
214
|
end
|
215
|
+
|
216
|
+
it "should not generate NoMethodError for :returning_id:Symbol" do
|
217
|
+
set_logger
|
218
|
+
@conn.reconnect! unless @conn.active?
|
219
|
+
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Yasuo')", nil, "id")
|
220
|
+
@logger.output(:error).should_not match(/^Could not log "sql.active_record" event. NoMethodError: undefined method `name' for :returning_id:Symbol/)
|
221
|
+
clear_logger
|
222
|
+
end
|
223
|
+
|
189
224
|
end
|
190
225
|
|
191
226
|
describe "with separate creation of primary key trigger" do
|
@@ -226,11 +261,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
226
261
|
@sequence_name = "test_employees_s"
|
227
262
|
create_table_with_trigger(:primary_key => @primary_key, :sequence_name => @sequence_name)
|
228
263
|
class ::TestEmployee < ActiveRecord::Base
|
229
|
-
|
230
|
-
self.primary_key = "employee_id"
|
231
|
-
else
|
232
|
-
set_primary_key "employee_id"
|
233
|
-
end
|
264
|
+
self.primary_key = "employee_id"
|
234
265
|
end
|
235
266
|
end
|
236
267
|
|
@@ -262,11 +293,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
262
293
|
@sequence_name = "test_employees_s"
|
263
294
|
create_table_with_trigger(:sequence_name => @sequence_name, :trigger_name => "test_employees_t1")
|
264
295
|
class ::TestEmployee < ActiveRecord::Base
|
265
|
-
|
266
|
-
self.sequence_name = :autogenerated
|
267
|
-
else
|
268
|
-
set_sequence_name :autogenerated
|
269
|
-
end
|
296
|
+
self.sequence_name = :autogenerated
|
270
297
|
end
|
271
298
|
end
|
272
299
|
|
@@ -313,7 +340,7 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
313
340
|
drop_table :test_employees
|
314
341
|
end
|
315
342
|
Object.send(:remove_const, "TestEmployee")
|
316
|
-
ActiveRecord::Base.table_name_prefix =
|
343
|
+
ActiveRecord::Base.table_name_prefix = ''
|
317
344
|
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
318
345
|
end
|
319
346
|
|
@@ -364,17 +391,26 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
364
391
|
schema_define do
|
365
392
|
drop_table :test_employees rescue nil
|
366
393
|
drop_table :new_test_employees rescue nil
|
394
|
+
drop_table :test_employees_no_primary_key rescue nil
|
395
|
+
|
367
396
|
create_table :test_employees do |t|
|
368
397
|
t.string :first_name
|
369
398
|
t.string :last_name
|
370
399
|
end
|
371
|
-
|
400
|
+
|
401
|
+
create_table :test_employees_no_pkey, :id => false do |t|
|
402
|
+
t.string :first_name
|
403
|
+
t.string :last_name
|
404
|
+
end
|
405
|
+
end
|
372
406
|
end
|
373
407
|
|
374
408
|
after(:each) do
|
375
409
|
schema_define do
|
376
410
|
drop_table :test_employees rescue nil
|
377
411
|
drop_table :new_test_employees rescue nil
|
412
|
+
drop_table :test_employees_no_pkey rescue nil
|
413
|
+
drop_table :new_test_employees_no_pkey rescue nil
|
378
414
|
end
|
379
415
|
end
|
380
416
|
|
@@ -396,6 +432,12 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
396
432
|
end.should raise_error
|
397
433
|
end
|
398
434
|
|
435
|
+
it "should rename table when table has no primary key and sequence" do
|
436
|
+
lambda do
|
437
|
+
@conn.rename_table("test_employees_no_pkey","new_test_employees_no_pkey")
|
438
|
+
end.should_not raise_error
|
439
|
+
end
|
440
|
+
|
399
441
|
end
|
400
442
|
|
401
443
|
describe "create triggers" do
|
@@ -536,7 +578,12 @@ end
|
|
536
578
|
end
|
537
579
|
|
538
580
|
describe "foreign key constraints" do
|
581
|
+
let(:table_name_prefix) { '' }
|
582
|
+
let(:table_name_suffix) { '' }
|
583
|
+
|
539
584
|
before(:each) do
|
585
|
+
ActiveRecord::Base.table_name_prefix = table_name_prefix
|
586
|
+
ActiveRecord::Base.table_name_suffix = table_name_suffix
|
540
587
|
schema_define do
|
541
588
|
create_table :test_posts, :force => true do |t|
|
542
589
|
t.string :title
|
@@ -562,6 +609,8 @@ end
|
|
562
609
|
drop_table :test_comments rescue nil
|
563
610
|
drop_table :test_posts rescue nil
|
564
611
|
end
|
612
|
+
ActiveRecord::Base.table_name_prefix = ''
|
613
|
+
ActiveRecord::Base.table_name_suffix = ''
|
565
614
|
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
566
615
|
end
|
567
616
|
|
@@ -574,6 +623,34 @@ end
|
|
574
623
|
end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.TEST_COMMENTS_TEST_POST_ID_FK/}
|
575
624
|
end
|
576
625
|
|
626
|
+
context "with table_name_prefix" do
|
627
|
+
let(:table_name_prefix) { 'xxx_' }
|
628
|
+
|
629
|
+
it "should use table_name_prefix for foreign table" do
|
630
|
+
schema_define do
|
631
|
+
add_foreign_key :test_comments, :test_posts
|
632
|
+
end
|
633
|
+
|
634
|
+
lambda do
|
635
|
+
TestComment.create(:body => "test", :test_post_id => 1)
|
636
|
+
end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.XXX_TES_COM_TES_POS_ID_FK/}
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
context "with table_name_suffix" do
|
641
|
+
let(:table_name_suffix) { '_xxx' }
|
642
|
+
|
643
|
+
it "should use table_name_suffix for foreign table" do
|
644
|
+
schema_define do
|
645
|
+
add_foreign_key :test_comments, :test_posts
|
646
|
+
end
|
647
|
+
|
648
|
+
lambda do
|
649
|
+
TestComment.create(:body => "test", :test_post_id => 1)
|
650
|
+
end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.TES_COM_XXX_TES_POS_ID_FK/}
|
651
|
+
end
|
652
|
+
end
|
653
|
+
|
577
654
|
it "should add foreign key with name" do
|
578
655
|
schema_define do
|
579
656
|
add_foreign_key :test_comments, :test_posts, :name => "comments_posts_fk"
|
@@ -757,7 +834,6 @@ end
|
|
757
834
|
end
|
758
835
|
|
759
836
|
it "should add foreign key in change_table" do
|
760
|
-
return pending("Not in this ActiveRecord version") unless ENV['RAILS_GEM_VERSION'] >= '2.1'
|
761
837
|
schema_define do
|
762
838
|
create_table :test_comments, :force => true do |t|
|
763
839
|
t.string :body, :limit => 4000
|
@@ -773,7 +849,6 @@ end
|
|
773
849
|
end
|
774
850
|
|
775
851
|
it "should add foreign key in change_table references" do
|
776
|
-
return pending("Not in this ActiveRecord version") unless ENV['RAILS_GEM_VERSION'] >= '2.1'
|
777
852
|
schema_define do
|
778
853
|
create_table :test_comments, :force => true do |t|
|
779
854
|
t.string :body, :limit => 4000
|
@@ -788,7 +863,6 @@ end
|
|
788
863
|
end
|
789
864
|
|
790
865
|
it "should remove foreign key by table name" do
|
791
|
-
return pending("Not in this ActiveRecord version") unless ENV['RAILS_GEM_VERSION'] >= '2.1'
|
792
866
|
schema_define do
|
793
867
|
create_table :test_comments, :force => true do |t|
|
794
868
|
t.string :body, :limit => 4000
|
@@ -874,11 +948,7 @@ end
|
|
874
948
|
|
875
949
|
before(:each) do
|
876
950
|
class ::TestPost < ActiveRecord::Base
|
877
|
-
|
878
|
-
self.table_name = "synonym_to_posts"
|
879
|
-
else
|
880
|
-
set_table_name "synonym_to_posts"
|
881
|
-
end
|
951
|
+
self.table_name = "synonym_to_posts"
|
882
952
|
end
|
883
953
|
end
|
884
954
|
|
@@ -1016,11 +1086,19 @@ end
|
|
1016
1086
|
TestPost.columns_hash['title'].should be_nil
|
1017
1087
|
TestPost.columns_hash['content'].should be_nil
|
1018
1088
|
end
|
1089
|
+
|
1090
|
+
it "should ignore type and options parameter and remove column" do
|
1091
|
+
schema_define do
|
1092
|
+
remove_column :test_posts, :title, :string, {}
|
1093
|
+
end
|
1094
|
+
TestPost.reset_column_information
|
1095
|
+
TestPost.columns_hash['title'].should be_nil
|
1096
|
+
end
|
1019
1097
|
end
|
1020
1098
|
|
1021
1099
|
describe 'virtual columns in create_table' do
|
1022
1100
|
before(:each) do
|
1023
|
-
pending "Not supported in this database version" unless @
|
1101
|
+
pending "Not supported in this database version" unless @oracle11g_or_higher
|
1024
1102
|
end
|
1025
1103
|
|
1026
1104
|
it 'should create virtual column with old syntax' do
|
@@ -1031,11 +1109,7 @@ end
|
|
1031
1109
|
end
|
1032
1110
|
end
|
1033
1111
|
class ::TestFraction < ActiveRecord::Base
|
1034
|
-
|
1035
|
-
self.table_name = "test_fractions"
|
1036
|
-
else
|
1037
|
-
set_table_name "test_fractions"
|
1038
|
-
end
|
1112
|
+
self.table_name = "test_fractions"
|
1039
1113
|
end
|
1040
1114
|
|
1041
1115
|
TestFraction.reset_column_information
|
@@ -1070,7 +1144,7 @@ end
|
|
1070
1144
|
|
1071
1145
|
describe 'virtual columns' do
|
1072
1146
|
before(:each) do
|
1073
|
-
pending "Not supported in this database version" unless @
|
1147
|
+
pending "Not supported in this database version" unless @oracle11g_or_higher
|
1074
1148
|
expr = "( numerator/NULLIF(denominator,0) )*100"
|
1075
1149
|
schema_define do
|
1076
1150
|
create_table :test_fractions, :force => true do |t|
|
@@ -1080,17 +1154,13 @@ end
|
|
1080
1154
|
end
|
1081
1155
|
end
|
1082
1156
|
class ::TestFraction < ActiveRecord::Base
|
1083
|
-
|
1084
|
-
self.table_name = "test_fractions"
|
1085
|
-
else
|
1086
|
-
set_table_name "test_fractions"
|
1087
|
-
end
|
1157
|
+
self.table_name = "test_fractions"
|
1088
1158
|
end
|
1089
1159
|
TestFraction.reset_column_information
|
1090
1160
|
end
|
1091
1161
|
|
1092
1162
|
after(:each) do
|
1093
|
-
if @
|
1163
|
+
if @oracle11g_or_higher
|
1094
1164
|
schema_define do
|
1095
1165
|
drop_table :test_fractions
|
1096
1166
|
end
|
@@ -1235,7 +1305,7 @@ end
|
|
1235
1305
|
it "should use correct tablespace" do
|
1236
1306
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:table] = DATABASE_NON_DEFAULT_TABLESPACE
|
1237
1307
|
@conn.create_table :tablespace_tests do |t|
|
1238
|
-
t.
|
1308
|
+
t.string :foo
|
1239
1309
|
end
|
1240
1310
|
@would_execute_sql.should =~ /CREATE +TABLE .* \(.*\) TABLESPACE #{DATABASE_NON_DEFAULT_TABLESPACE}/
|
1241
1311
|
end
|
@@ -1276,5 +1346,65 @@ end
|
|
1276
1346
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:index)
|
1277
1347
|
@would_execute_sql.should =~ /CREATE +INDEX .* ON .* \(.*\) TABLESPACE #{DATABASE_NON_DEFAULT_TABLESPACE}/
|
1278
1348
|
end
|
1349
|
+
|
1350
|
+
describe "#initialize_schema_migrations_table" do
|
1351
|
+
# In Rails 2.3 to 3.2.x the index name for the migrations
|
1352
|
+
# table is hard-coded. We can modify the index name here
|
1353
|
+
# so we can support prefixes/suffixes that would
|
1354
|
+
# cause the index to be too long.
|
1355
|
+
#
|
1356
|
+
# Rails 4 can use this solution as well.
|
1357
|
+
after(:each) do
|
1358
|
+
ActiveRecord::Base.table_name_prefix = ''
|
1359
|
+
ActiveRecord::Base.table_name_suffix = ''
|
1360
|
+
end
|
1361
|
+
|
1362
|
+
def add_schema_migrations_index
|
1363
|
+
schema_define do
|
1364
|
+
initialize_schema_migrations_table
|
1365
|
+
end
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
context "without prefix or suffix" do
|
1369
|
+
it "should not truncate the index name" do
|
1370
|
+
add_schema_migrations_index
|
1371
|
+
|
1372
|
+
@would_execute_sql.should include('CREATE UNIQUE INDEX "UNIQUE_SCHEMA_MIGRATIONS" ON "SCHEMA_MIGRATIONS" ("VERSION")')
|
1373
|
+
end
|
1374
|
+
end
|
1375
|
+
|
1376
|
+
context "with prefix" do
|
1377
|
+
before { ActiveRecord::Base.table_name_prefix = 'toolong_' }
|
1378
|
+
|
1379
|
+
it "should truncate the 'unique_schema_migrations' portion of the index name to fit the prefix within the limit" do
|
1380
|
+
add_schema_migrations_index
|
1381
|
+
|
1382
|
+
@would_execute_sql.should include('CREATE UNIQUE INDEX "TOOLONG_UNIQUE_SCHEMA_MIGRATIO" ON "TOOLONG_SCHEMA_MIGRATIONS" ("VERSION")')
|
1383
|
+
end
|
1384
|
+
end
|
1385
|
+
|
1386
|
+
context "with suffix" do
|
1387
|
+
before { ActiveRecord::Base.table_name_suffix = '_toolong' }
|
1388
|
+
|
1389
|
+
it "should truncate the 'unique_schema_migrations' portion of the index name to fit the suffix within the limit" do
|
1390
|
+
add_schema_migrations_index
|
1391
|
+
|
1392
|
+
@would_execute_sql.should include('CREATE UNIQUE INDEX "UNIQUE_SCHEMA_MIGRATIO_TOOLONG" ON "SCHEMA_MIGRATIONS_TOOLONG" ("VERSION")')
|
1393
|
+
end
|
1394
|
+
end
|
1395
|
+
|
1396
|
+
context "with prefix and suffix" do
|
1397
|
+
before do
|
1398
|
+
ActiveRecord::Base.table_name_prefix = 'begin_'
|
1399
|
+
ActiveRecord::Base.table_name_suffix = '_end'
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
it "should truncate the 'unique_schema_migrations' portion of the index name to fit the suffix within the limit" do
|
1403
|
+
add_schema_migrations_index
|
1404
|
+
|
1405
|
+
@would_execute_sql.should include('CREATE UNIQUE INDEX "BEGIN_UNIQUE_SCHEMA_MIGRAT_END" ON "BEGIN_SCHEMA_MIGRATIONS_END" ("VERSION")')
|
1406
|
+
end
|
1407
|
+
end
|
1408
|
+
end
|
1279
1409
|
end
|
1280
1410
|
end
|
@@ -6,7 +6,8 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
6
6
|
before(:all) do
|
7
7
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
8
8
|
@conn = ActiveRecord::Base.connection
|
9
|
-
@
|
9
|
+
@oracle11g_or_higher = !! @conn.select_value(
|
10
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
|
10
11
|
end
|
11
12
|
describe "structure dump" do
|
12
13
|
before(:each) do
|
@@ -19,11 +20,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
19
20
|
end
|
20
21
|
class ::TestPost < ActiveRecord::Base
|
21
22
|
end
|
22
|
-
|
23
|
-
TestPost.table_name = "test_posts"
|
24
|
-
else
|
25
|
-
TestPost.set_table_name "test_posts"
|
26
|
-
end
|
23
|
+
TestPost.table_name = "test_posts"
|
27
24
|
end
|
28
25
|
|
29
26
|
after(:each) do
|
@@ -40,6 +37,8 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
40
37
|
@conn.execute "ALTER TABLE foos drop column baz_id" rescue nil
|
41
38
|
@conn.execute "ALTER TABLE test_posts drop column fooz_id" rescue nil
|
42
39
|
@conn.execute "ALTER TABLE test_posts drop column baz_id" rescue nil
|
40
|
+
@conn.execute "DROP VIEW test_posts_view_z" rescue nil
|
41
|
+
@conn.execute "DROP VIEW test_posts_view_a" rescue nil
|
43
42
|
end
|
44
43
|
|
45
44
|
it "should dump single primary key" do
|
@@ -141,9 +140,16 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
141
140
|
dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
|
142
141
|
dump.should =~ /CREATE OR REPLACE TYPE TEST_TYPE/
|
143
142
|
end
|
143
|
+
|
144
|
+
it "should dump views" do
|
145
|
+
@conn.execute "create or replace VIEW test_posts_view_z as select * from test_posts"
|
146
|
+
@conn.execute "create or replace VIEW test_posts_view_a as select * from test_posts_view_z"
|
147
|
+
dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
|
148
|
+
dump.should =~ /CREATE OR REPLACE FORCE VIEW TEST_POSTS_VIEW_A.*CREATE OR REPLACE FORCE VIEW TEST_POSTS_VIEW_Z/
|
149
|
+
end
|
144
150
|
|
145
151
|
it "should dump virtual columns" do
|
146
|
-
pending "Not supported in this database version" unless @
|
152
|
+
pending "Not supported in this database version" unless @oracle11g_or_higher
|
147
153
|
@conn.execute <<-SQL
|
148
154
|
CREATE TABLE bars (
|
149
155
|
id NUMBER(38,0) NOT NULL,
|
@@ -250,7 +256,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
250
256
|
describe "full drop" do
|
251
257
|
before(:each) do
|
252
258
|
@conn.create_table :full_drop_test do |t|
|
253
|
-
t.
|
259
|
+
t.string :foo
|
254
260
|
end
|
255
261
|
@conn.create_table :full_drop_test_temp, :temporary => true do |t|
|
256
262
|
t.string :foo
|
data/spec/spec_helper.rb
CHANGED
@@ -13,35 +13,21 @@ elsif RUBY_ENGINE == 'jruby'
|
|
13
13
|
puts "==> Running specs with JRuby version #{JRUBY_VERSION}"
|
14
14
|
end
|
15
15
|
|
16
|
-
ENV['RAILS_GEM_VERSION'] ||= '
|
17
|
-
NO_COMPOSITE_PRIMARY_KEYS = true
|
16
|
+
ENV['RAILS_GEM_VERSION'] ||= '4.0-master'
|
17
|
+
NO_COMPOSITE_PRIMARY_KEYS = true
|
18
18
|
|
19
19
|
puts "==> Running specs with Rails version #{ENV['RAILS_GEM_VERSION']}"
|
20
20
|
|
21
21
|
require 'active_record'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
require 'active_support/core_ext/class/attribute_accessors'
|
27
|
-
|
28
|
-
if ENV['RAILS_GEM_VERSION'] =~ /^3.0.0.beta/
|
29
|
-
require "rails/log_subscriber"
|
30
|
-
require 'active_record/railties/log_subscriber'
|
31
|
-
else
|
32
|
-
require "active_support/log_subscriber"
|
33
|
-
require 'active_record/log_subscriber'
|
34
|
-
end
|
23
|
+
require 'action_dispatch'
|
24
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
25
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
require 'active_record/session_store'
|
41
|
-
elsif ENV['RAILS_GEM_VERSION'] <= '2.3'
|
42
|
-
require 'action_pack'
|
43
|
-
require 'action_controller/session/active_record_store'
|
44
|
-
end
|
27
|
+
require "active_support/log_subscriber"
|
28
|
+
require 'active_record/log_subscriber'
|
29
|
+
|
30
|
+
require 'logger'
|
45
31
|
|
46
32
|
require 'active_record/connection_adapters/oracle_enhanced_adapter'
|
47
33
|
require 'ruby-plsql'
|
@@ -51,30 +37,16 @@ module LoggerSpecHelper
|
|
51
37
|
@logger = MockLogger.new
|
52
38
|
@old_logger = ActiveRecord::Base.logger
|
53
39
|
|
54
|
-
|
55
|
-
@notifier = ActiveSupport::Notifications::Fanout.new
|
56
|
-
|
57
|
-
ActiveSupport::LogSubscriber.colorize_logging = false
|
40
|
+
@notifier = ActiveSupport::Notifications::Fanout.new
|
58
41
|
|
59
|
-
|
60
|
-
@old_notifier = ActiveSupport::Notifications.notifier
|
61
|
-
ActiveSupport::Notifications.notifier = @notifier
|
42
|
+
ActiveSupport::LogSubscriber.colorize_logging = false
|
62
43
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
else # ActiveRecord 2.x
|
68
|
-
if ActiveRecord::Base.respond_to?(:connection_pool)
|
69
|
-
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
|
70
|
-
else
|
71
|
-
ActiveRecord::Base.clear_active_connections!
|
72
|
-
end
|
73
|
-
ActiveRecord::Base.logger = @logger
|
74
|
-
ActiveRecord::Base.colorize_logging = false
|
75
|
-
# ActiveRecord::Base.logger.level = Logger::DEBUG
|
76
|
-
end
|
44
|
+
ActiveRecord::Base.logger = @logger
|
45
|
+
@old_notifier = ActiveSupport::Notifications.notifier
|
46
|
+
ActiveSupport::Notifications.notifier = @notifier
|
77
47
|
|
48
|
+
ActiveRecord::LogSubscriber.attach_to(:active_record)
|
49
|
+
ActiveSupport::Notifications.subscribe("sql.active_record", ActiveRecord::ExplainSubscriber.new)
|
78
50
|
end
|
79
51
|
|
80
52
|
class MockLogger
|
@@ -115,11 +87,8 @@ module LoggerSpecHelper
|
|
115
87
|
ActiveRecord::Base.logger = @old_logger
|
116
88
|
@logger = nil
|
117
89
|
|
118
|
-
|
119
|
-
|
120
|
-
@notifier = nil
|
121
|
-
end
|
122
|
-
|
90
|
+
ActiveSupport::Notifications.notifier = @old_notifier
|
91
|
+
@notifier = nil
|
123
92
|
end
|
124
93
|
|
125
94
|
# Wait notifications to be published (for Rails 3.0)
|
@@ -177,11 +146,13 @@ SYSTEM_CONNECTION_PARAMS = {
|
|
177
146
|
|
178
147
|
DATABASE_NON_DEFAULT_TABLESPACE = ENV['DATABASE_NON_DEFAULT_TABLESPACE'] || "SYSTEM"
|
179
148
|
|
180
|
-
# Set default $KCODE to UTF8
|
181
|
-
if RUBY_VERSION < "1.9"
|
182
|
-
$KCODE = "UTF8"
|
183
|
-
end
|
184
|
-
|
185
149
|
# set default time zone in TZ environment variable
|
186
150
|
# which will be used to set session time zone
|
187
151
|
ENV['TZ'] ||= 'Europe/Riga'
|
152
|
+
|
153
|
+
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
154
|
+
|
155
|
+
# Set default_timezone :local explicitly
|
156
|
+
# because this default value has been changed to :utc atrails master branch
|
157
|
+
ActiveRecord::Base.default_timezone = :local
|
158
|
+
|