activerecord-oracle_enhanced-adapter 1.5.6 → 1.6.0
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 +4 -4
- data/Gemfile +2 -2
- data/History.md +107 -0
- data/README.md +271 -174
- data/VERSION +1 -1
- data/activerecord-oracle_enhanced-adapter.gemspec +26 -22
- data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +65 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +257 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +17 -16
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +95 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +4 -32
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +546 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +65 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +26 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +159 -66
- data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
- data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
- data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +6 -31
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +63 -63
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +7 -13
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +25 -178
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +14 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +1 -0
- data/spec/spec_config.yaml.template +10 -0
- data/spec/spec_helper.rb +21 -10
- metadata +27 -23
- data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
- data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -197
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
- /data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
- /data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.rb} +0 -0
- /data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +0 -0
- /data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +0 -0
- /data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +0 -0
@@ -67,21 +67,21 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
67
67
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
68
68
|
columns = @conn.columns('test_employees')
|
69
69
|
column = columns.detect{|c| c.name == "hire_date"}
|
70
|
-
column.
|
70
|
+
column.type_cast_from_database(Time.now).class.should == Time
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
74
74
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
75
75
|
columns = @conn.columns('test_employees')
|
76
76
|
column = columns.detect{|c| c.name == "hire_date"}
|
77
|
-
column.
|
77
|
+
column.type_cast_from_database(Time.now).class.should == Date
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should typecast DateTime value to Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
81
81
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
82
82
|
columns = @conn.columns('test_employees')
|
83
83
|
column = columns.detect{|c| c.name == "hire_date"}
|
84
|
-
column.
|
84
|
+
column.type_cast_from_database(DateTime.new(1900,1,1)).class.should == Date
|
85
85
|
end
|
86
86
|
|
87
87
|
describe "/ DATE values from ActiveRecord model" do
|
@@ -206,7 +206,6 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
206
206
|
job_id NUMBER,
|
207
207
|
salary NUMBER,
|
208
208
|
commission_pct NUMBER(2,2),
|
209
|
-
unwise_name_id NUMBER(2,2),
|
210
209
|
manager_id NUMBER(6),
|
211
210
|
is_manager NUMBER(1),
|
212
211
|
department_id NUMBER(4,0),
|
@@ -219,46 +218,17 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
219
218
|
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
220
219
|
SQL
|
221
220
|
end
|
222
|
-
|
221
|
+
|
223
222
|
after(:all) do
|
224
223
|
@conn.execute "DROP TABLE test2_employees"
|
225
224
|
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
226
225
|
end
|
227
226
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
columns = @conn.columns('test2_employees')
|
234
|
-
column = columns.detect{|c| c.name == "job_id"}
|
235
|
-
column.type.should == :decimal
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should set NUMBER column type as decimal if column name is not 'id' and does not ends with '_id' and emulate_integers_by_column_name is true" do
|
239
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
240
|
-
columns = @conn.columns('test2_employees')
|
241
|
-
column = columns.detect{|c| c.name == "salary"}
|
242
|
-
column.type.should == :decimal
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
context "when number_datatype_coercion is :float" do
|
247
|
-
before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
|
248
|
-
|
249
|
-
it "should set NUMBER column type as float if emulate_integers_by_column_name is false" do
|
250
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
|
251
|
-
columns = @conn.columns('test2_employees')
|
252
|
-
column = columns.detect{|c| c.name == "job_id"}
|
253
|
-
column.type.should == :float
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should set NUMBER column type as float if column name is not 'id' and does not ends with '_id' and emulate_integers_by_column_name is true" do
|
257
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
258
|
-
columns = @conn.columns('test2_employees')
|
259
|
-
column = columns.detect{|c| c.name == "salary"}
|
260
|
-
column.type.should == :float
|
261
|
-
end
|
227
|
+
it "should set NUMBER column type as decimal if emulate_integers_by_column_name is false" do
|
228
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
|
229
|
+
columns = @conn.columns('test2_employees')
|
230
|
+
column = columns.detect{|c| c.name == "job_id"}
|
231
|
+
column.type.should == :decimal
|
262
232
|
end
|
263
233
|
|
264
234
|
it "should set NUMBER column type as integer if emulate_integers_by_column_name is true" do
|
@@ -270,24 +240,10 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
270
240
|
column.type.should == :integer
|
271
241
|
end
|
272
242
|
|
273
|
-
it "should set NUMBER
|
243
|
+
it "should set NUMBER column type as decimal if column name does not contain 'id' and emulate_integers_by_column_name is true" do
|
274
244
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
275
245
|
columns = @conn.columns('test2_employees')
|
276
|
-
column = columns.detect{|c| c.name == "
|
277
|
-
column.type.should == :integer
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should set NUMBER(p,s) column type as integer if column name ends with '_id' and emulate_integers_by_column_name is true" do
|
281
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
282
|
-
columns = @conn.columns('test2_employees')
|
283
|
-
column = columns.detect{|c| c.name == "unwise_name_id"}
|
284
|
-
column.type.should == :integer
|
285
|
-
end
|
286
|
-
|
287
|
-
it "should set NUMBER(p,s) column type as decimal if column name ends with '_id' and emulate_integers_by_column_name is false" do
|
288
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
|
289
|
-
columns = @conn.columns('test2_employees')
|
290
|
-
column = columns.detect{|c| c.name == "unwise_name_id"}
|
246
|
+
column = columns.detect{|c| c.name == "salary"}
|
291
247
|
column.type.should == :decimal
|
292
248
|
end
|
293
249
|
|
@@ -295,14 +251,14 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
295
251
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
|
296
252
|
columns = @conn.columns('test2_employees')
|
297
253
|
column = columns.detect{|c| c.name == "job_id"}
|
298
|
-
column.
|
254
|
+
column.type_cast_from_database(1.0).class.should == BigDecimal
|
299
255
|
end
|
300
256
|
|
301
|
-
it "should return Fixnum value from NUMBER column if column name
|
257
|
+
it "should return Fixnum value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
|
302
258
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
303
259
|
columns = @conn.columns('test2_employees')
|
304
260
|
column = columns.detect{|c| c.name == "job_id"}
|
305
|
-
column.
|
261
|
+
column.type_cast_from_database(1.0).class.should == Fixnum
|
306
262
|
end
|
307
263
|
|
308
264
|
describe "/ NUMBER values from ActiveRecord model" do
|
@@ -310,7 +266,7 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
310
266
|
class ::Test2Employee < ActiveRecord::Base
|
311
267
|
end
|
312
268
|
end
|
313
|
-
|
269
|
+
|
314
270
|
after(:each) do
|
315
271
|
Object.send(:remove_const, "Test2Employee")
|
316
272
|
@conn.clear_types_for_columns
|
@@ -452,7 +408,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
452
408
|
columns = @conn.columns('test3_employees')
|
453
409
|
%w(has_email has_phone active_flag manager_yn).each do |col|
|
454
410
|
column = columns.detect{|c| c.name == col}
|
455
|
-
column.
|
411
|
+
column.type_cast_from_database("Y").class.should == String
|
456
412
|
end
|
457
413
|
end
|
458
414
|
|
@@ -461,8 +417,8 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
461
417
|
columns = @conn.columns('test3_employees')
|
462
418
|
%w(has_email has_phone active_flag manager_yn).each do |col|
|
463
419
|
column = columns.detect{|c| c.name == col}
|
464
|
-
column.
|
465
|
-
column.
|
420
|
+
column.type_cast_from_database("Y").class.should == TrueClass
|
421
|
+
column.type_cast_from_database("N").class.should == FalseClass
|
466
422
|
end
|
467
423
|
end
|
468
424
|
|
@@ -650,6 +606,7 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
650
606
|
|
651
607
|
end
|
652
608
|
|
609
|
+
|
653
610
|
describe "OracleEnhancedAdapter date and timestamp with different NLS date formats" do
|
654
611
|
before(:all) do
|
655
612
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
@@ -906,7 +863,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
906
863
|
@employee.reload
|
907
864
|
@employee.last_login_at.should == @today.to_time
|
908
865
|
end
|
909
|
-
|
866
|
+
|
910
867
|
end
|
911
868
|
|
912
869
|
describe "OracleEnhancedAdapter handling of CLOB columns" do
|
@@ -1383,6 +1340,7 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
1383
1340
|
end
|
1384
1341
|
end
|
1385
1342
|
|
1343
|
+
|
1386
1344
|
describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
|
1387
1345
|
before(:all) do
|
1388
1346
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
@@ -1443,3 +1401,45 @@ describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
|
|
1443
1401
|
end
|
1444
1402
|
|
1445
1403
|
end
|
1404
|
+
|
1405
|
+
describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
|
1406
|
+
before(:all) do
|
1407
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
1408
|
+
@conn = ActiveRecord::Base.connection
|
1409
|
+
@conn.execute "DROP TABLE test2_employees" rescue nil
|
1410
|
+
@conn.execute <<-SQL
|
1411
|
+
CREATE TABLE test2_employees (
|
1412
|
+
id NUMBER PRIMARY KEY,
|
1413
|
+
first_name VARCHAR2(20),
|
1414
|
+
last_name VARCHAR2(25),
|
1415
|
+
email VARCHAR2(25),
|
1416
|
+
phone_number VARCHAR2(20),
|
1417
|
+
hire_date DATE,
|
1418
|
+
job_id NUMBER,
|
1419
|
+
salary NUMBER,
|
1420
|
+
commission_pct NUMBER(2,2),
|
1421
|
+
hourly_rate BINARY_FLOAT,
|
1422
|
+
manager_id NUMBER(6),
|
1423
|
+
is_manager NUMBER(1),
|
1424
|
+
department_id NUMBER(4,0),
|
1425
|
+
created_at DATE
|
1426
|
+
)
|
1427
|
+
SQL
|
1428
|
+
@conn.execute "DROP SEQUENCE test2_employees_seq" rescue nil
|
1429
|
+
@conn.execute <<-SQL
|
1430
|
+
CREATE SEQUENCE test2_employees_seq MINVALUE 1
|
1431
|
+
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
1432
|
+
SQL
|
1433
|
+
end
|
1434
|
+
|
1435
|
+
after(:all) do
|
1436
|
+
@conn.execute "DROP TABLE test2_employees"
|
1437
|
+
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
1438
|
+
end
|
1439
|
+
|
1440
|
+
it "should set BINARY_FLOAT column type as float" do
|
1441
|
+
columns = @conn.columns('test2_employees')
|
1442
|
+
column = columns.detect{|c| c.name == "hourly_rate"}
|
1443
|
+
column.type.should == :float
|
1444
|
+
end
|
1445
|
+
end
|
@@ -16,7 +16,6 @@ if ActiveRecord::Base.method_defined?(:changed?)
|
|
16
16
|
last_name VARCHAR2(25),
|
17
17
|
job_id NUMBER(6,0) NULL,
|
18
18
|
salary NUMBER(8,2),
|
19
|
-
pto_per_hour NUMBER,
|
20
19
|
comments CLOB,
|
21
20
|
hire_date DATE
|
22
21
|
)
|
@@ -28,7 +27,7 @@ if ActiveRecord::Base.method_defined?(:changed?)
|
|
28
27
|
class TestEmployee < ActiveRecord::Base
|
29
28
|
end
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
after(:all) do
|
33
32
|
Object.send(:remove_const, "TestEmployee")
|
34
33
|
@conn.execute "DROP TABLE test_employees"
|
@@ -63,16 +62,6 @@ if ActiveRecord::Base.method_defined?(:changed?)
|
|
63
62
|
@employee.should_not be_changed
|
64
63
|
end
|
65
64
|
|
66
|
-
it "should not mark empty float (stored as NULL) as changed when reassigning it" do
|
67
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion) { :float }
|
68
|
-
@employee = TestEmployee.create!(:pto_per_hour => '')
|
69
|
-
@employee.pto_per_hour = ''
|
70
|
-
@employee.should_not be_changed
|
71
|
-
@employee.reload
|
72
|
-
@employee.pto_per_hour = ''
|
73
|
-
@employee.should_not be_changed
|
74
|
-
end
|
75
|
-
|
76
65
|
it "should not mark empty text (stored as NULL) as changed when reassigning it" do
|
77
66
|
@employee = TestEmployee.create!(:comments => nil)
|
78
67
|
@employee.comments = nil
|
@@ -122,7 +111,7 @@ if ActiveRecord::Base.method_defined?(:changed?)
|
|
122
111
|
@employee = TestEmployee.new
|
123
112
|
@employee.job_id = 0
|
124
113
|
@employee.save!.should be_true
|
125
|
-
|
114
|
+
|
126
115
|
@employee.should_not be_changed
|
127
116
|
|
128
117
|
@employee.job_id = '0'
|
@@ -147,6 +136,11 @@ if ActiveRecord::Base.method_defined?(:changed?)
|
|
147
136
|
end
|
148
137
|
end
|
149
138
|
|
139
|
+
it "should be able to handle attributes which are not backed by a column" do
|
140
|
+
TestEmployee.create!(:comments => "initial")
|
141
|
+
@employee = TestEmployee.select("#{TestEmployee.quoted_table_name}.*, 24 ranking").first
|
142
|
+
expect { @employee.ranking = 25 }.to_not raise_error
|
143
|
+
end
|
150
144
|
end
|
151
145
|
|
152
146
|
end
|
@@ -22,7 +22,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
22
22
|
schema_define do
|
23
23
|
create_table :test_posts, options do |t|
|
24
24
|
t.string :title
|
25
|
-
t.timestamps
|
25
|
+
t.timestamps null: true
|
26
26
|
end
|
27
27
|
add_index :test_posts, :title
|
28
28
|
end
|
@@ -180,21 +180,21 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
180
180
|
schema_define do
|
181
181
|
add_foreign_key :test_comments, :test_posts
|
182
182
|
end
|
183
|
-
standard_dump.should =~ /add_foreign_key "test_comments", "test_posts"
|
183
|
+
standard_dump.should =~ /add_foreign_key "test_comments", "test_posts"/
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should include foreign key with delete dependency in schema dump" do
|
187
187
|
schema_define do
|
188
188
|
add_foreign_key :test_comments, :test_posts, dependent: :delete
|
189
189
|
end
|
190
|
-
standard_dump.should =~ /add_foreign_key "test_comments", "test_posts",
|
190
|
+
standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", on_delete: :cascade/
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should include foreign key with nullify dependency in schema dump" do
|
194
194
|
schema_define do
|
195
195
|
add_foreign_key :test_comments, :test_posts, dependent: :nullify
|
196
196
|
end
|
197
|
-
standard_dump.should =~ /add_foreign_key "test_comments", "test_posts",
|
197
|
+
standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", on_delete: :nullify/
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should not include foreign keys on ignored table names in schema dump" do
|
@@ -226,6 +226,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
226
226
|
end
|
227
227
|
|
228
228
|
it "should include composite foreign keys" do
|
229
|
+
pending "Composite foreign keys are not supported in this version"
|
229
230
|
schema_define do
|
230
231
|
add_column :test_posts, :baz_id, :integer
|
231
232
|
add_column :test_posts, :fooz_id, :integer
|
@@ -376,7 +377,7 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
376
377
|
t.virtual :full_name, :as => "first_name || ', ' || last_name"
|
377
378
|
t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
|
378
379
|
t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
|
379
|
-
t.virtual :name_ratio, :as=>'(LENGTH(first_name)/LENGTH(last_name))'
|
380
|
+
t.virtual :name_ratio, :as=>'(LENGTH(first_name)*10/LENGTH(last_name)*10)'
|
380
381
|
t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
|
381
382
|
t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
|
382
383
|
end
|
@@ -402,30 +403,13 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
402
403
|
end
|
403
404
|
end
|
404
405
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*),(\s*)type: :float$/
|
413
|
-
standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
|
414
|
-
standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
context "when number_datatype_coercion is :decimal" do
|
419
|
-
before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
|
420
|
-
|
421
|
-
it 'should dump correctly' do
|
422
|
-
standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
|
423
|
-
standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
|
424
|
-
standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)scale: 0,(\s*)as:(.*),(\s*)type: :integer/
|
425
|
-
standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*)\"$/
|
426
|
-
standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
|
427
|
-
standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
|
428
|
-
end
|
406
|
+
it 'should dump correctly' do
|
407
|
+
standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
|
408
|
+
standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
|
409
|
+
standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)as:(.*),(\s*)type: :integer/
|
410
|
+
standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*)\"$/ # no :type
|
411
|
+
standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
|
412
|
+
standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
|
429
413
|
end
|
430
414
|
|
431
415
|
context 'with column cache' do
|
@@ -471,160 +455,23 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
471
455
|
end
|
472
456
|
end
|
473
457
|
|
474
|
-
describe "
|
475
|
-
|
458
|
+
describe ":float datatype" do
|
459
|
+
before(:each) do
|
476
460
|
schema_define do
|
477
|
-
|
478
|
-
|
479
|
-
end
|
480
|
-
|
481
|
-
let(:value_within_max_precision) { (10 ** @conn.class::NUMBER_MAX_PRECISION) - 1 }
|
482
|
-
let(:value_exceeding_max_precision) { (10 ** @conn.class::NUMBER_MAX_PRECISION) + 1 }
|
483
|
-
|
484
|
-
context "when using ActiveRecord::Schema.define and ActiveRecord::ConnectionAdapters::TableDefinition#float" do
|
485
|
-
before :each do
|
486
|
-
schema_define do
|
487
|
-
create_table :test_numbers, :force => true do |t|
|
488
|
-
t.float :value
|
489
|
-
end
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
context "when number_datatype_coercion is :float" do
|
494
|
-
before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
|
495
|
-
|
496
|
-
it "should dump correctly" do
|
497
|
-
standard_dump.should =~ /t\.float "value"$/
|
498
|
-
end
|
499
|
-
end
|
500
|
-
|
501
|
-
context "when number_datatype_coercion is :decimal" do
|
502
|
-
before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
|
503
|
-
|
504
|
-
it "should dump correctly" do
|
505
|
-
standard_dump.should =~ /t\.decimal "value"$/
|
461
|
+
create_table :test_floats, force: true do |t|
|
462
|
+
t.float :hourly_rate
|
506
463
|
end
|
507
464
|
end
|
508
465
|
end
|
509
466
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
@conn = ActiveRecord::Base.connection
|
514
|
-
@conn.execute <<-SQL
|
515
|
-
CREATE TABLE test_numbers (
|
516
|
-
id NUMBER(#{@conn.class::NUMBER_MAX_PRECISION},0) PRIMARY KEY,
|
517
|
-
value NUMBER
|
518
|
-
)
|
519
|
-
SQL
|
520
|
-
@conn.execute <<-SQL
|
521
|
-
CREATE SEQUENCE test_numbers_seq MINVALUE 1
|
522
|
-
INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
|
523
|
-
SQL
|
524
|
-
end
|
525
|
-
|
526
|
-
context "when number_datatype_coercion is :float" do
|
527
|
-
before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
|
528
|
-
|
529
|
-
it "should dump correctly" do
|
530
|
-
standard_dump.should =~ /t\.float "value"$/
|
531
|
-
end
|
532
|
-
|
533
|
-
describe "ActiveRecord saving" do
|
534
|
-
before :each do
|
535
|
-
class ::TestNumber < ActiveRecord::Base
|
536
|
-
self.table_name = "test_numbers"
|
537
|
-
end
|
538
|
-
end
|
539
|
-
|
540
|
-
it "should allow saving of values within NUMBER_MAX_PRECISION" do
|
541
|
-
number = TestNumber.new(value: value_within_max_precision)
|
542
|
-
number.save!
|
543
|
-
number.reload
|
544
|
-
number.value.should eq(value_within_max_precision)
|
545
|
-
end
|
546
|
-
|
547
|
-
it "should allow saving of values larger than NUMBER_MAX_PRECISION" do
|
548
|
-
number = TestNumber.new(value: value_exceeding_max_precision)
|
549
|
-
number.save!
|
550
|
-
number.reload
|
551
|
-
number.value.should eq(value_exceeding_max_precision)
|
552
|
-
end
|
553
|
-
|
554
|
-
it "should be recreatable from dump and have same properties" do
|
555
|
-
# Simulating db:schema:dump & db:test:load
|
556
|
-
2.times do
|
557
|
-
create_table_dump = standard_dump[/(create_table.+?end)/m]
|
558
|
-
|
559
|
-
schema_define do
|
560
|
-
drop_table "test_numbers"
|
561
|
-
end
|
562
|
-
|
563
|
-
schema_define(&eval("-> * { #{create_table_dump} }"))
|
564
|
-
end
|
565
|
-
|
566
|
-
number = TestNumber.new(value: value_within_max_precision)
|
567
|
-
number.save!
|
568
|
-
|
569
|
-
number2 = TestNumber.new(value: value_exceeding_max_precision)
|
570
|
-
number2.save!
|
571
|
-
end
|
572
|
-
end
|
467
|
+
after(:each) do
|
468
|
+
schema_define do
|
469
|
+
drop_table :test_floats
|
573
470
|
end
|
471
|
+
end
|
574
472
|
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
standard_dump.should =~ /t\.decimal "value"$/
|
580
|
-
end
|
581
|
-
|
582
|
-
describe "ActiveRecord saving" do
|
583
|
-
before :each do
|
584
|
-
class ::TestNumber < ActiveRecord::Base
|
585
|
-
self.table_name = "test_numbers"
|
586
|
-
end
|
587
|
-
end
|
588
|
-
|
589
|
-
it "should allow saving of values within NUMBER_MAX_PRECISION" do
|
590
|
-
number = TestNumber.new(value: value_within_max_precision)
|
591
|
-
number.save!
|
592
|
-
number.reload
|
593
|
-
number.value.should eq(value_within_max_precision)
|
594
|
-
end
|
595
|
-
|
596
|
-
it "should allow saving of values larger than NUMBER_MAX_PRECISION" do
|
597
|
-
number = TestNumber.new(value: value_exceeding_max_precision)
|
598
|
-
number.save!
|
599
|
-
number.reload
|
600
|
-
number.value.should eq(value_exceeding_max_precision)
|
601
|
-
end
|
602
|
-
|
603
|
-
it "should be recreatable from dump and have same properties" do
|
604
|
-
# Simulating db:schema:dump & db:test:load
|
605
|
-
2.times do |i|
|
606
|
-
create_table_dump = standard_dump[/(create_table.+?end)/m]
|
607
|
-
|
608
|
-
schema_define do
|
609
|
-
drop_table "test_numbers"
|
610
|
-
end
|
611
|
-
|
612
|
-
schema_define(&eval("-> * { #{create_table_dump} }"))
|
613
|
-
end
|
614
|
-
|
615
|
-
number = TestNumber.new(value: value_within_max_precision)
|
616
|
-
number.save!
|
617
|
-
|
618
|
-
# Raises 'ORA-01438' as :value column type isn't FLOAT'ish
|
619
|
-
number2 = TestNumber.new(value: value_exceeding_max_precision)
|
620
|
-
lambda do
|
621
|
-
number2.save!
|
622
|
-
end.should raise_error() { |e| e.message.should =~ /ORA-01438/ }
|
623
|
-
end
|
624
|
-
end
|
625
|
-
end # context (:decimal)
|
626
|
-
|
627
|
-
end # context (handwritten)
|
628
|
-
end # describe (NUMBER columns)
|
629
|
-
|
473
|
+
it "should dump float type correctly" do
|
474
|
+
standard_dump.should =~ /t\.float "hourly_rate"$/
|
475
|
+
end
|
476
|
+
end
|
630
477
|
end
|
@@ -627,25 +627,28 @@ end
|
|
627
627
|
end
|
628
628
|
|
629
629
|
it "should add foreign key" do
|
630
|
+
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_test_post_id_fk").first(10)}"
|
631
|
+
|
630
632
|
schema_define do
|
631
633
|
add_foreign_key :test_comments, :test_posts
|
632
634
|
end
|
633
635
|
lambda do
|
634
636
|
TestComment.create(:body => "test", :test_post_id => 1)
|
635
|
-
end.should raise_error() {|e| e.message.should =~ /ORA-02291
|
637
|
+
end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
|
636
638
|
end
|
637
639
|
|
638
640
|
context "with table_name_prefix" do
|
639
641
|
let(:table_name_prefix) { 'xxx_' }
|
640
642
|
|
641
643
|
it "should use table_name_prefix for foreign table" do
|
644
|
+
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("xxx_test_comments_test_post_id_fk").first(10)}"
|
642
645
|
schema_define do
|
643
646
|
add_foreign_key :test_comments, :test_posts
|
644
647
|
end
|
645
648
|
|
646
649
|
lambda do
|
647
650
|
TestComment.create(:body => "test", :test_post_id => 1)
|
648
|
-
end.should raise_error() {|e| e.message.should =~ /ORA-02291
|
651
|
+
end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
|
649
652
|
end
|
650
653
|
end
|
651
654
|
|
@@ -653,13 +656,14 @@ end
|
|
653
656
|
let(:table_name_suffix) { '_xxx' }
|
654
657
|
|
655
658
|
it "should use table_name_suffix for foreign table" do
|
659
|
+
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_xxx_test_post_id_fk").first(10)}"
|
656
660
|
schema_define do
|
657
661
|
add_foreign_key :test_comments, :test_posts
|
658
662
|
end
|
659
663
|
|
660
664
|
lambda do
|
661
665
|
TestComment.create(:body => "test", :test_post_id => 1)
|
662
|
-
end.should raise_error() {|e| e.message.should =~ /ORA-02291
|
666
|
+
end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
|
663
667
|
end
|
664
668
|
end
|
665
669
|
|
@@ -678,7 +682,8 @@ end
|
|
678
682
|
end
|
679
683
|
lambda do
|
680
684
|
TestComment.create(:body => "test", :test_post_id => 1)
|
681
|
-
end.should raise_error() {|e| e.message.should =~
|
685
|
+
end.should raise_error() {|e| e.message.should =~
|
686
|
+
/ORA-02291.*\.C#{Digest::SHA1.hexdigest("test_comments_test_post_id_foreign_key")[0,29].upcase}/}
|
682
687
|
end
|
683
688
|
|
684
689
|
it "should add foreign key with very long name which is shortened" do
|
@@ -692,12 +697,14 @@ end
|
|
692
697
|
end
|
693
698
|
|
694
699
|
it "should add foreign key with column" do
|
700
|
+
fk_name = "fk_rails_#{Digest::SHA256.hexdigest("test_comments_post_id_fk").first(10)}"
|
701
|
+
|
695
702
|
schema_define do
|
696
703
|
add_foreign_key :test_comments, :test_posts, :column => "post_id"
|
697
704
|
end
|
698
705
|
lambda do
|
699
706
|
TestComment.create(:body => "test", :post_id => 1)
|
700
|
-
end.should raise_error() {|e| e.message.should =~ /ORA-02291
|
707
|
+
end.should raise_error() {|e| e.message.should =~ /ORA-02291.*\.#{fk_name}/i}
|
701
708
|
end
|
702
709
|
|
703
710
|
it "should add foreign key with delete dependency" do
|
@@ -721,6 +728,7 @@ end
|
|
721
728
|
end
|
722
729
|
|
723
730
|
it "should add a composite foreign key" do
|
731
|
+
pending "Composite foreign keys are not supported in this version"
|
724
732
|
schema_define do
|
725
733
|
add_column :test_posts, :baz_id, :integer
|
726
734
|
add_column :test_posts, :fooz_id, :integer
|
@@ -743,6 +751,7 @@ end
|
|
743
751
|
end
|
744
752
|
|
745
753
|
it "should add a composite foreign key with name" do
|
754
|
+
pending "Composite foreign keys are not supported in this version"
|
746
755
|
schema_define do
|
747
756
|
add_column :test_posts, :baz_id, :integer
|
748
757
|
add_column :test_posts, :fooz_id, :integer
|
@@ -92,6 +92,7 @@ describe "OracleEnhancedAdapter structure dump" do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should dump composite foreign keys" do
|
95
|
+
pending "Composite foreign keys are not supported in this version"
|
95
96
|
@conn.add_column :foos, :fooz_id, :integer
|
96
97
|
@conn.add_column :foos, :baz_id, :integer
|
97
98
|
|