activerecord-oracle_enhanced-adapter 1.7.7 → 1.7.11

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +45 -0
  3. data/README.md +3 -0
  4. data/VERSION +1 -1
  5. data/activerecord-oracle_enhanced-adapter.gemspec +2 -3
  6. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +2 -6
  7. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +0 -2
  8. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +2 -5
  9. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +0 -2
  10. data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +1 -3
  11. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +0 -1
  12. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +2 -6
  13. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +3 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +0 -10
  15. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +1 -1
  16. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +2 -2
  17. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +1 -2
  18. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +1 -5
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +0 -2
  20. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +22 -4
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +0 -1
  22. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +4 -7
  23. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +3 -7
  24. data/lib/active_record/oracle_enhanced/type/boolean.rb +0 -1
  25. data/lib/active_record/oracle_enhanced/type/integer.rb +1 -1
  26. data/lib/active_record/oracle_enhanced/type/national_character_string.rb +0 -1
  27. data/lib/active_record/oracle_enhanced/type/raw.rb +0 -1
  28. data/lib/active_record/oracle_enhanced/type/string.rb +0 -1
  29. data/lib/active_record/oracle_enhanced/type/text.rb +0 -2
  30. data/lib/activerecord-oracle_enhanced-adapter.rb +0 -1
  31. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +28 -1
  32. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +3 -1
  33. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +4 -4
  34. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +20 -8
  35. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +0 -1
  36. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +2 -2
  37. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +3 -3
  38. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +5 -5
  39. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +4 -3
  40. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +40 -0
  41. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +86 -29
  42. data/spec/spec_helper.rb +0 -1
  43. metadata +3 -3
@@ -15,7 +15,6 @@ if defined?(Rails)
15
15
  end
16
16
 
17
17
  end
18
-
19
18
  end
20
19
  end
21
20
  end
@@ -283,7 +283,6 @@ describe "OracleEnhancedAdapter" do
283
283
 
284
284
  end
285
285
 
286
-
287
286
  describe "reserved words column quoting" do
288
287
 
289
288
  before(:all) do
@@ -682,6 +681,7 @@ describe "OracleEnhancedAdapter" do
682
681
  end
683
682
 
684
683
  it "should explain query with binds" do
684
+ pending "Pending until further investigation made for #908" if RUBY_ENGINE == 'jruby'
685
685
  pk = TestPost.columns_hash[TestPost.primary_key]
686
686
  sub = Arel::Nodes::BindParam.new.to_sql
687
687
  binds = [ActiveRecord::Relation::QueryAttribute.new(pk, 1, ActiveRecord::Type::Integer.new)]
@@ -816,4 +816,31 @@ describe "OracleEnhancedAdapter" do
816
816
  expect(serialized_column.save!).to eq(true)
817
817
  end
818
818
  end
819
+
820
+ describe "quoting" do
821
+ before(:all) do
822
+ schema_define do
823
+ create_table :test_logs, force: true do |t|
824
+ t.timestamp :send_time
825
+ end
826
+ end
827
+ class TestLog < ActiveRecord::Base
828
+ validates_uniqueness_of :send_time
829
+ end
830
+ end
831
+
832
+ after(:all) do
833
+ schema_define do
834
+ drop_table :test_logs
835
+ end
836
+ Object.send(:remove_const, "TestLog")
837
+ ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
838
+ end
839
+
840
+ it "should create records including Time" do
841
+ TestLog.create! send_time: Time.now + 1.seconds
842
+ TestLog.create! send_time: Time.now + 2.seconds
843
+ expect(TestLog.count).to eq 2
844
+ end
845
+ end
819
846
  end
@@ -111,9 +111,11 @@ describe "OracleEnhancedConnection" do
111
111
  end
112
112
 
113
113
  describe "default_timezone" do
114
+ include SchemaSpecHelper
115
+
114
116
  before(:all) do
115
117
  ActiveRecord::Base.establish_connection(CONNECTION_WITH_TIMEZONE_PARAMS)
116
- ActiveRecord::Schema.define do
118
+ schema_define do
117
119
  create_table :posts, :force => true do |t|
118
120
  t.timestamps null: false
119
121
  end
@@ -64,7 +64,7 @@ describe "OracleEnhancedAdapter composite_primary_keys support" do
64
64
  before(:all) do
65
65
  schema_define do
66
66
  create_table :cpk_write_lobs_test, :primary_key => [:type_category, :date_value], :force => true do |t|
67
- t.string :type_category, :limit => 15, :null => false
67
+ t.string :type_category, :limit => 15, :null => false
68
68
  t.date :date_value, :null => false
69
69
  t.text :results, :null => false
70
70
  t.timestamps null: true
@@ -83,7 +83,7 @@ describe "OracleEnhancedAdapter composite_primary_keys support" do
83
83
  set_table_name 'non_cpk_write_lobs_test'
84
84
  end
85
85
  end
86
-
86
+
87
87
  after(:all) do
88
88
  schema_define do
89
89
  drop_table :cpk_write_lobs_test
@@ -98,14 +98,14 @@ describe "OracleEnhancedAdapter composite_primary_keys support" do
98
98
  CpkWriteLobsTest.create(:type_category => 'AAA', :date_value => Date.today, :results => 'DATA '*10)
99
99
  }.not_to raise_error
100
100
  end
101
-
101
+
102
102
  it "should create new record in table without CPK and with LOB" do
103
103
  expect {
104
104
  NonCpkWriteLobsTest.create(:date_value => Date.today, :results => 'DATA '*10)
105
105
  }.not_to raise_error
106
106
  end
107
107
  end
108
-
108
+
109
109
  # Other testing was done based on composite_primary_keys tests
110
110
 
111
111
  end
@@ -171,7 +171,7 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
171
171
  INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
172
172
  SQL
173
173
  end
174
-
174
+
175
175
  after(:all) do
176
176
  @conn.execute "DROP TABLE test2_employees"
177
177
  @conn.execute "DROP SEQUENCE test2_employees_seq"
@@ -182,7 +182,7 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
182
182
  class ::Test2Employee < ActiveRecord::Base
183
183
  end
184
184
  end
185
-
185
+
186
186
  after(:each) do
187
187
  Object.send(:remove_const, "Test2Employee")
188
188
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
@@ -440,10 +440,12 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
440
440
  end
441
441
 
442
442
  describe "OracleEnhancedAdapter boolean support when emulate_booleans_from_strings = true" do
443
+ include SchemaSpecHelper
444
+
443
445
  before(:all) do
444
446
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
445
447
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
446
- ActiveRecord::Schema.define do
448
+ schema_define do
447
449
  create_table :posts, :force => true do |t|
448
450
  t.string :name, null: false
449
451
  t.boolean :is_default, default: false
@@ -559,7 +561,6 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
559
561
 
560
562
  end
561
563
 
562
-
563
564
  describe "OracleEnhancedAdapter date and timestamp with different NLS date formats" do
564
565
  before(:all) do
565
566
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
@@ -818,7 +819,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
818
819
  @employee.reload
819
820
  expect(@employee.last_login_at).to eq(@today.to_time)
820
821
  end
821
-
822
+
822
823
  end
823
824
 
824
825
  describe "OracleEnhancedAdapter handling of CLOB columns" do
@@ -941,7 +942,6 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
941
942
  expect(@employee.comments).to be_nil
942
943
  end
943
944
 
944
-
945
945
  it "should create record with CLOB data" do
946
946
  @employee = TestEmployee.create!(
947
947
  :first_name => "First",
@@ -1321,7 +1321,6 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
1321
1321
  end
1322
1322
  end
1323
1323
 
1324
-
1325
1324
  describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
1326
1325
  before(:all) do
1327
1326
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
@@ -1402,9 +1401,14 @@ describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
1402
1401
  CREATE SEQUENCE test2_employees_seq MINVALUE 1
1403
1402
  INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
1404
1403
  SQL
1404
+
1405
+ class ::Test2Employee < ActiveRecord::Base
1406
+ end
1405
1407
  end
1406
-
1408
+
1407
1409
  after(:all) do
1410
+ Object.send(:remove_const, "Test2Employee")
1411
+
1408
1412
  @conn.execute "DROP TABLE test2_employees"
1409
1413
  @conn.execute "DROP SEQUENCE test2_employees_seq"
1410
1414
  end
@@ -1414,4 +1418,12 @@ describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
1414
1418
  column = columns.detect{|c| c.name == "hourly_rate"}
1415
1419
  expect(column.type).to eq(:float)
1416
1420
  end
1421
+
1422
+ it "should BINARY_FLOAT column type returns an approximate value" do
1423
+ employee = Test2Employee.create(hourly_rate: 4.4)
1424
+
1425
+ employee.reload
1426
+
1427
+ expect(employee.hourly_rate).to eq(4.400000095367432)
1428
+ end
1417
1429
  end
@@ -90,4 +90,3 @@ describe "Oracle Enhanced adapter database tasks" do
90
90
  after { ActiveRecord::Base.connection.execute "DROP TABLE test_posts" rescue nil }
91
91
  end
92
92
  end
93
-
@@ -51,7 +51,7 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
51
51
  @conn.enable_dbms_output
52
52
 
53
53
  expect(@conn.select_all("select more_than_five_characters_long('hi there') is_it_long from dual").to_a).to eq([{'is_it_long'=>1}])
54
-
54
+
55
55
  expect(@logger.output(:debug)).to match(/^DBMS_OUTPUT: before the if -hi there-$/)
56
56
  expect(@logger.output(:debug)).to match(/^DBMS_OUTPUT: it is longer than 5$/)
57
57
  expect(@logger.output(:debug)).to match(/^DBMS_OUTPUT: about to return: 1$/)
@@ -61,7 +61,7 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
61
61
  @conn.enable_dbms_output
62
62
 
63
63
  expect(@conn.select_all("select more_than_five_characters_long('short') is_it_long from dual").to_a).to eq([{'is_it_long'=>0}])
64
-
64
+
65
65
  expect(@logger.output(:debug)).to match(/^DBMS_OUTPUT: before the if -short-$/)
66
66
  expect(@logger.output(:debug)).to match(/^DBMS_OUTPUT: it is 5 or shorter$/)
67
67
  expect(@logger.output(:debug)).to match(/^DBMS_OUTPUT: about to return: 0$/)
@@ -27,13 +27,13 @@ if ActiveRecord::Base.method_defined?(:changed?)
27
27
  class TestEmployee < ActiveRecord::Base
28
28
  end
29
29
  end
30
-
30
+
31
31
  after(:all) do
32
32
  Object.send(:remove_const, "TestEmployee")
33
33
  @conn.execute "DROP TABLE test_employees"
34
34
  @conn.execute "DROP SEQUENCE test_employees_seq"
35
35
  ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
36
- end
36
+ end
37
37
 
38
38
  it "should not mark empty string (stored as NULL) as changed when reassigning it" do
39
39
  @employee = TestEmployee.create!(:first_name => '')
@@ -111,7 +111,7 @@ if ActiveRecord::Base.method_defined?(:changed?)
111
111
  @employee = TestEmployee.new
112
112
  @employee.job_id = 0
113
113
  expect(@employee.save!).to be_truthy
114
-
114
+
115
115
  expect(@employee).not_to be_changed
116
116
 
117
117
  @employee.job_id = '0'
@@ -4,7 +4,7 @@ require 'ruby-plsql'
4
4
 
5
5
  describe "OracleEnhancedAdapter custom methods for create, update and destroy" do
6
6
  include LoggerSpecHelper
7
-
7
+
8
8
  before(:all) do
9
9
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
10
10
  @conn = ActiveRecord::Base.connection
@@ -67,7 +67,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
67
67
  VALUES (p_employee_id, p_first_name, p_last_name, p_hire_date, p_salary, p_description,
68
68
  1, SYSDATE, SYSDATE);
69
69
  END create_employee;
70
-
70
+
71
71
  PROCEDURE update_employee(
72
72
  p_employee_id NUMBER,
73
73
  p_first_name VARCHAR2,
@@ -85,7 +85,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
85
85
  version = v_version + 1, update_time = SYSDATE
86
86
  WHERE employee_id = p_employee_id;
87
87
  END update_employee;
88
-
88
+
89
89
  PROCEDURE delete_employee(
90
90
  p_employee_id NUMBER)
91
91
  IS
@@ -111,7 +111,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
111
111
  self.primary_key = :employee_id
112
112
 
113
113
  validates_presence_of :first_name, :last_name, :hire_date
114
-
114
+
115
115
  # should return ID of new record
116
116
  set_create_method do
117
117
  plsql.test_employees_pkg.create_employee(
@@ -372,5 +372,5 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
372
372
  expect(@employee.save).to be_falsey
373
373
  expect(@employee.errors[:first_name]).not_to be_blank
374
374
  end
375
-
375
+
376
376
  end
@@ -77,6 +77,7 @@ describe "OracleEnhancedAdapter schema dump" do
77
77
  after(:each) do
78
78
  drop_test_posts_table
79
79
  @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
80
+ @conn.drop_table(ActiveRecord::InternalMetadata.table_name) if @conn.table_exists?(ActiveRecord::InternalMetadata.table_name)
80
81
  ActiveRecord::Base.table_name_prefix = ''
81
82
  ActiveRecord::Base.table_name_suffix = ''
82
83
  end
@@ -234,7 +235,7 @@ describe "OracleEnhancedAdapter schema dump" do
234
235
  dump = standard_dump
235
236
  expect(dump.rindex("create_table")).to be < dump.index("add_foreign_key")
236
237
  end
237
-
238
+
238
239
  it "should include primary_key when reference column name is not 'id'" do
239
240
  schema_define do
240
241
  create_table :test_posts, force: true, :primary_key => 'baz_id' do |t|
@@ -253,7 +254,7 @@ describe "OracleEnhancedAdapter schema dump" do
253
254
 
254
255
  expect(standard_dump).to match(/add_foreign_key "test_comments", "test_posts", column: "baz_id", primary_key: "baz_id", name: "test_comments_baz_id_fk"/)
255
256
  end
256
-
257
+
257
258
  end
258
259
 
259
260
  describe "synonyms" do
@@ -415,7 +416,7 @@ describe "OracleEnhancedAdapter schema dump" do
415
416
  context "with index on virtual column" do
416
417
  before(:all) do
417
418
  if @oracle11g_or_higher
418
- schema_define do
419
+ schema_define do
419
420
  add_index 'test_names', 'field_with_leading_space', :name => "index_on_virtual_col"
420
421
  end
421
422
  end
@@ -1429,4 +1429,44 @@ end
1429
1429
  end
1430
1430
 
1431
1431
  end
1432
+
1433
+ describe "load schema" do
1434
+ let(:versions) {
1435
+ %w(20160101000000 20160102000000 20160103000000)
1436
+ }
1437
+
1438
+ before do
1439
+ @conn = ActiveRecord::Base.connection
1440
+
1441
+ ActiveRecord::SchemaMigration.create_table
1442
+ end
1443
+
1444
+ context "multi insert is supported" do
1445
+ it "should loads the migration schema table from insert versions sql" do
1446
+ skip "Not supported in this database version" unless ActiveRecord::Base.connection.supports_multi_insert?
1447
+
1448
+ expect {
1449
+ @conn.execute @conn.insert_versions_sql(versions)
1450
+ }.not_to raise_error
1451
+
1452
+ expect(@conn.select_value("SELECT COUNT(version) FROM schema_migrations")).to eq versions.count
1453
+ end
1454
+ end
1455
+
1456
+ context "multi insert is NOT supported" do
1457
+ it "should loads the migration schema table from insert versions sql" do
1458
+ skip "Not supported in this database version" if ActiveRecord::Base.connection.supports_multi_insert?
1459
+
1460
+ expect {
1461
+ versions.each { |version| @conn.execute @conn.insert_versions_sql(version) }
1462
+ }.not_to raise_error
1463
+
1464
+ expect(@conn.select_value("SELECT COUNT(version) FROM schema_migrations")).to eq versions.count
1465
+ end
1466
+ end
1467
+
1468
+ after do
1469
+ ActiveRecord::SchemaMigration.drop_table
1470
+ end
1471
+ end
1432
1472
  end
@@ -22,9 +22,9 @@ describe "OracleEnhancedAdapter structure dump" do
22
22
  end
23
23
  TestPost.table_name = "test_posts"
24
24
  end
25
-
25
+
26
26
  after(:each) do
27
- @conn.drop_table :test_posts
27
+ @conn.drop_table :test_posts
28
28
  @conn.drop_table :foos
29
29
  @conn.execute "DROP SEQUENCE test_posts_seq" rescue nil
30
30
  @conn.execute "ALTER TABLE test_posts drop CONSTRAINT fk_test_post_foo" rescue nil
@@ -40,12 +40,12 @@ describe "OracleEnhancedAdapter structure dump" do
40
40
  @conn.execute "DROP VIEW test_posts_view_z" rescue nil
41
41
  @conn.execute "DROP VIEW test_posts_view_a" rescue nil
42
42
  end
43
-
43
+
44
44
  it "should dump single primary key" do
45
45
  dump = ActiveRecord::Base.connection.structure_dump
46
46
  expect(dump).to match(/CONSTRAINT (.+) PRIMARY KEY \(ID\)\n/)
47
47
  end
48
-
48
+
49
49
  it "should dump composite primary keys" do
50
50
  pk = @conn.send(:select_one, <<-SQL)
51
51
  select constraint_name from user_constraints where table_name = 'TEST_POSTS' and constraint_type='P'
@@ -60,43 +60,43 @@ describe "OracleEnhancedAdapter structure dump" do
60
60
  dump = ActiveRecord::Base.connection.structure_dump
61
61
  expect(dump).to match(/CONSTRAINT (.+) PRIMARY KEY \(ID,TITLE\)\n/)
62
62
  end
63
-
63
+
64
64
  it "should dump foreign keys" do
65
65
  @conn.execute <<-SQL
66
- ALTER TABLE TEST_POSTS
66
+ ALTER TABLE TEST_POSTS
67
67
  ADD CONSTRAINT fk_test_post_foo FOREIGN KEY (foo_id) REFERENCES foos(id)
68
68
  SQL
69
69
  dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
70
70
  expect(dump.split('\n').length).to eq(1)
71
71
  expect(dump).to match(/ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_FOO\"? FOREIGN KEY \(\"?FOO_ID\"?\) REFERENCES \"?FOOS\"?\(\"?ID\"?\)/i)
72
72
  end
73
-
73
+
74
74
  it "should dump foreign keys when reference column name is not 'id'" do
75
75
  @conn.add_column :foos, :baz_id, :integer
76
-
76
+
77
77
  @conn.execute <<-SQL
78
- ALTER TABLE FOOS
78
+ ALTER TABLE FOOS
79
79
  ADD CONSTRAINT UK_BAZ UNIQUE (BAZ_ID)
80
80
  SQL
81
-
81
+
82
82
  @conn.add_column :test_posts, :baz_id, :integer
83
-
83
+
84
84
  @conn.execute <<-SQL
85
- ALTER TABLE TEST_POSTS
85
+ ALTER TABLE TEST_POSTS
86
86
  ADD CONSTRAINT fk_test_post_baz FOREIGN KEY (baz_id) REFERENCES foos(baz_id)
87
87
  SQL
88
-
88
+
89
89
  dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
90
90
  expect(dump.split('\n').length).to eq(1)
91
91
  expect(dump).to match(/ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_BAZ\"? FOREIGN KEY \(\"?BAZ_ID\"?\) REFERENCES \"?FOOS\"?\(\"?BAZ_ID\"?\)/i)
92
92
  end
93
-
93
+
94
94
  it "should not error when no foreign keys are present" do
95
95
  dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
96
96
  expect(dump.split('\n').length).to eq(0)
97
97
  expect(dump).to eq('')
98
98
  end
99
-
99
+
100
100
  it "should dump triggers" do
101
101
  @conn.execute <<-SQL
102
102
  create or replace TRIGGER TEST_POST_TRIGGER
@@ -110,7 +110,7 @@ describe "OracleEnhancedAdapter structure dump" do
110
110
  dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
111
111
  expect(dump).to match(/CREATE OR REPLACE TRIGGER TEST_POST_TRIGGER/)
112
112
  end
113
-
113
+
114
114
  it "should dump types" do
115
115
  @conn.execute <<-SQL
116
116
  create or replace TYPE TEST_TYPE AS TABLE OF VARCHAR2(10);
@@ -125,7 +125,7 @@ describe "OracleEnhancedAdapter structure dump" do
125
125
  dump = ActiveRecord::Base.connection.structure_dump_db_stored_code.gsub(/\n|\s+/,' ')
126
126
  expect(dump).to match(/CREATE OR REPLACE FORCE VIEW TEST_POSTS_VIEW_A.*CREATE OR REPLACE FORCE VIEW TEST_POSTS_VIEW_Z/)
127
127
  end
128
-
128
+
129
129
  it "should dump virtual columns" do
130
130
  skip "Not supported in this database version" unless @oracle11g_or_higher
131
131
  @conn.execute <<-SQL
@@ -159,20 +159,20 @@ describe "OracleEnhancedAdapter structure dump" do
159
159
  SQL
160
160
  dump = ActiveRecord::Base.connection.structure_dump_unique_keys("test_posts")
161
161
  expect(dump).to eq(["ALTER TABLE TEST_POSTS ADD CONSTRAINT UK_FOO_FOO_ID UNIQUE (FOO,FOO_ID)"])
162
-
162
+
163
163
  dump = ActiveRecord::Base.connection.structure_dump
164
164
  expect(dump).to match(/CONSTRAINT UK_FOO_FOO_ID UNIQUE \(FOO,FOO_ID\)/)
165
165
  end
166
-
166
+
167
167
  it "should dump indexes" do
168
168
  ActiveRecord::Base.connection.add_index(:test_posts, :foo, :name => :ix_test_posts_foo)
169
169
  ActiveRecord::Base.connection.add_index(:test_posts, :foo_id, :name => :ix_test_posts_foo_id, :unique => true)
170
-
170
+
171
171
  @conn.execute <<-SQL
172
172
  ALTER TABLE test_posts
173
173
  add CONSTRAINT uk_foo_foo_id UNIQUE (foo, foo_id)
174
174
  SQL
175
-
175
+
176
176
  dump = ActiveRecord::Base.connection.structure_dump
177
177
  expect(dump).to match(/CREATE UNIQUE INDEX "?IX_TEST_POSTS_FOO_ID"? ON "?TEST_POSTS"? \("?FOO_ID"?\)/i)
178
178
  expect(dump).to match(/CREATE INDEX "?IX_TEST_POSTS_FOO\"? ON "?TEST_POSTS"? \("?FOO"?\)/i)
@@ -260,11 +260,11 @@ describe "OracleEnhancedAdapter structure dump" do
260
260
 
261
261
  it "should return the character size of nvarchar fields" do
262
262
  if /.*unq_nvarchar nvarchar2\((\d+)\).*/ =~ @conn.structure_dump
263
- expect("#$1").to eq("255")
263
+ expect("#$1").to eq("255")
264
264
  end
265
265
  end
266
266
  end
267
-
267
+
268
268
  describe "temp_table_drop" do
269
269
  before(:each) do
270
270
  @conn.create_table :temp_tbl, :temporary => true do |t|
@@ -280,13 +280,70 @@ describe "OracleEnhancedAdapter structure dump" do
280
280
  expect(dump).not_to match(/DROP TABLE "?NOT_TEMP_TBL"?/i)
281
281
  end
282
282
  after(:each) do
283
- @conn.drop_table :temp_tbl
283
+ @conn.drop_table :temp_tbl
284
284
  @conn.drop_table :not_temp_tbl
285
285
  end
286
286
  end
287
-
287
+
288
+ describe "schema migrations" do
289
+ let(:versions) do
290
+ (1..10).map do |i|
291
+ Time.parse("2016.01.#{i}").strftime("%Y%m%d%H%M%S")
292
+ end
293
+ end
294
+
295
+ let(:dump) { ActiveRecord::Base.connection.dump_schema_information }
296
+
297
+ before do
298
+ ActiveRecord::SchemaMigration.reset_table_name
299
+ ActiveRecord::SchemaMigration.create_table
300
+ versions.each do |i|
301
+ ActiveRecord::SchemaMigration.create!(:version => i)
302
+ end
303
+ end
304
+
305
+ context "multi insert is supported" do
306
+ it "should dump schema migrations using multi inserts" do
307
+ skip "Not supported in this database version" unless ActiveRecord::Base.connection.supports_multi_insert?
308
+
309
+ expect(dump).to eq <<-SQL.strip_heredoc
310
+ INSERT ALL
311
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160101000000')
312
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160102000000')
313
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160103000000')
314
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160104000000')
315
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160105000000')
316
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160106000000')
317
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160107000000')
318
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160108000000')
319
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160109000000')
320
+ INTO "SCHEMA_MIGRATIONS" (version) VALUES ('20160110000000')
321
+ SELECT * FROM DUAL
322
+ SQL
323
+ end
324
+ end
325
+
326
+ context "multi insert is NOT supported" do
327
+ let(:insert_statement_per_migration) {
328
+ 1.step(10).map { |i|
329
+ %Q|INSERT INTO "SCHEMA_MIGRATIONS" (version) VALUES ('201601#{sprintf("%02d", i)}000000')|
330
+ }.join("\n\n/\n\n")
331
+ }
332
+
333
+ it "should dump schema migrations one version per insert" do
334
+ skip "Not supported in this database version" if ActiveRecord::Base.connection.supports_multi_insert?
335
+
336
+ expect(dump).to eq insert_statement_per_migration
337
+ end
338
+ end
339
+
340
+ after do
341
+ ActiveRecord::SchemaMigration.drop_table
342
+ end
343
+ end
344
+
288
345
  describe "full drop" do
289
- before(:each) do
346
+ before(:each) do
290
347
  @conn.create_table :full_drop_test do |t|
291
348
  t.string :foo
292
349
  end
@@ -308,7 +365,7 @@ describe "OracleEnhancedAdapter structure dump" do
308
365
  end test_package;
309
366
  SQL
310
367
  @conn.execute <<-SQL
311
- create or replace package body full_drop_test_package as
368
+ create or replace package body full_drop_test_package as
312
369
  function test_func return varchar2 is
313
370
  begin
314
371
  return ('foo');
@@ -318,10 +375,10 @@ describe "OracleEnhancedAdapter structure dump" do
318
375
  #function
319
376
  @conn.execute <<-SQL
320
377
  create or replace function full_drop_test_function
321
- return varchar2
378
+ return varchar2
322
379
  is
323
380
  foo varchar2(3);
324
- begin
381
+ begin
325
382
  return('foo');
326
383
  end;
327
384
  SQL
data/spec/spec_helper.rb CHANGED
@@ -103,7 +103,6 @@ module LoggerSpecHelper
103
103
  def wait
104
104
  @notifier.wait if @notifier
105
105
  end
106
-
107
106
  end
108
107
 
109
108
  module SchemaSpecHelper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-oracle_enhanced-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.7
4
+ version: 1.7.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.5.2
136
+ rubygems_version: 2.6.11
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Oracle enhanced adapter for ActiveRecord