activerecord-oracle_enhanced-adapter 1.5.6 → 1.6.9

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/.travis/oracle/download.sh +14 -0
  3. data/.travis/oracle/install.sh +31 -0
  4. data/.travis/setup_accounts.sh +9 -0
  5. data/.travis.yml +39 -0
  6. data/Gemfile +8 -8
  7. data/History.md +189 -0
  8. data/README.md +388 -178
  9. data/RUNNING_TESTS.md +11 -6
  10. data/VERSION +1 -1
  11. data/activerecord-oracle_enhanced-adapter.gemspec +29 -26
  12. data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
  13. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +66 -0
  14. data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
  15. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +260 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
  18. data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +13 -4
  19. data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +11 -5
  20. data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +1 -1
  21. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +34 -35
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +95 -0
  23. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +14 -37
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +562 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +65 -0
  26. data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +63 -14
  27. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +171 -73
  29. data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
  30. data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
  31. data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
  32. data/lib/activerecord-oracle_enhanced-adapter.rb +1 -1
  33. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +127 -49
  34. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +46 -5
  35. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +11 -3
  36. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +3 -3
  37. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +151 -78
  38. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +4 -4
  39. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +10 -16
  40. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -1
  41. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +5 -5
  42. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +65 -181
  43. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +114 -11
  44. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +17 -1
  45. data/spec/spec_config.yaml.template +11 -0
  46. data/spec/spec_helper.rb +31 -12
  47. data/spec/support/alter_system_user_password.sql +2 -0
  48. data/spec/support/create_oracle_enhanced_users.sql +31 -0
  49. metadata +37 -27
  50. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
  51. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
  52. data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
  53. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
  54. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -197
  55. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
  56. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
  57. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
  58. /data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
  59. /data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.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.type_cast(Time.now).class.should == Time
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.type_cast(Time.now).class.should == Date
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.type_cast(DateTime.new(1900,1,1)).class.should == Date
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
- context "when number_datatype_coercion is :decimal" do
229
- before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
230
-
231
- it "should set NUMBER column type as decimal if emulate_integers_by_column_name is false" do
232
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
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(p,0) column type as integer" do
274
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
275
- columns = @conn.columns('test2_employees')
276
- column = columns.detect{|c| c.name == "department_id"}
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
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
281
244
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
282
245
  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.type_cast(1.0).class.should == BigDecimal
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 ends with '_id' and emulate_integers_by_column_name is true" do
257
+ it "should return Integer 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.type_cast(1.0).class.should == Fixnum
261
+ expect(column.type_cast_from_database(1.0)).to be_a(Integer)
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
@@ -335,16 +291,16 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
335
291
  @employee2.job_id.class.should == BigDecimal
336
292
  end
337
293
 
338
- it "should return Fixnum value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
294
+ it "should return Integer value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
339
295
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
340
296
  create_employee2
341
- @employee2.job_id.class.should == Fixnum
297
+ expect(@employee2.job_id).to be_a(Integer)
342
298
  end
343
299
 
344
- it "should return Fixnum value from NUMBER column with integer value using _before_type_cast method" do
300
+ it "should return Integer value from NUMBER column with integer value using _before_type_cast method" do
345
301
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
346
302
  create_employee2
347
- @employee2.job_id_before_type_cast.class.should == Fixnum
303
+ expect(@employee2.job_id_before_type_cast).to be_a(Integer)
348
304
  end
349
305
 
350
306
  it "should return BigDecimal value from NUMBER column if column name does not contain 'id' and emulate_integers_by_column_name is true" do
@@ -353,11 +309,11 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
353
309
  @employee2.salary.class.should == BigDecimal
354
310
  end
355
311
 
356
- it "should return Fixnum value from NUMBER column if column specified in set_integer_columns" do
312
+ it "should return Integer value from NUMBER column if column specified in set_integer_columns" do
357
313
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
358
314
  Test2Employee.set_integer_columns :job_id
359
315
  create_employee2
360
- @employee2.job_id.class.should == Fixnum
316
+ expect(@employee2.job_id).to be_a(Integer)
361
317
  end
362
318
 
363
319
  it "should return Boolean value from NUMBER(1) column if emulate booleans is used" do
@@ -366,17 +322,17 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
366
322
  @employee2.is_manager.class.should == TrueClass
367
323
  end
368
324
 
369
- it "should return Fixnum value from NUMBER(1) column if emulate booleans is not used" do
325
+ it "should return Integer value from NUMBER(1) column if emulate booleans is not used" do
370
326
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = false
371
327
  create_employee2
372
- @employee2.is_manager.class.should == Fixnum
328
+ expect(@employee2.is_manager).to be_a(Integer)
373
329
  end
374
330
 
375
- it "should return Fixnum value from NUMBER(1) column if column specified in set_integer_columns" do
331
+ it "should return Integer value from NUMBER(1) column if column specified in set_integer_columns" do
376
332
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
377
333
  Test2Employee.set_integer_columns :is_manager
378
334
  create_employee2
379
- @employee2.is_manager.class.should == Fixnum
335
+ expect(@employee2.is_manager).to be_a(Integer)
380
336
  end
381
337
 
382
338
  end
@@ -420,6 +376,43 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
420
376
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
421
377
  end
422
378
 
379
+ before(:each) do
380
+ class ::Test3Employee < ActiveRecord::Base
381
+ end
382
+ end
383
+
384
+ after(:each) do
385
+ Object.send(:remove_const, "Test3Employee")
386
+ @conn.clear_types_for_columns
387
+ ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
388
+ end
389
+
390
+ describe "default values in new records" do
391
+ context "when emulate_booleans_from_strings is false" do
392
+ before do
393
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
394
+ end
395
+
396
+ it "are Y or N" do
397
+ subject = Test3Employee.new
398
+ expect(subject.has_phone).to eq('Y')
399
+ expect(subject.manager_yn).to eq('N')
400
+ end
401
+ end
402
+
403
+ context "when emulate_booleans_from_strings is true" do
404
+ before do
405
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
406
+ end
407
+
408
+ it "are True or False" do
409
+ subject = Test3Employee.new
410
+ expect(subject.has_phone).to be_a(TrueClass)
411
+ expect(subject.manager_yn).to be_a(FalseClass)
412
+ end
413
+ end
414
+ end
415
+
423
416
  it "should set CHAR/VARCHAR2 column type as string if emulate_booleans_from_strings is false" do
424
417
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
425
418
  columns = @conn.columns('test3_employees')
@@ -452,7 +445,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
452
445
  columns = @conn.columns('test3_employees')
453
446
  %w(has_email has_phone active_flag manager_yn).each do |col|
454
447
  column = columns.detect{|c| c.name == col}
455
- column.type_cast("Y").class.should == String
448
+ column.type_cast_from_database("Y").class.should == String
456
449
  end
457
450
  end
458
451
 
@@ -461,8 +454,8 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
461
454
  columns = @conn.columns('test3_employees')
462
455
  %w(has_email has_phone active_flag manager_yn).each do |col|
463
456
  column = columns.detect{|c| c.name == col}
464
- column.type_cast("Y").class.should == TrueClass
465
- column.type_cast("N").class.should == FalseClass
457
+ column.type_cast_from_database("Y").class.should == TrueClass
458
+ column.type_cast_from_database("N").class.should == FalseClass
466
459
  end
467
460
  end
468
461
 
@@ -481,19 +474,16 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
481
474
  it "should get default value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
482
475
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
483
476
  columns = @conn.columns('test3_employees')
484
- columns.detect{|c| c.name == 'has_phone'}.default.should be_true
485
- columns.detect{|c| c.name == 'manager_yn'}.default.should be_false
477
+ columns.detect{|c| c.name == 'has_phone'}.default.should eq 'Y'
478
+ columns.detect{|c| c.name == 'manager_yn'}.default.should be false
486
479
  end
487
480
 
488
481
  describe "/ VARCHAR2 boolean values from ActiveRecord model" do
489
482
  before(:each) do
490
483
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
491
- class ::Test3Employee < ActiveRecord::Base
492
- end
493
484
  end
494
485
 
495
486
  after(:each) do
496
- Object.send(:remove_const, "Test3Employee")
497
487
  @conn.clear_types_for_columns
498
488
  ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
499
489
  end
@@ -650,6 +640,7 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
650
640
 
651
641
  end
652
642
 
643
+
653
644
  describe "OracleEnhancedAdapter date and timestamp with different NLS date formats" do
654
645
  before(:all) do
655
646
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
@@ -906,7 +897,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
906
897
  @employee.reload
907
898
  @employee.last_login_at.should == @today.to_time
908
899
  end
909
-
900
+
910
901
  end
911
902
 
912
903
  describe "OracleEnhancedAdapter handling of CLOB columns" do
@@ -1119,6 +1110,20 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
1119
1110
  @employee.comments.should == @char_data
1120
1111
  end
1121
1112
 
1113
+ it "should store serializable ruby data structures" do
1114
+ ruby_data1 = {"arbitrary1" => ["ruby", :data, 123]}
1115
+ ruby_data2 = {"arbitrary2" => ["ruby", :data, 123]}
1116
+ @employee = Test2Employee.create!(
1117
+ :comments => ruby_data1
1118
+ )
1119
+ @employee.reload
1120
+ @employee.comments.should == ruby_data1
1121
+ @employee.comments = ruby_data2
1122
+ @employee.save
1123
+ @employee.reload
1124
+ @employee.comments.should == ruby_data2
1125
+ end
1126
+
1122
1127
  it "should keep unchanged serialized data when other columns changed" do
1123
1128
  @employee = Test2Employee.create!(
1124
1129
  :first_name => "First",
@@ -1130,6 +1135,18 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
1130
1135
  @employee.reload
1131
1136
  @employee.comments.should == "initial serialized data"
1132
1137
  end
1138
+
1139
+ it "should keep serialized data after save" do
1140
+ @employee = Test2Employee.new
1141
+ @employee.comments = {:length=>{:is=>1}}
1142
+ @employee.save
1143
+ @employee.reload
1144
+ @employee.comments.should == {:length=>{:is=>1}}
1145
+ @employee.comments = {:length=>{:is=>2}}
1146
+ @employee.save
1147
+ @employee.reload
1148
+ @employee.comments.should == {:length=>{:is=>2}}
1149
+ end
1133
1150
  end
1134
1151
 
1135
1152
  describe "OracleEnhancedAdapter handling of BLOB columns" do
@@ -1383,6 +1400,7 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
1383
1400
  end
1384
1401
  end
1385
1402
 
1403
+
1386
1404
  describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
1387
1405
  before(:all) do
1388
1406
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
@@ -1443,3 +1461,58 @@ describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
1443
1461
  end
1444
1462
 
1445
1463
  end
1464
+
1465
+ describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
1466
+ before(:all) do
1467
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
1468
+ @conn = ActiveRecord::Base.connection
1469
+ @conn.execute "DROP TABLE test2_employees" rescue nil
1470
+ @conn.execute <<-SQL
1471
+ CREATE TABLE test2_employees (
1472
+ id NUMBER PRIMARY KEY,
1473
+ first_name VARCHAR2(20),
1474
+ last_name VARCHAR2(25),
1475
+ email VARCHAR2(25),
1476
+ phone_number VARCHAR2(20),
1477
+ hire_date DATE,
1478
+ job_id NUMBER,
1479
+ salary NUMBER,
1480
+ commission_pct NUMBER(2,2),
1481
+ hourly_rate BINARY_FLOAT,
1482
+ manager_id NUMBER(6),
1483
+ is_manager NUMBER(1),
1484
+ department_id NUMBER(4,0),
1485
+ created_at DATE
1486
+ )
1487
+ SQL
1488
+ @conn.execute "DROP SEQUENCE test2_employees_seq" rescue nil
1489
+ @conn.execute <<-SQL
1490
+ CREATE SEQUENCE test2_employees_seq MINVALUE 1
1491
+ INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
1492
+ SQL
1493
+
1494
+ class ::Test2Employee < ActiveRecord::Base
1495
+ end
1496
+ end
1497
+
1498
+ after(:all) do
1499
+ Object.send(:remove_const, "Test2Employee")
1500
+
1501
+ @conn.execute "DROP TABLE test2_employees"
1502
+ @conn.execute "DROP SEQUENCE test2_employees_seq"
1503
+ end
1504
+
1505
+ it "should set BINARY_FLOAT column type as float" do
1506
+ columns = @conn.columns('test2_employees')
1507
+ column = columns.detect{|c| c.name == "hourly_rate"}
1508
+ column.type.should == :float
1509
+ end
1510
+
1511
+ it "should BINARY_FLOAT column type returns an approximate value" do
1512
+ employee = Test2Employee.create(hourly_rate: 4.4)
1513
+
1514
+ employee.reload
1515
+
1516
+ expect(employee.hourly_rate).to eq(4.400000095367432)
1517
+ end
1518
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'active_record/connection_adapters/oracle_enhanced_database_tasks'
2
+ require 'active_record/connection_adapters/oracle_enhanced/database_tasks'
3
3
  require 'stringio'
4
4
  require 'tempfile'
5
5
 
@@ -42,14 +42,14 @@ describe "Oracle Enhanced adapter database tasks" do
42
42
  describe "drop" do
43
43
  before { ActiveRecord::Tasks::DatabaseTasks.drop(config) }
44
44
  it "drops all tables" do
45
- ActiveRecord::Base.connection.table_exists?(:test_posts).should be_false
45
+ ActiveRecord::Base.connection.table_exists?(:test_posts).should be false
46
46
  end
47
47
  end
48
48
 
49
49
  describe "purge" do
50
50
  before { ActiveRecord::Tasks::DatabaseTasks.purge(config) }
51
51
  it "drops all tables" do
52
- ActiveRecord::Base.connection.table_exists?(:test_posts).should be_false
52
+ ActiveRecord::Base.connection.table_exists?(:test_posts).should be false
53
53
  ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM RECYCLEBIN").should == 0
54
54
  end
55
55
  end
@@ -77,7 +77,7 @@ describe "Oracle Enhanced adapter database tasks" do
77
77
  ActiveRecord::Tasks::DatabaseTasks.structure_load(config, temp_file)
78
78
  end
79
79
  it "loads the database structure from a file" do
80
- ActiveRecord::Base.connection.table_exists?(:test_posts).should be_true
80
+ ActiveRecord::Base.connection.table_exists?(:test_posts).should be true
81
81
  end
82
82
  end
83
83
 
@@ -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
@@ -121,8 +110,8 @@ if ActiveRecord::Base.method_defined?(:changed?)
121
110
  it "should not mark integer as changed when reassigning it" do
122
111
  @employee = TestEmployee.new
123
112
  @employee.job_id = 0
124
- @employee.save!.should be_true
125
-
113
+ @employee.save.should be true
114
+
126
115
  @employee.should_not be_changed
127
116
 
128
117
  @employee.job_id = '0'
@@ -133,7 +122,7 @@ if ActiveRecord::Base.method_defined?(:changed?)
133
122
  @employee = TestEmployee.create!(
134
123
  :comments => "initial"
135
124
  )
136
- @employee.save!.should be_true
125
+ @employee.save.should be true
137
126
  @employee.reload
138
127
  @employee.comments.should == 'initial'
139
128
 
@@ -141,12 +130,17 @@ if ActiveRecord::Base.method_defined?(:changed?)
141
130
  class << oci_conn
142
131
  def write_lob(lob, value, is_binary = false); raise "don't do this'"; end
143
132
  end
144
- @employee.save!.should_not raise_exception(RuntimeError, "don't do this'")
133
+ expect { @employee.save! }.to_not raise_error
145
134
  class << oci_conn
146
135
  remove_method :write_lob
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
@@ -12,7 +12,7 @@ describe "OracleEnhancedAdapter emulate OracleAdapter" do
12
12
  it "should be an OracleAdapter" do
13
13
  @conn = ActiveRecord::Base.establish_connection(CONNECTION_PARAMS.merge(:emulate_oracle_adapter => true))
14
14
  ActiveRecord::Base.connection.should_not be_nil
15
- ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::OracleAdapter).should be_true
15
+ ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::OracleAdapter).should be true
16
16
  end
17
17
 
18
18
  after(:all) do
@@ -186,7 +186,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
186
186
  lambda {
187
187
  @employee.save
188
188
  }.should raise_error("Make the transaction rollback")
189
- @employee.id.should == nil
189
+ @employee.new_record?.should be true
190
190
  TestEmployee.count.should == employees_count
191
191
  end
192
192
 
@@ -263,7 +263,6 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
263
263
  end
264
264
 
265
265
  it "should delete record and set destroyed flag" do
266
- return pending("Not in this ActiveRecord version (requires >= 2.3.5)") unless TestEmployee.method_defined?(:destroyed?)
267
266
  @employee = TestEmployee.create(
268
267
  :first_name => "First",
269
268
  :last_name => "Last",
@@ -325,7 +324,8 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
325
324
  :last_name => "Last",
326
325
  :hire_date => @today
327
326
  )
328
- @logger.logged(:debug).last.should match(/^TestEmployee Create \(\d+\.\d+(ms)?\) custom create method$/)
327
+ #TODO: dirty workaround to remove sql statement for `table` method
328
+ @logger.logged(:debug)[-2].should match(/^TestEmployee Create \(\d+\.\d+(ms)?\) custom create method$/)
329
329
  clear_logger
330
330
  end
331
331
 
@@ -359,7 +359,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
359
359
  :last_name => "Last",
360
360
  :hire_date => @today
361
361
  )
362
- @employee.save.should be_false
362
+ @employee.save.should be false
363
363
  @employee.errors[:first_name].should_not be_blank
364
364
  end
365
365
 
@@ -370,7 +370,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
370
370
  :hire_date => @today
371
371
  )
372
372
  @employee.first_name = nil
373
- @employee.save.should be_false
373
+ @employee.save.should be false
374
374
  @employee.errors[:first_name].should_not be_blank
375
375
  end
376
376