activerecord-oracle_enhanced-adapter 1.1.5 → 1.1.6
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.
Potentially problematic release.
This version of activerecord-oracle_enhanced-adapter might be problematic. Click here for more details.
- data/History.txt +10 -0
- data/README.txt +9 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +95 -17
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +123 -18
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +17 -8
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 1.1.6 2008-08-19
|
2
|
+
|
3
|
+
* Enhancements:
|
4
|
+
* Added support for set_date_columns and set_datetime_columns
|
5
|
+
* Added support for set_boolean_columns
|
6
|
+
* Added support for schema prefix in set_table_name (removed table name quoting)
|
7
|
+
* Added support for NVARCHAR2 column type
|
8
|
+
* Bug fixes:
|
9
|
+
* Do not call write_lobs callback when custom create or update methods are defined
|
10
|
+
|
1
11
|
== 1.1.5 2008-07-27
|
2
12
|
|
3
13
|
* Bug fixes:
|
data/README.txt
CHANGED
@@ -39,6 +39,15 @@ The following model class methods are available:
|
|
39
39
|
* specify which table columns should be ignored by ActiveRecord
|
40
40
|
ignore_table_columns :column1, :column2, :column3
|
41
41
|
|
42
|
+
* specify which table columns should be with :date type (without time) or with :datetime type (with date and time) - this could be used
|
43
|
+
if emulation by column names is not working because of different naming conventions
|
44
|
+
set_date_columns :started_on, :finished_on
|
45
|
+
set_datetime_columns :start_date_and_time, :end_date_and_time
|
46
|
+
|
47
|
+
* specify which table columns should be with :boolean type - this should be used together with boolean emulation from strings if
|
48
|
+
there are other boolean columns with different naming convention
|
49
|
+
set_boolean_columns :some_boolean_column
|
50
|
+
|
42
51
|
* specify custom create, update and delete methods which should be used instead of Rails generated INSERT, UPDATE and DELETE statements
|
43
52
|
# should return ID of new record
|
44
53
|
set_create_method do
|
@@ -57,11 +57,27 @@ begin
|
|
57
57
|
connection.ignore_table_columns(table_name,*args)
|
58
58
|
end
|
59
59
|
|
60
|
+
# RSI: specify which table columns should be treated as date (without time)
|
61
|
+
def self.set_date_columns(*args)
|
62
|
+
connection.set_type_for_columns(table_name,:date,*args)
|
63
|
+
end
|
64
|
+
|
65
|
+
# RSI: specify which table columns should be treated as datetime
|
66
|
+
def self.set_datetime_columns(*args)
|
67
|
+
connection.set_type_for_columns(table_name,:datetime,*args)
|
68
|
+
end
|
69
|
+
|
70
|
+
# RSI: specify which table columns should be treated as booleans
|
71
|
+
def self.set_boolean_columns(*args)
|
72
|
+
connection.set_type_for_columns(table_name,:boolean,*args)
|
73
|
+
end
|
74
|
+
|
60
75
|
# After setting large objects to empty, select the OCI8::LOB
|
61
76
|
# and write back the data.
|
62
77
|
after_save :enhanced_write_lobs
|
63
78
|
def enhanced_write_lobs #:nodoc:
|
64
|
-
if connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter)
|
79
|
+
if connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
|
80
|
+
!(self.class.custom_create_method || self.class.custom_update_method)
|
65
81
|
connection.write_lobs(self.class.table_name, self.class, attributes)
|
66
82
|
end
|
67
83
|
end
|
@@ -73,8 +89,15 @@ begin
|
|
73
89
|
module ConnectionAdapters #:nodoc:
|
74
90
|
class OracleEnhancedColumn < Column #:nodoc:
|
75
91
|
|
92
|
+
attr_reader :table_name, :forced_column_type
|
93
|
+
|
94
|
+
def initialize(name, default, sql_type = nil, null = true, table_name = nil, forced_column_type = nil)
|
95
|
+
@table_name = table_name
|
96
|
+
@forced_column_type = forced_column_type
|
97
|
+
super(name, default, sql_type, null)
|
98
|
+
end
|
99
|
+
|
76
100
|
def type_cast(value)
|
77
|
-
return value.to_date if type == :date && OracleEnhancedAdapter.emulate_dates_by_column_name && value.class == Time
|
78
101
|
return guess_date_or_time(value) if type == :datetime && OracleEnhancedAdapter.emulate_dates
|
79
102
|
super
|
80
103
|
end
|
@@ -88,29 +111,44 @@ begin
|
|
88
111
|
%w(true t 1 y +).include?(value.to_s.downcase)
|
89
112
|
end
|
90
113
|
end
|
114
|
+
|
115
|
+
# RSI: convert Time value to Date for :date columns
|
116
|
+
def self.string_to_date(string)
|
117
|
+
return string.to_date if string.is_a?(Time)
|
118
|
+
super
|
119
|
+
end
|
120
|
+
|
121
|
+
# RSI: convert Date value to Time for :datetime columns
|
122
|
+
def self.string_to_time(string)
|
123
|
+
return string.to_time if string.is_a?(Date) && !OracleEnhancedAdapter.emulate_dates
|
124
|
+
super
|
125
|
+
end
|
91
126
|
|
92
127
|
private
|
93
128
|
def simplified_type(field_type)
|
94
129
|
return :boolean if OracleEnhancedAdapter.emulate_booleans && field_type == 'NUMBER(1)'
|
95
130
|
return :boolean if OracleEnhancedAdapter.emulate_booleans_from_strings &&
|
96
|
-
|
131
|
+
(forced_column_type == :boolean ||
|
132
|
+
OracleEnhancedAdapter.is_boolean_column?(name, field_type, table_name))
|
133
|
+
|
97
134
|
case field_type
|
98
135
|
when /date/i
|
99
|
-
|
136
|
+
forced_column_type ||
|
137
|
+
(:date if OracleEnhancedAdapter.emulate_dates_by_column_name && OracleEnhancedAdapter.is_date_column?(name, table_name)) ||
|
100
138
|
:datetime
|
101
139
|
when /timestamp/i then :timestamp
|
102
140
|
when /time/i then :datetime
|
103
141
|
when /decimal|numeric|number/i
|
104
142
|
return :integer if extract_scale(field_type) == 0
|
105
143
|
# RSI: if column name is ID or ends with _ID
|
106
|
-
return :integer if OracleEnhancedAdapter.emulate_integers_by_column_name && OracleEnhancedAdapter.is_integer_column?(name)
|
144
|
+
return :integer if OracleEnhancedAdapter.emulate_integers_by_column_name && OracleEnhancedAdapter.is_integer_column?(name, table_name)
|
107
145
|
:decimal
|
108
146
|
else super
|
109
147
|
end
|
110
148
|
end
|
111
149
|
|
112
150
|
def guess_date_or_time(value)
|
113
|
-
(value.hour == 0 and value.min == 0 and value.sec == 0) ?
|
151
|
+
value.respond_to?(:hour) && (value.hour == 0 and value.min == 0 and value.sec == 0) ?
|
114
152
|
Date.new(value.year, value.month, value.day) : value
|
115
153
|
end
|
116
154
|
|
@@ -185,14 +223,25 @@ begin
|
|
185
223
|
# RSI: set to true if columns with DATE in their name should be emulated as date
|
186
224
|
@@emulate_dates_by_column_name = false
|
187
225
|
cattr_accessor :emulate_dates_by_column_name
|
188
|
-
def self.is_date_column?(name)
|
226
|
+
def self.is_date_column?(name, table_name = nil)
|
189
227
|
name =~ /(^|_)date(_|$)/i
|
190
228
|
end
|
229
|
+
# RSI: instance method uses at first check if column type defined at class level
|
230
|
+
def is_date_column?(name, table_name = nil)
|
231
|
+
case get_type_for_column(table_name, name)
|
232
|
+
when nil
|
233
|
+
self.class.is_date_column?(name, table_name)
|
234
|
+
when :date
|
235
|
+
true
|
236
|
+
else
|
237
|
+
false
|
238
|
+
end
|
239
|
+
end
|
191
240
|
|
192
241
|
# RSI: set to true if NUMBER columns with ID at the end of their name should be emulated as integers
|
193
242
|
@@emulate_integers_by_column_name = false
|
194
243
|
cattr_accessor :emulate_integers_by_column_name
|
195
|
-
def self.is_integer_column?(name)
|
244
|
+
def self.is_integer_column?(name, table_name = nil)
|
196
245
|
name =~ /(^|_)id$/i
|
197
246
|
end
|
198
247
|
|
@@ -200,7 +249,7 @@ begin
|
|
200
249
|
# should be emulated as booleans
|
201
250
|
@@emulate_booleans_from_strings = false
|
202
251
|
cattr_accessor :emulate_booleans_from_strings
|
203
|
-
def self.is_boolean_column?(name, field_type)
|
252
|
+
def self.is_boolean_column?(name, field_type, table_name = nil)
|
204
253
|
return true if ["CHAR(1)","VARCHAR2(1)"].include?(field_type)
|
205
254
|
field_type =~ /^VARCHAR2/ && (name =~ /_flag$/i || name =~ /_yn$/i)
|
206
255
|
end
|
@@ -260,6 +309,11 @@ begin
|
|
260
309
|
name.to_s =~ /[A-Z]/ ? "\"#{name}\"" : name
|
261
310
|
end
|
262
311
|
|
312
|
+
# abstract_adapter calls quote_column_name from quote_table_name, so prevent that
|
313
|
+
def quote_table_name(name)
|
314
|
+
name
|
315
|
+
end
|
316
|
+
|
263
317
|
def quote_string(s) #:nodoc:
|
264
318
|
s.gsub(/'/, "''")
|
265
319
|
end
|
@@ -471,11 +525,29 @@ begin
|
|
471
525
|
@ignore_table_columns[table_name]
|
472
526
|
end
|
473
527
|
|
528
|
+
# RSI: set explicit type for specified table columns
|
529
|
+
def set_type_for_columns(table_name, column_type, *args)
|
530
|
+
@table_column_type ||= {}
|
531
|
+
@table_column_type[table_name] ||= {}
|
532
|
+
args.each do |col|
|
533
|
+
@table_column_type[table_name][col.to_s.downcase] = column_type
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
def get_type_for_column(table_name, column_name)
|
538
|
+
result = @table_column_type && @table_column_type[table_name] && @table_column_type[table_name][column_name.to_s.downcase]
|
539
|
+
result
|
540
|
+
end
|
541
|
+
|
542
|
+
def clear_types_for_columns
|
543
|
+
@table_column_type = nil
|
544
|
+
end
|
545
|
+
|
474
546
|
def columns(table_name, name = nil) #:nodoc:
|
475
547
|
# RSI: get ignored_columns by original table name
|
476
548
|
ignored_columns = ignored_table_columns(table_name)
|
477
549
|
|
478
|
-
(owner,
|
550
|
+
(owner, desc_table_name) = @connection.describe(table_name)
|
479
551
|
|
480
552
|
table_cols = <<-SQL
|
481
553
|
select column_name as name, data_type as sql_type, data_default, nullable,
|
@@ -487,7 +559,7 @@ begin
|
|
487
559
|
decode(data_type, 'NUMBER', data_scale, null) as scale
|
488
560
|
from all_tab_columns
|
489
561
|
where owner = '#{owner}'
|
490
|
-
and table_name = '#{
|
562
|
+
and table_name = '#{desc_table_name}'
|
491
563
|
order by column_id
|
492
564
|
SQL
|
493
565
|
|
@@ -510,7 +582,11 @@ begin
|
|
510
582
|
OracleEnhancedColumn.new(oracle_downcase(row['name']),
|
511
583
|
row['data_default'],
|
512
584
|
row['sql_type'],
|
513
|
-
row['nullable'] == 'Y'
|
585
|
+
row['nullable'] == 'Y',
|
586
|
+
# RSI: pass table name for table specific column definitions
|
587
|
+
table_name,
|
588
|
+
# RSI: pass column type if specified in class definition
|
589
|
+
get_type_for_column(table_name, oracle_downcase(row['name'])))
|
514
590
|
end
|
515
591
|
end
|
516
592
|
|
@@ -582,7 +658,7 @@ begin
|
|
582
658
|
select_all("select table_name from all_tables where owner = sys_context('userenv','session_user')").inject(s) do |structure, table|
|
583
659
|
ddl = "create table #{table.to_a.first.last} (\n "
|
584
660
|
cols = select_all(%Q{
|
585
|
-
select column_name, data_type, data_length, data_precision, data_scale, data_default, nullable
|
661
|
+
select column_name, data_type, data_length, char_used, char_length, data_precision, data_scale, data_default, nullable
|
586
662
|
from user_tab_columns
|
587
663
|
where table_name = '#{table.to_a.first.last}'
|
588
664
|
order by column_id
|
@@ -593,7 +669,8 @@ begin
|
|
593
669
|
col << ",#{row['data_scale'].to_i}" if !row['data_scale'].nil?
|
594
670
|
col << ')'
|
595
671
|
elsif row['data_type'].include?('CHAR')
|
596
|
-
|
672
|
+
length = row['char_used'] == 'C' ? row['char_length'].to_i : row['data_length'].to_i
|
673
|
+
col << "(#{length})"
|
597
674
|
end
|
598
675
|
col << " default #{row['data_default']}" if !row['data_default'].nil?
|
599
676
|
col << ' not null' if row['nullable'] == 'N'
|
@@ -678,9 +755,10 @@ begin
|
|
678
755
|
when OraDate
|
679
756
|
d = row[i]
|
680
757
|
# RSI: added emulate_dates_by_column_name functionality
|
681
|
-
if emulate_dates_by_column_name && self.class.is_date_column?(col)
|
682
|
-
|
683
|
-
elsif
|
758
|
+
# if emulate_dates_by_column_name && self.class.is_date_column?(col)
|
759
|
+
# d.to_date
|
760
|
+
# elsif
|
761
|
+
if emulate_dates && (d.hour == 0 && d.minute == 0 && d.second == 0)
|
684
762
|
d.to_date
|
685
763
|
else
|
686
764
|
# see string_to_time; Time overflowing to DateTime, respecting the default timezone
|
@@ -24,7 +24,6 @@ module ActiveRecord #:nodoc:
|
|
24
24
|
private
|
25
25
|
def include_with_custom_methods
|
26
26
|
unless included_modules.include? InstanceMethods
|
27
|
-
class_inheritable_accessor :custom_create_method, :custom_update_method, :custom_delete_method
|
28
27
|
include InstanceMethods
|
29
28
|
end
|
30
29
|
end
|
@@ -96,6 +95,7 @@ end
|
|
96
95
|
|
97
96
|
ActiveRecord::Base.class_eval do
|
98
97
|
extend ActiveRecord::ConnectionAdapters::OracleEnhancedProcedures::ClassMethods
|
98
|
+
class_inheritable_accessor :custom_create_method, :custom_update_method, :custom_delete_method
|
99
99
|
end
|
100
100
|
|
101
101
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
|
@@ -52,7 +52,43 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
52
52
|
it "should return the same structure drop as original oracle adapter" do
|
53
53
|
@new_conn.structure_drop.should == @old_conn.structure_drop
|
54
54
|
end
|
55
|
+
|
56
|
+
it "should return the character size of nvarchar fields" do
|
57
|
+
@new_conn.execute <<-SQL
|
58
|
+
CREATE TABLE nvarchartable (
|
59
|
+
session_id NVARCHAR2(255) DEFAULT NULL
|
60
|
+
)
|
61
|
+
SQL
|
62
|
+
if /.*session_id nvarchar2\((\d+)\).*/ =~ @new_conn.structure_dump
|
63
|
+
"#$1".should == "255"
|
64
|
+
end
|
65
|
+
@new_conn.execute "DROP TABLE nvarchartable"
|
66
|
+
end
|
67
|
+
end
|
55
68
|
|
69
|
+
describe "OracleEnhancedAdapter database stucture dump extentions" do
|
70
|
+
before(:all) do
|
71
|
+
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced",
|
72
|
+
:database => "xe",
|
73
|
+
:username => "hr",
|
74
|
+
:password => "hr")
|
75
|
+
@conn = ActiveRecord::Base.connection
|
76
|
+
@conn.execute <<-SQL
|
77
|
+
CREATE TABLE nvarchartable (
|
78
|
+
unq_nvarchar NVARCHAR2(255) DEFAULT NULL
|
79
|
+
)
|
80
|
+
SQL
|
81
|
+
end
|
82
|
+
|
83
|
+
after(:all) do
|
84
|
+
@conn.execute "DROP TABLE nvarchartable"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return the character size of nvarchar fields" do
|
88
|
+
if /.*unq_nvarchar nvarchar2\((\d+)\).*/ =~ @conn.structure_dump
|
89
|
+
"#$1".should == "255"
|
90
|
+
end
|
91
|
+
end
|
56
92
|
end
|
57
93
|
|
58
94
|
describe "OracleEnhancedAdapter database session store" do
|
@@ -200,36 +236,79 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
200
236
|
end
|
201
237
|
|
202
238
|
describe "/ DATE values from ActiveRecord model" do
|
203
|
-
before(:
|
239
|
+
before(:each) do
|
240
|
+
ActiveRecord::Base.connection.clear_types_for_columns
|
241
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
242
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
|
204
243
|
class TestEmployee < ActiveRecord::Base
|
244
|
+
set_table_name "hr.test_employees"
|
205
245
|
set_primary_key :employee_id
|
206
246
|
end
|
207
247
|
end
|
208
|
-
|
209
|
-
|
248
|
+
|
249
|
+
def create_test_employee
|
250
|
+
@today = Date.new(2008,8,19)
|
251
|
+
@now = Time.local(2008,8,19,17,03,59)
|
210
252
|
@employee = TestEmployee.create(
|
211
253
|
:first_name => "First",
|
212
254
|
:last_name => "Last",
|
213
|
-
:hire_date =>
|
214
|
-
:created_at =>
|
255
|
+
:hire_date => @today,
|
256
|
+
:created_at => @now
|
215
257
|
)
|
258
|
+
@employee.reload
|
259
|
+
end
|
260
|
+
|
261
|
+
after(:each) do
|
262
|
+
# @employee.destroy if @employee
|
263
|
+
Object.send(:remove_const, "TestEmployee")
|
216
264
|
end
|
217
265
|
|
218
266
|
it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
|
219
267
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
220
|
-
|
268
|
+
create_test_employee
|
221
269
|
@employee.hire_date.class.should == Time
|
222
270
|
end
|
223
271
|
|
224
272
|
it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
225
273
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
226
|
-
|
274
|
+
create_test_employee
|
227
275
|
@employee.hire_date.class.should == Date
|
228
276
|
end
|
229
277
|
|
230
278
|
it "should return Time value from DATE column if column name does not contain 'date' and emulate_dates_by_column_name is true" do
|
231
279
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
280
|
+
create_test_employee
|
281
|
+
@employee.created_at.class.should == Time
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should return Date value from DATE column if emulate_dates_by_column_name is false but column is defined as date" do
|
285
|
+
class TestEmployee < ActiveRecord::Base
|
286
|
+
set_date_columns :hire_date
|
287
|
+
end
|
288
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
289
|
+
create_test_employee
|
290
|
+
@employee.hire_date.class.should == Date
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should return Time value from DATE column if emulate_dates_by_column_name is true but column is defined as datetime" do
|
294
|
+
class TestEmployee < ActiveRecord::Base
|
295
|
+
set_datetime_columns :hire_date
|
296
|
+
end
|
297
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
298
|
+
create_test_employee
|
299
|
+
@employee.hire_date.class.should == Time
|
300
|
+
# change to current time with hours, minutes and seconds
|
301
|
+
@employee.hire_date = @now
|
302
|
+
@employee.save!
|
232
303
|
@employee.reload
|
304
|
+
@employee.hire_date.class.should == Time
|
305
|
+
@employee.hire_date.should == @now
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should guess Date or Time value if emulate_dates is true" do
|
309
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = true
|
310
|
+
create_test_employee
|
311
|
+
@employee.hire_date.class.should == Date
|
233
312
|
@employee.created_at.class.should == Time
|
234
313
|
end
|
235
314
|
|
@@ -374,7 +453,8 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
374
453
|
has_email CHAR(1),
|
375
454
|
has_phone VARCHAR2(1),
|
376
455
|
active_flag VARCHAR2(2),
|
377
|
-
manager_yn VARCHAR2(3)
|
456
|
+
manager_yn VARCHAR2(3),
|
457
|
+
test_boolean VARCHAR2(3)
|
378
458
|
)
|
379
459
|
SQL
|
380
460
|
@conn.execute <<-SQL
|
@@ -436,6 +516,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
436
516
|
|
437
517
|
describe "/ VARCHAR2 boolean values from ActiveRecord model" do
|
438
518
|
before(:each) do
|
519
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
439
520
|
class Test3Employee < ActiveRecord::Base
|
440
521
|
end
|
441
522
|
end
|
@@ -444,14 +525,16 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
444
525
|
Object.send(:remove_const, "Test3Employee")
|
445
526
|
end
|
446
527
|
|
447
|
-
def create_employee3
|
528
|
+
def create_employee3(params={})
|
448
529
|
@employee3 = Test3Employee.create(
|
530
|
+
{
|
449
531
|
:first_name => "First",
|
450
532
|
:last_name => "Last",
|
451
533
|
:has_email => true,
|
452
534
|
:has_phone => false,
|
453
535
|
:active_flag => true,
|
454
536
|
:manager_yn => false
|
537
|
+
}.merge(params)
|
455
538
|
)
|
456
539
|
@employee3.reload
|
457
540
|
end
|
@@ -482,6 +565,19 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
482
565
|
create_employee3
|
483
566
|
@employee3.first_name.class.should == String
|
484
567
|
end
|
568
|
+
|
569
|
+
it "should return boolean value from VARCHAR2 boolean column if column specified in set_boolean_columns" do
|
570
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
571
|
+
class Test3Employee < ActiveRecord::Base
|
572
|
+
set_boolean_columns :test_boolean
|
573
|
+
end
|
574
|
+
create_employee3(:test_boolean => true)
|
575
|
+
@employee3.test_boolean.class.should == TrueClass
|
576
|
+
@employee3.test_boolean_before_type_cast.should == "Y"
|
577
|
+
create_employee3(:test_boolean => false)
|
578
|
+
@employee3.test_boolean.class.should == FalseClass
|
579
|
+
@employee3.test_boolean_before_type_cast.should == "N"
|
580
|
+
end
|
485
581
|
|
486
582
|
end
|
487
583
|
|
@@ -668,9 +764,6 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
|
|
668
764
|
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
669
765
|
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
670
766
|
SQL
|
671
|
-
class TestEmployee < ActiveRecord::Base
|
672
|
-
set_primary_key :employee_id
|
673
|
-
end
|
674
767
|
# @conn.execute %q{alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'}
|
675
768
|
@conn.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
|
676
769
|
# @conn.execute %q{alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'}
|
@@ -678,14 +771,25 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
|
|
678
771
|
end
|
679
772
|
|
680
773
|
after(:all) do
|
681
|
-
Object.send(:remove_const, "TestEmployee")
|
682
774
|
@conn.execute "DROP TABLE test_employees"
|
683
775
|
@conn.execute "DROP SEQUENCE test_employees_seq"
|
684
776
|
end
|
685
777
|
|
686
778
|
before(:each) do
|
779
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
|
780
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
781
|
+
class TestEmployee < ActiveRecord::Base
|
782
|
+
set_primary_key :employee_id
|
783
|
+
end
|
687
784
|
@today = Date.new(2008,6,28)
|
688
785
|
@now = Time.local(2008,6,28,13,34,33)
|
786
|
+
end
|
787
|
+
|
788
|
+
after(:each) do
|
789
|
+
Object.send(:remove_const, "TestEmployee")
|
790
|
+
end
|
791
|
+
|
792
|
+
def create_test_employee
|
689
793
|
@employee = TestEmployee.create(
|
690
794
|
:first_name => "First",
|
691
795
|
:last_name => "Last",
|
@@ -693,31 +797,32 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
|
|
693
797
|
:created_at => @now,
|
694
798
|
:created_at_ts => @now
|
695
799
|
)
|
800
|
+
@employee.reload
|
696
801
|
end
|
697
802
|
|
698
803
|
it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
|
699
804
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
700
|
-
|
805
|
+
create_test_employee
|
701
806
|
@employee.hire_date.class.should == Time
|
702
807
|
@employee.hire_date.should == @today.to_time
|
703
808
|
end
|
704
809
|
|
705
810
|
it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
706
811
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
707
|
-
|
812
|
+
create_test_employee
|
708
813
|
@employee.hire_date.class.should == Date
|
709
814
|
@employee.hire_date.should == @today
|
710
815
|
end
|
711
816
|
|
712
817
|
it "should return Time value from DATE column if column name does not contain 'date' and emulate_dates_by_column_name is true" do
|
713
818
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
714
|
-
|
819
|
+
create_test_employee
|
715
820
|
@employee.created_at.class.should == Time
|
716
821
|
@employee.created_at.should == @now
|
717
822
|
end
|
718
823
|
|
719
824
|
it "should return Time value from TIMESTAMP columns" do
|
720
|
-
|
825
|
+
create_test_employee
|
721
826
|
@employee.created_at_ts.class.should == Time
|
722
827
|
@employee.created_at_ts.should == @now
|
723
828
|
end
|
@@ -870,4 +975,4 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
870
975
|
@employee.last_login_at.should == @today.to_time
|
871
976
|
end
|
872
977
|
|
873
|
-
end
|
978
|
+
end
|
@@ -23,6 +23,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
23
23
|
last_name VARCHAR2(25),
|
24
24
|
hire_date DATE,
|
25
25
|
salary NUMBER(8,2),
|
26
|
+
description CLOB,
|
26
27
|
version NUMBER(15,0),
|
27
28
|
create_time DATE,
|
28
29
|
update_time DATE
|
@@ -40,13 +41,15 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
40
41
|
p_last_name VARCHAR2,
|
41
42
|
p_hire_date DATE,
|
42
43
|
p_salary NUMBER,
|
44
|
+
p_description VARCHAR2,
|
43
45
|
p_employee_id OUT NUMBER);
|
44
46
|
PROCEDURE update_employee(
|
45
47
|
p_employee_id NUMBER,
|
46
48
|
p_first_name VARCHAR2,
|
47
49
|
p_last_name VARCHAR2,
|
48
50
|
p_hire_date DATE,
|
49
|
-
p_salary NUMBER
|
51
|
+
p_salary NUMBER,
|
52
|
+
p_description VARCHAR2);
|
50
53
|
PROCEDURE delete_employee(
|
51
54
|
p_employee_id NUMBER);
|
52
55
|
END;
|
@@ -58,13 +61,14 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
58
61
|
p_last_name VARCHAR2,
|
59
62
|
p_hire_date DATE,
|
60
63
|
p_salary NUMBER,
|
64
|
+
p_description VARCHAR2,
|
61
65
|
p_employee_id OUT NUMBER)
|
62
66
|
IS
|
63
67
|
BEGIN
|
64
68
|
SELECT test_employees_s.NEXTVAL INTO p_employee_id FROM dual;
|
65
|
-
INSERT INTO test_employees (employee_id, first_name, last_name, hire_date, salary,
|
69
|
+
INSERT INTO test_employees (employee_id, first_name, last_name, hire_date, salary, description,
|
66
70
|
version, create_time, update_time)
|
67
|
-
VALUES (p_employee_id, p_first_name, p_last_name, p_hire_date, p_salary,
|
71
|
+
VALUES (p_employee_id, p_first_name, p_last_name, p_hire_date, p_salary, p_description,
|
68
72
|
1, SYSDATE, SYSDATE);
|
69
73
|
END create_employee;
|
70
74
|
|
@@ -73,14 +77,15 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
73
77
|
p_first_name VARCHAR2,
|
74
78
|
p_last_name VARCHAR2,
|
75
79
|
p_hire_date DATE,
|
76
|
-
p_salary NUMBER
|
80
|
+
p_salary NUMBER,
|
81
|
+
p_description VARCHAR2)
|
77
82
|
IS
|
78
83
|
v_version NUMBER;
|
79
84
|
BEGIN
|
80
85
|
SELECT version INTO v_version FROM test_employees WHERE employee_id = p_employee_id FOR UPDATE;
|
81
86
|
UPDATE test_employees
|
82
87
|
SET employee_id = p_employee_id, first_name = p_first_name, last_name = p_last_name,
|
83
|
-
hire_date = p_hire_date, salary = p_salary,
|
88
|
+
hire_date = p_hire_date, salary = p_salary, description = p_description,
|
84
89
|
version = v_version + 1, update_time = SYSDATE;
|
85
90
|
END update_employee;
|
86
91
|
|
@@ -107,6 +112,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
107
112
|
:p_last_name => last_name,
|
108
113
|
:p_hire_date => hire_date,
|
109
114
|
:p_salary => salary,
|
115
|
+
:p_description => "#{first_name} #{last_name}",
|
110
116
|
:p_employee_id => nil
|
111
117
|
)[:p_employee_id]
|
112
118
|
end
|
@@ -118,7 +124,8 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
118
124
|
:p_first_name => first_name,
|
119
125
|
:p_last_name => last_name,
|
120
126
|
:p_hire_date => hire_date,
|
121
|
-
:p_salary => salary
|
127
|
+
:p_salary => salary,
|
128
|
+
:p_description => "#{first_name} #{last_name}"
|
122
129
|
)
|
123
130
|
end
|
124
131
|
|
@@ -154,6 +161,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
154
161
|
@employee.first_name.should == "First"
|
155
162
|
@employee.last_name.should == "Last"
|
156
163
|
@employee.hire_date.should == @today
|
164
|
+
@employee.description.should == "First Last"
|
157
165
|
@employee.create_time.should_not be_nil
|
158
166
|
@employee.update_time.should_not be_nil
|
159
167
|
end
|
@@ -162,13 +170,14 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
|
|
162
170
|
@employee = TestEmployee.create(
|
163
171
|
:first_name => "First",
|
164
172
|
:last_name => "Last",
|
165
|
-
:hire_date => @today
|
173
|
+
:hire_date => @today,
|
174
|
+
:description => "description"
|
166
175
|
)
|
167
176
|
@employee.reload
|
168
177
|
@employee.first_name = "Second"
|
169
178
|
@employee.save!
|
170
179
|
@employee.reload
|
171
|
-
@employee.
|
180
|
+
@employee.description.should == "Second Last"
|
172
181
|
end
|
173
182
|
|
174
183
|
it "should not update record if nothing is changed and partial updates are enabled" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-oracle_enhanced-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raimonds Simanovskis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-19 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|