c3-activerecord-oracle_enhanced-adapter 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/History.txt +182 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +32 -0
  4. data/README.rdoc +77 -0
  5. data/Rakefile +49 -0
  6. data/VERSION +1 -0
  7. data/activerecord-oracle_enhanced-adapter.gemspec +79 -0
  8. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +5 -0
  9. data/lib/active_record/connection_adapters/oracle_enhanced.rake +51 -0
  10. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +1664 -0
  11. data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +121 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +64 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +21 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +39 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +393 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +389 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +163 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced_reserved_words.rb +126 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +168 -0
  20. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +213 -0
  21. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +224 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +11 -0
  23. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -0
  24. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +477 -0
  25. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_structure_dumper_spec.rb +267 -0
  26. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +206 -0
  27. data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +40 -0
  28. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +107 -0
  29. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +984 -0
  30. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +67 -0
  31. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +93 -0
  32. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +25 -0
  33. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +370 -0
  34. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +218 -0
  35. data/spec/active_record/connection_adapters/oracle_enhanced_schema_spec.rb +784 -0
  36. data/spec/spec.opts +6 -0
  37. data/spec/spec_helper.rb +114 -0
  38. metadata +137 -0
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
+
5
+ describe "OracleEnhancedAdapter to_d method" do
6
+ it "BigDecimal#to_d returns the same decimal number" do
7
+ d = BigDecimal.new("12345678901234567890.0123456789")
8
+ d.to_d.should == d
9
+ end
10
+
11
+ it "Bignum#to_d translates large integer to decimal" do
12
+ n = 12345678901234567890
13
+ n.to_d.should == BigDecimal.new(n.to_s)
14
+ end
15
+
16
+ it "Fixnum#to_d translates small integer to decimal" do
17
+ n = 123456
18
+ n.to_d.should == BigDecimal.new(n.to_s)
19
+ end
20
+ end
21
+
22
+ if ENV['RAILS_GEM_VERSION'] >= '2.3'
23
+
24
+ describe "OracleEnhancedAdapter Unicode aware upcase and downcase" do
25
+ before(:all) do
26
+ @down = "āčēģīķļņšūž"
27
+ @up = "ĀČĒĢĪĶĻŅŠŪŽ"
28
+ end
29
+
30
+ it "should translate Unicode string to upcase" do
31
+ @down.mb_chars.upcase.to_s.should == @up
32
+ end
33
+
34
+ it "should translate Unicode string to downcase" do
35
+ @up.mb_chars.downcase.to_s.should == @down
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,107 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ unless defined?(NO_COMPOSITE_PRIMARY_KEYS)
4
+
5
+ describe "OracleEnhancedAdapter composite_primary_keys support" do
6
+
7
+ before(:all) do
8
+ if defined?(::ActiveRecord::ConnectionAdapters::OracleAdapter)
9
+ @old_oracle_adapter = ::ActiveRecord::ConnectionAdapters::OracleAdapter
10
+ ::ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
11
+ end
12
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
13
+ if $cpk_oracle_adapter
14
+ ::ActiveRecord::ConnectionAdapters::OracleAdapter = $cpk_oracle_adapter
15
+ $cpk_oracle_adapter = nil
16
+ end
17
+ require 'composite_primary_keys'
18
+ end
19
+
20
+ after(:all) do
21
+ # Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
22
+ if defined?(::ActiveRecord::ConnectionAdapters::OracleAdapter)
23
+ $cpk_oracle_adapter = ::ActiveRecord::ConnectionAdapters::OracleAdapter
24
+ ::ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
25
+ end
26
+ if @old_oracle_adapter
27
+ ::ActiveRecord::ConnectionAdapters::OracleAdapter = @old_oracle_adapter
28
+ @old_oracle_adapter = nil
29
+ end
30
+ end
31
+
32
+ describe "do not use count distinct" do
33
+ before(:all) do
34
+ class ::JobHistory < ActiveRecord::Base
35
+ set_table_name "job_history"
36
+ set_primary_keys :employee_id, :start_date
37
+ end
38
+ end
39
+
40
+ after(:all) do
41
+ Object.send(:remove_const, 'JobHistory') if defined?(JobHistory)
42
+ end
43
+
44
+ it "should tell ActiveRecord that count distinct is not supported" do
45
+ ActiveRecord::Base.connection.supports_count_distinct?.should be_false
46
+ end
47
+
48
+ it "should execute correct SQL COUNT DISTINCT statement on table with composite primary keys" do
49
+ lambda { JobHistory.count(:distinct => true) }.should_not raise_error
50
+ end
51
+ end
52
+
53
+ describe "table with LOB" do
54
+ before(:all) do
55
+ ActiveRecord::Schema.define do
56
+ suppress_messages do
57
+ create_table :cpk_write_lobs_test, :primary_key => [:type_category, :date_value], :force => true do |t|
58
+ t.string :type_category, :limit => 15, :null => false
59
+ t.date :date_value, :null => false
60
+ t.text :results, :null => false
61
+ t.timestamps
62
+ end
63
+ create_table :non_cpk_write_lobs_test, :force => true do |t|
64
+ t.date :date_value, :null => false
65
+ t.text :results, :null => false
66
+ t.timestamps
67
+ end
68
+ end
69
+ end
70
+ class ::CpkWriteLobsTest < ActiveRecord::Base
71
+ set_table_name 'cpk_write_lobs_test'
72
+ set_primary_keys :type_category, :date_value
73
+ end
74
+ class ::NonCpkWriteLobsTest < ActiveRecord::Base
75
+ set_table_name 'non_cpk_write_lobs_test'
76
+ end
77
+ end
78
+
79
+ after(:all) do
80
+ ActiveRecord::Schema.define do
81
+ suppress_messages do
82
+ drop_table :cpk_write_lobs_test
83
+ drop_table :non_cpk_write_lobs_test
84
+ end
85
+ end
86
+ Object.send(:remove_const, "CpkWriteLobsTest")
87
+ Object.send(:remove_const, "NonCpkWriteLobsTest")
88
+ end
89
+
90
+ it "should create new record in table with CPK and LOB" do
91
+ lambda {
92
+ CpkWriteLobsTest.create(:type_category => 'AAA', :date_value => Date.today, :results => 'DATA '*10)
93
+ }.should_not raise_error
94
+ end
95
+
96
+ it "should create new record in table without CPK and with LOB" do
97
+ lambda {
98
+ NonCpkWriteLobsTest.create(:date_value => Date.today, :results => 'DATA '*10)
99
+ }.should_not raise_error
100
+ end
101
+ end
102
+
103
+ # Other testing was done based on composite_primary_keys tests
104
+
105
+ end
106
+
107
+ end
@@ -0,0 +1,984 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "OracleEnhancedAdapter date type detection based on column names" do
4
+ before(:all) do
5
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
6
+ @conn = ActiveRecord::Base.connection
7
+ @conn.execute <<-SQL
8
+ CREATE TABLE test_employees (
9
+ employee_id NUMBER(6,0),
10
+ first_name VARCHAR2(20),
11
+ last_name VARCHAR2(25),
12
+ email VARCHAR2(25),
13
+ phone_number VARCHAR2(20),
14
+ hire_date DATE,
15
+ job_id NUMBER(6,0),
16
+ salary NUMBER(8,2),
17
+ commission_pct NUMBER(2,2),
18
+ manager_id NUMBER(6,0),
19
+ department_id NUMBER(4,0),
20
+ created_at DATE,
21
+ updated_at DATE
22
+ )
23
+ SQL
24
+ @conn.execute <<-SQL
25
+ CREATE SEQUENCE test_employees_seq MINVALUE 1
26
+ INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
27
+ SQL
28
+ end
29
+
30
+ after(:all) do
31
+ @conn.execute "DROP TABLE test_employees"
32
+ @conn.execute "DROP SEQUENCE test_employees_seq"
33
+ end
34
+
35
+ it "should set DATE column type as datetime if emulate_dates_by_column_name is false" do
36
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
37
+ columns = @conn.columns('test_employees')
38
+ column = columns.detect{|c| c.name == "hire_date"}
39
+ column.type.should == :datetime
40
+ end
41
+
42
+ it "should set DATE column type as date if column name contains '_date_' and emulate_dates_by_column_name is true" do
43
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
44
+ columns = @conn.columns('test_employees')
45
+ column = columns.detect{|c| c.name == "hire_date"}
46
+ column.type.should == :date
47
+ end
48
+
49
+ it "should set DATE column type as datetime if column name does not contain '_date_' and emulate_dates_by_column_name is true" do
50
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
51
+ columns = @conn.columns('test_employees')
52
+ column = columns.detect{|c| c.name == "created_at"}
53
+ column.type.should == :datetime
54
+ end
55
+
56
+ it "should set DATE column type as datetime if column name contains 'date' as part of other word and emulate_dates_by_column_name is true" do
57
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
58
+ columns = @conn.columns('test_employees')
59
+ column = columns.detect{|c| c.name == "updated_at"}
60
+ column.type.should == :datetime
61
+ end
62
+
63
+ it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
64
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
65
+ columns = @conn.columns('test_employees')
66
+ column = columns.detect{|c| c.name == "hire_date"}
67
+ column.type_cast(Time.now).class.should == Time
68
+ end
69
+
70
+ it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
71
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
72
+ columns = @conn.columns('test_employees')
73
+ column = columns.detect{|c| c.name == "hire_date"}
74
+ column.type_cast(Time.now).class.should == Date
75
+ end
76
+
77
+ 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
78
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
79
+ columns = @conn.columns('test_employees')
80
+ column = columns.detect{|c| c.name == "hire_date"}
81
+ column.type_cast(DateTime.new(1900,1,1)).class.should == Date
82
+ end
83
+
84
+ describe "/ DATE values from ActiveRecord model" do
85
+ before(:each) do
86
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
87
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
88
+ class ::TestEmployee < ActiveRecord::Base
89
+ set_primary_key :employee_id
90
+ end
91
+ end
92
+
93
+ def create_test_employee(params={})
94
+ @today = params[:today] || Date.new(2008,8,19)
95
+ @now = params[:now] || Time.local(2008,8,19,17,03,59)
96
+ @employee = TestEmployee.create(
97
+ :first_name => "First",
98
+ :last_name => "Last",
99
+ :hire_date => @today,
100
+ :created_at => @now
101
+ )
102
+ @employee.reload
103
+ end
104
+
105
+ after(:each) do
106
+ # @employee.destroy if @employee
107
+ Object.send(:remove_const, "TestEmployee")
108
+ @conn.clear_types_for_columns
109
+ end
110
+
111
+ it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
112
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
113
+ create_test_employee
114
+ @employee.hire_date.class.should == Time
115
+ end
116
+
117
+ it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
118
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
119
+ create_test_employee
120
+ @employee.hire_date.class.should == Date
121
+ end
122
+
123
+ it "should return Date value from DATE column with old date value if column name contains 'date' and emulate_dates_by_column_name is true" do
124
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
125
+ create_test_employee(:today => Date.new(1900,1,1))
126
+ @employee.hire_date.class.should == Date
127
+ end
128
+
129
+ it "should return Time value from DATE column if column name does not contain 'date' and emulate_dates_by_column_name is true" do
130
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
131
+ create_test_employee
132
+ @employee.created_at.class.should == Time
133
+ end
134
+
135
+ it "should return Date value from DATE column if emulate_dates_by_column_name is false but column is defined as date" do
136
+ class ::TestEmployee < ActiveRecord::Base
137
+ set_date_columns :hire_date
138
+ end
139
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
140
+ create_test_employee
141
+ @employee.hire_date.class.should == Date
142
+ end
143
+
144
+ it "should return Date value from DATE column with old date value if emulate_dates_by_column_name is false but column is defined as date" do
145
+ class ::TestEmployee < ActiveRecord::Base
146
+ set_date_columns :hire_date
147
+ end
148
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
149
+ create_test_employee(:today => Date.new(1900,1,1))
150
+ @employee.hire_date.class.should == Date
151
+ end
152
+
153
+ it "should see set_date_columns values in different connection" do
154
+ class ::TestEmployee < ActiveRecord::Base
155
+ set_date_columns :hire_date
156
+ end
157
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
158
+ # establish other connection
159
+ other_conn = ActiveRecord::Base.oracle_enhanced_connection(CONNECTION_PARAMS)
160
+ other_conn.get_type_for_column('test_employees', 'hire_date').should == :date
161
+ end
162
+
163
+ it "should return Time value from DATE column if emulate_dates_by_column_name is true but column is defined as datetime" do
164
+ class ::TestEmployee < ActiveRecord::Base
165
+ set_datetime_columns :hire_date
166
+ end
167
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
168
+ create_test_employee
169
+ @employee.hire_date.class.should == Time
170
+ # change to current time with hours, minutes and seconds
171
+ @employee.hire_date = @now
172
+ @employee.save!
173
+ @employee.reload
174
+ @employee.hire_date.class.should == Time
175
+ @employee.hire_date.should == @now
176
+ end
177
+
178
+ it "should guess Date or Time value if emulate_dates is true" do
179
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = true
180
+ create_test_employee
181
+ @employee.hire_date.class.should == Date
182
+ @employee.created_at.class.should == Time
183
+ end
184
+
185
+ end
186
+
187
+ end
188
+
189
+ describe "OracleEnhancedAdapter integer type detection based on column names" do
190
+ before(:all) do
191
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
192
+ @conn = ActiveRecord::Base.connection
193
+ @conn.execute <<-SQL
194
+ CREATE TABLE test2_employees (
195
+ id NUMBER,
196
+ first_name VARCHAR2(20),
197
+ last_name VARCHAR2(25),
198
+ email VARCHAR2(25),
199
+ phone_number VARCHAR2(20),
200
+ hire_date DATE,
201
+ job_id NUMBER,
202
+ salary NUMBER,
203
+ commission_pct NUMBER(2,2),
204
+ manager_id NUMBER(6),
205
+ is_manager NUMBER(1),
206
+ department_id NUMBER(4,0),
207
+ created_at DATE
208
+ )
209
+ SQL
210
+ @conn.execute <<-SQL
211
+ CREATE SEQUENCE test2_employees_seq MINVALUE 1
212
+ INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
213
+ SQL
214
+ end
215
+
216
+ after(:all) do
217
+ @conn.execute "DROP TABLE test2_employees"
218
+ @conn.execute "DROP SEQUENCE test2_employees_seq"
219
+ end
220
+
221
+ it "should set NUMBER column type as decimal if emulate_integers_by_column_name is false" do
222
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
223
+ columns = @conn.columns('test2_employees')
224
+ column = columns.detect{|c| c.name == "job_id"}
225
+ column.type.should == :decimal
226
+ end
227
+
228
+ it "should set NUMBER column type as integer if emulate_integers_by_column_name is true" do
229
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
230
+ columns = @conn.columns('test2_employees')
231
+ column = columns.detect{|c| c.name == "job_id"}
232
+ column.type.should == :integer
233
+ column = columns.detect{|c| c.name == "id"}
234
+ column.type.should == :integer
235
+ end
236
+
237
+ it "should set NUMBER column type as decimal if column name does not contain 'id' and emulate_integers_by_column_name is true" do
238
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
239
+ columns = @conn.columns('test2_employees')
240
+ column = columns.detect{|c| c.name == "salary"}
241
+ column.type.should == :decimal
242
+ end
243
+
244
+ it "should return BigDecimal value from NUMBER column if emulate_integers_by_column_name is false" do
245
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
246
+ columns = @conn.columns('test2_employees')
247
+ column = columns.detect{|c| c.name == "job_id"}
248
+ column.type_cast(1.0).class.should == BigDecimal
249
+ end
250
+
251
+ it "should return Fixnum value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
252
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
253
+ columns = @conn.columns('test2_employees')
254
+ column = columns.detect{|c| c.name == "job_id"}
255
+ column.type_cast(1.0).class.should == Fixnum
256
+ end
257
+
258
+ describe "/ NUMBER values from ActiveRecord model" do
259
+ before(:each) do
260
+ class ::Test2Employee < ActiveRecord::Base
261
+ end
262
+ end
263
+
264
+ after(:each) do
265
+ Object.send(:remove_const, "Test2Employee")
266
+ @conn.clear_types_for_columns
267
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
268
+ end
269
+
270
+ def create_employee2
271
+ @employee2 = Test2Employee.create(
272
+ :first_name => "First",
273
+ :last_name => "Last",
274
+ :job_id => 1,
275
+ :is_manager => 1,
276
+ :salary => 1000
277
+ )
278
+ @employee2.reload
279
+ end
280
+
281
+ it "should return BigDecimal value from NUMBER column if emulate_integers_by_column_name is false" do
282
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
283
+ create_employee2
284
+ @employee2.job_id.class.should == BigDecimal
285
+ end
286
+
287
+ it "should return Fixnum value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
288
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
289
+ create_employee2
290
+ @employee2.job_id.class.should == Fixnum
291
+ end
292
+
293
+ it "should return Fixnum value from NUMBER column with integer value using _before_type_cast method" do
294
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
295
+ create_employee2
296
+ @employee2.job_id_before_type_cast.class.should == Fixnum
297
+ end
298
+
299
+ it "should return BigDecimal value from NUMBER column if column name does not contain 'id' and emulate_integers_by_column_name is true" do
300
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
301
+ create_employee2
302
+ @employee2.salary.class.should == BigDecimal
303
+ end
304
+
305
+ it "should return Fixnum value from NUMBER column if column specified in set_integer_columns" do
306
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
307
+ Test2Employee.set_integer_columns :job_id
308
+ create_employee2
309
+ @employee2.job_id.class.should == Fixnum
310
+ end
311
+
312
+ it "should return Boolean value from NUMBER(1) column if emulate booleans is used" do
313
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
314
+ create_employee2
315
+ @employee2.is_manager.class.should == TrueClass
316
+ end
317
+
318
+ it "should return Fixnum value from NUMBER(1) column if emulate booleans is not used" do
319
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = false
320
+ create_employee2
321
+ @employee2.is_manager.class.should == Fixnum
322
+ end
323
+
324
+ it "should return Fixnum value from NUMBER(1) column if column specified in set_integer_columns" do
325
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
326
+ Test2Employee.set_integer_columns :is_manager
327
+ create_employee2
328
+ @employee2.is_manager.class.should == Fixnum
329
+ end
330
+
331
+ end
332
+
333
+ end
334
+
335
+ describe "OracleEnhancedAdapter boolean type detection based on string column types and names" do
336
+ before(:all) do
337
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
338
+ @conn = ActiveRecord::Base.connection
339
+ @conn.execute <<-SQL
340
+ CREATE TABLE test3_employees (
341
+ id NUMBER,
342
+ first_name VARCHAR2(20),
343
+ last_name VARCHAR2(25),
344
+ email VARCHAR2(25),
345
+ phone_number VARCHAR2(20),
346
+ hire_date DATE,
347
+ job_id NUMBER,
348
+ salary NUMBER,
349
+ commission_pct NUMBER(2,2),
350
+ manager_id NUMBER(6),
351
+ department_id NUMBER(4,0),
352
+ created_at DATE,
353
+ has_email CHAR(1),
354
+ has_phone VARCHAR2(1) DEFAULT 'Y',
355
+ active_flag VARCHAR2(2),
356
+ manager_yn VARCHAR2(3) DEFAULT 'N',
357
+ test_boolean VARCHAR2(3)
358
+ )
359
+ SQL
360
+ @conn.execute <<-SQL
361
+ CREATE SEQUENCE test3_employees_seq MINVALUE 1
362
+ INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
363
+ SQL
364
+ end
365
+
366
+ after(:all) do
367
+ @conn.execute "DROP TABLE test3_employees"
368
+ @conn.execute "DROP SEQUENCE test3_employees_seq"
369
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
370
+ end
371
+
372
+ it "should set CHAR/VARCHAR2 column type as string if emulate_booleans_from_strings is false" do
373
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
374
+ columns = @conn.columns('test3_employees')
375
+ %w(has_email has_phone active_flag manager_yn).each do |col|
376
+ column = columns.detect{|c| c.name == col}
377
+ column.type.should == :string
378
+ end
379
+ end
380
+
381
+ it "should set CHAR/VARCHAR2 column type as boolean if emulate_booleans_from_strings is true" do
382
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
383
+ columns = @conn.columns('test3_employees')
384
+ %w(has_email has_phone active_flag manager_yn).each do |col|
385
+ column = columns.detect{|c| c.name == col}
386
+ column.type.should == :boolean
387
+ end
388
+ end
389
+
390
+ it "should set VARCHAR2 column type as string if column name does not contain 'flag' or 'yn' and emulate_booleans_from_strings is true" do
391
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
392
+ columns = @conn.columns('test3_employees')
393
+ %w(phone_number email).each do |col|
394
+ column = columns.detect{|c| c.name == col}
395
+ column.type.should == :string
396
+ end
397
+ end
398
+
399
+ it "should return string value from VARCHAR2 boolean column if emulate_booleans_from_strings is false" do
400
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
401
+ columns = @conn.columns('test3_employees')
402
+ %w(has_email has_phone active_flag manager_yn).each do |col|
403
+ column = columns.detect{|c| c.name == col}
404
+ column.type_cast("Y").class.should == String
405
+ end
406
+ end
407
+
408
+ it "should return boolean value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
409
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
410
+ columns = @conn.columns('test3_employees')
411
+ %w(has_email has_phone active_flag manager_yn).each do |col|
412
+ column = columns.detect{|c| c.name == col}
413
+ column.type_cast("Y").class.should == TrueClass
414
+ column.type_cast("N").class.should == FalseClass
415
+ end
416
+ end
417
+
418
+ it "should translate boolean type to VARCHAR2(1) if emulate_booleans_from_strings is true" do
419
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
420
+ ActiveRecord::Base.connection.type_to_sql(
421
+ :boolean, nil, nil, nil).should == "VARCHAR2(1)"
422
+ end
423
+
424
+ it "should translate boolean type to NUMBER(1) if emulate_booleans_from_strings is false" do
425
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
426
+ ActiveRecord::Base.connection.type_to_sql(
427
+ :boolean, nil, nil, nil).should == "NUMBER(1)"
428
+ end
429
+
430
+ it "should get default value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
431
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
432
+ columns = @conn.columns('test3_employees')
433
+ columns.detect{|c| c.name == 'has_phone'}.default.should be_true
434
+ columns.detect{|c| c.name == 'manager_yn'}.default.should be_false
435
+ end
436
+
437
+ describe "/ VARCHAR2 boolean values from ActiveRecord model" do
438
+ before(:each) do
439
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
440
+ class ::Test3Employee < ActiveRecord::Base
441
+ end
442
+ end
443
+
444
+ after(:each) do
445
+ Object.send(:remove_const, "Test3Employee")
446
+ @conn.clear_types_for_columns
447
+ end
448
+
449
+ def create_employee3(params={})
450
+ @employee3 = Test3Employee.create(
451
+ {
452
+ :first_name => "First",
453
+ :last_name => "Last",
454
+ :has_email => true,
455
+ :has_phone => false,
456
+ :active_flag => true,
457
+ :manager_yn => false
458
+ }.merge(params)
459
+ )
460
+ @employee3.reload
461
+ end
462
+
463
+ it "should return String value from VARCHAR2 boolean column if emulate_booleans_from_strings is false" do
464
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
465
+ create_employee3
466
+ %w(has_email has_phone active_flag manager_yn).each do |col|
467
+ @employee3.send(col.to_sym).class.should == String
468
+ end
469
+ end
470
+
471
+ it "should return boolean value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
472
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
473
+ create_employee3
474
+ %w(has_email active_flag).each do |col|
475
+ @employee3.send(col.to_sym).class.should == TrueClass
476
+ @employee3.send((col+"_before_type_cast").to_sym).should == "Y"
477
+ end
478
+ %w(has_phone manager_yn).each do |col|
479
+ @employee3.send(col.to_sym).class.should == FalseClass
480
+ @employee3.send((col+"_before_type_cast").to_sym).should == "N"
481
+ end
482
+ end
483
+
484
+ it "should return string value from VARCHAR2 column if it is not boolean column and emulate_booleans_from_strings is true" do
485
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
486
+ create_employee3
487
+ @employee3.first_name.class.should == String
488
+ end
489
+
490
+ it "should return boolean value from VARCHAR2 boolean column if column specified in set_boolean_columns" do
491
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
492
+ Test3Employee.set_boolean_columns :test_boolean
493
+ create_employee3(:test_boolean => true)
494
+ @employee3.test_boolean.class.should == TrueClass
495
+ @employee3.test_boolean_before_type_cast.should == "Y"
496
+ create_employee3(:test_boolean => false)
497
+ @employee3.test_boolean.class.should == FalseClass
498
+ @employee3.test_boolean_before_type_cast.should == "N"
499
+ create_employee3(:test_boolean => nil)
500
+ @employee3.test_boolean.class.should == NilClass
501
+ @employee3.test_boolean_before_type_cast.should == nil
502
+ create_employee3(:test_boolean => "")
503
+ @employee3.test_boolean.class.should == NilClass
504
+ @employee3.test_boolean_before_type_cast.should == nil
505
+ end
506
+
507
+ it "should return string value from VARCHAR2 column with boolean column name but is specified in set_string_columns" do
508
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
509
+ Test3Employee.set_string_columns :active_flag
510
+ create_employee3
511
+ @employee3.active_flag.class.should == String
512
+ end
513
+
514
+ end
515
+
516
+ end
517
+
518
+ describe "OracleEnhancedAdapter timestamp with timezone support" do
519
+ before(:all) do
520
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
521
+ @conn = ActiveRecord::Base.connection
522
+ @conn.execute <<-SQL
523
+ CREATE TABLE test_employees (
524
+ employee_id NUMBER(6,0),
525
+ first_name VARCHAR2(20),
526
+ last_name VARCHAR2(25),
527
+ email VARCHAR2(25),
528
+ phone_number VARCHAR2(20),
529
+ hire_date DATE,
530
+ job_id NUMBER(6,0),
531
+ salary NUMBER(8,2),
532
+ commission_pct NUMBER(2,2),
533
+ manager_id NUMBER(6,0),
534
+ department_id NUMBER(4,0),
535
+ created_at TIMESTAMP,
536
+ created_at_tz TIMESTAMP WITH TIME ZONE,
537
+ created_at_ltz TIMESTAMP WITH LOCAL TIME ZONE
538
+ )
539
+ SQL
540
+ @conn.execute <<-SQL
541
+ CREATE SEQUENCE test_employees_seq MINVALUE 1
542
+ INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
543
+ SQL
544
+ end
545
+
546
+ after(:all) do
547
+ @conn.execute "DROP TABLE test_employees"
548
+ @conn.execute "DROP SEQUENCE test_employees_seq"
549
+ end
550
+
551
+ it "should set TIMESTAMP columns type as datetime" do
552
+ columns = @conn.columns('test_employees')
553
+ ts_columns = columns.select{|c| c.name =~ /created_at/}
554
+ ts_columns.each {|c| c.type.should == :timestamp}
555
+ end
556
+
557
+ describe "/ TIMESTAMP WITH TIME ZONE values from ActiveRecord model" do
558
+ before(:all) do
559
+ class ::TestEmployee < ActiveRecord::Base
560
+ set_primary_key :employee_id
561
+ end
562
+ end
563
+
564
+ after(:all) do
565
+ Object.send(:remove_const, "TestEmployee")
566
+ end
567
+
568
+ it "should return Time value from TIMESTAMP columns" do
569
+ @now = Time.local(2008,5,26,23,11,11,0)
570
+ @employee = TestEmployee.create(
571
+ :created_at => @now,
572
+ :created_at_tz => @now,
573
+ :created_at_ltz => @now
574
+ )
575
+ @employee.reload
576
+ [:created_at, :created_at_tz, :created_at_ltz].each do |c|
577
+ @employee.send(c).class.should == Time
578
+ @employee.send(c).to_f.should == @now.to_f
579
+ end
580
+ end
581
+
582
+ it "should return Time value with fractional seconds from TIMESTAMP columns" do
583
+ @now = Time.local(2008,5,26,23,11,11,10)
584
+ @employee = TestEmployee.create(
585
+ :created_at => @now,
586
+ :created_at_tz => @now,
587
+ :created_at_ltz => @now
588
+ )
589
+ @employee.reload
590
+ [:created_at, :created_at_tz, :created_at_ltz].each do |c|
591
+ @employee.send(c).class.should == Time
592
+ @employee.send(c).to_f.should == @now.to_f
593
+ end
594
+ end
595
+
596
+ end
597
+
598
+ end
599
+
600
+
601
+ describe "OracleEnhancedAdapter date and timestamp with different NLS date formats" do
602
+ before(:all) do
603
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
604
+ @conn = ActiveRecord::Base.connection
605
+ @conn.execute <<-SQL
606
+ CREATE TABLE test_employees (
607
+ employee_id NUMBER(6,0),
608
+ first_name VARCHAR2(20),
609
+ last_name VARCHAR2(25),
610
+ email VARCHAR2(25),
611
+ phone_number VARCHAR2(20),
612
+ hire_date DATE,
613
+ job_id NUMBER(6,0),
614
+ salary NUMBER(8,2),
615
+ commission_pct NUMBER(2,2),
616
+ manager_id NUMBER(6,0),
617
+ department_id NUMBER(4,0),
618
+ created_at DATE,
619
+ created_at_ts TIMESTAMP
620
+ )
621
+ SQL
622
+ @conn.execute <<-SQL
623
+ CREATE SEQUENCE test_employees_seq MINVALUE 1
624
+ INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
625
+ SQL
626
+ # @conn.execute %q{alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'}
627
+ @conn.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
628
+ # @conn.execute %q{alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'}
629
+ @conn.execute %q{alter session set nls_timestamp_format = 'DD-MON-YYYY HH24:MI:SS'}
630
+ end
631
+
632
+ after(:all) do
633
+ @conn.execute "DROP TABLE test_employees"
634
+ @conn.execute "DROP SEQUENCE test_employees_seq"
635
+ end
636
+
637
+ before(:each) do
638
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
639
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
640
+ class ::TestEmployee < ActiveRecord::Base
641
+ set_primary_key :employee_id
642
+ end
643
+ @today = Date.new(2008,6,28)
644
+ @now = Time.local(2008,6,28,13,34,33)
645
+ end
646
+
647
+ after(:each) do
648
+ Object.send(:remove_const, "TestEmployee")
649
+ end
650
+
651
+ def create_test_employee
652
+ @employee = TestEmployee.create(
653
+ :first_name => "First",
654
+ :last_name => "Last",
655
+ :hire_date => @today,
656
+ :created_at => @now,
657
+ :created_at_ts => @now
658
+ )
659
+ @employee.reload
660
+ end
661
+
662
+ it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
663
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
664
+ create_test_employee
665
+ @employee.hire_date.class.should == Time
666
+ @employee.hire_date.should == @today.to_time
667
+ end
668
+
669
+ it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
670
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
671
+ create_test_employee
672
+ @employee.hire_date.class.should == Date
673
+ @employee.hire_date.should == @today
674
+ end
675
+
676
+ it "should return Time value from DATE column if column name does not contain 'date' and emulate_dates_by_column_name is true" do
677
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
678
+ create_test_employee
679
+ @employee.created_at.class.should == Time
680
+ @employee.created_at.should == @now
681
+ end
682
+
683
+ it "should return Time value from TIMESTAMP columns" do
684
+ create_test_employee
685
+ @employee.created_at_ts.class.should == Time
686
+ @employee.created_at_ts.should == @now
687
+ end
688
+
689
+ it "should quote Date values with TO_DATE" do
690
+ @conn.quote(@today).should == "TO_DATE('#{@today.year}-#{"%02d" % @today.month}-#{"%02d" % @today.day}','YYYY-MM-DD HH24:MI:SS')"
691
+ end
692
+
693
+ it "should quote Time values with TO_DATE" do
694
+ @conn.quote(@now).should == "TO_DATE('#{@now.year}-#{"%02d" % @now.month}-#{"%02d" % @now.day} "+
695
+ "#{"%02d" % @now.hour}:#{"%02d" % @now.min}:#{"%02d" % @now.sec}','YYYY-MM-DD HH24:MI:SS')"
696
+ end
697
+
698
+ it "should quote Time values with TO_TIMESTAMP" do
699
+ @ts = @now + 0.1
700
+ @conn.quote(@ts).should == "TO_TIMESTAMP('#{@ts.year}-#{"%02d" % @ts.month}-#{"%02d" % @ts.day} "+
701
+ "#{"%02d" % @ts.hour}:#{"%02d" % @ts.min}:#{"%02d" % @ts.sec}:100000','YYYY-MM-DD HH24:MI:SS:FF6')"
702
+ end
703
+
704
+ end
705
+
706
+ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
707
+ before(:all) do
708
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
709
+ @conn = ActiveRecord::Base.connection
710
+ @conn.execute <<-SQL
711
+ CREATE TABLE test_employees (
712
+ employee_id NUMBER(6,0),
713
+ first_name VARCHAR2(20),
714
+ last_name VARCHAR2(25),
715
+ hire_date DATE,
716
+ last_login_at DATE,
717
+ last_login_at_ts TIMESTAMP
718
+ )
719
+ SQL
720
+ @conn.execute <<-SQL
721
+ CREATE SEQUENCE test_employees_seq MINVALUE 1
722
+ INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
723
+ SQL
724
+ class ::TestEmployee < ActiveRecord::Base
725
+ set_primary_key :employee_id
726
+ end
727
+ end
728
+
729
+ after(:all) do
730
+ Object.send(:remove_const, "TestEmployee")
731
+ @conn.execute "DROP TABLE test_employees"
732
+ @conn.execute "DROP SEQUENCE test_employees_seq"
733
+ end
734
+
735
+ before(:each) do
736
+ @today = Date.new(2008,6,28)
737
+ @today_iso = "2008-06-28"
738
+ @today_nls = "28.06.2008"
739
+ @nls_date_format = "%d.%m.%Y"
740
+ @now = Time.local(2008,6,28,13,34,33)
741
+ @now_iso = "2008-06-28 13:34:33"
742
+ @now_nls = "28.06.2008 13:34:33"
743
+ @nls_time_format = "%d.%m.%Y %H:%M:%S"
744
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
745
+ end
746
+
747
+ it "should assign ISO string to date column" do
748
+ @employee = TestEmployee.create(
749
+ :first_name => "First",
750
+ :last_name => "Last",
751
+ :hire_date => @today_iso
752
+ )
753
+ @employee.reload
754
+ @employee.hire_date.should == @today
755
+ end
756
+
757
+ it "should assign NLS string to date column" do
758
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
759
+ @employee = TestEmployee.create(
760
+ :first_name => "First",
761
+ :last_name => "Last",
762
+ :hire_date => @today_nls
763
+ )
764
+ @employee.reload
765
+ @employee.hire_date.should == @today
766
+ end
767
+
768
+ it "should assign ISO time string to date column" do
769
+ @employee = TestEmployee.create(
770
+ :first_name => "First",
771
+ :last_name => "Last",
772
+ :hire_date => @now_iso
773
+ )
774
+ @employee.reload
775
+ @employee.hire_date.should == @today
776
+ end
777
+
778
+ it "should assign NLS time string to date column" do
779
+ # ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
780
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
781
+ @employee = TestEmployee.create(
782
+ :first_name => "First",
783
+ :last_name => "Last",
784
+ :hire_date => @now_nls
785
+ )
786
+ @employee.reload
787
+ @employee.hire_date.should == @today
788
+ end
789
+
790
+ it "should assign ISO time string to datetime column" do
791
+ @employee = TestEmployee.create(
792
+ :first_name => "First",
793
+ :last_name => "Last",
794
+ :last_login_at => @now_iso
795
+ )
796
+ @employee.reload
797
+ @employee.last_login_at.should == @now
798
+ end
799
+
800
+ it "should assign NLS time string to datetime column" do
801
+ # ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
802
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
803
+ @employee = TestEmployee.create(
804
+ :first_name => "First",
805
+ :last_name => "Last",
806
+ :last_login_at => @now_nls
807
+ )
808
+ @employee.reload
809
+ @employee.last_login_at.should == @now
810
+ end
811
+
812
+ it "should assign ISO date string to datetime column" do
813
+ @employee = TestEmployee.create(
814
+ :first_name => "First",
815
+ :last_name => "Last",
816
+ :last_login_at => @today_iso
817
+ )
818
+ @employee.reload
819
+ @employee.last_login_at.should == @today.to_time
820
+ end
821
+
822
+ it "should assign NLS date string to datetime column" do
823
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
824
+ # ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
825
+ @employee = TestEmployee.create(
826
+ :first_name => "First",
827
+ :last_name => "Last",
828
+ :last_login_at => @today_nls
829
+ )
830
+ @employee.reload
831
+ @employee.last_login_at.should == @today.to_time
832
+ end
833
+
834
+ end
835
+
836
+ describe "OracleEnhancedAdapter handling of CLOB columns" do
837
+ before(:all) do
838
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
839
+ @conn = ActiveRecord::Base.connection
840
+ @conn.execute <<-SQL
841
+ CREATE TABLE test_employees (
842
+ employee_id NUMBER(6,0),
843
+ first_name VARCHAR2(20),
844
+ last_name VARCHAR2(25),
845
+ comments CLOB
846
+ )
847
+ SQL
848
+ @conn.execute <<-SQL
849
+ CREATE SEQUENCE test_employees_seq MINVALUE 1
850
+ INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
851
+ SQL
852
+ class ::TestEmployee < ActiveRecord::Base
853
+ set_primary_key :employee_id
854
+ end
855
+ end
856
+
857
+ after(:all) do
858
+ Object.send(:remove_const, "TestEmployee")
859
+ @conn.execute "DROP TABLE test_employees"
860
+ @conn.execute "DROP SEQUENCE test_employees_seq"
861
+ end
862
+
863
+ before(:each) do
864
+ end
865
+
866
+ it "should create record without CLOB data when attribute is serialized" do
867
+ TestEmployee.serialize :comments
868
+ @employee = TestEmployee.create!(
869
+ :first_name => "First",
870
+ :last_name => "Last"
871
+ )
872
+ @employee.should be_valid
873
+ TestEmployee.serialized_attributes.delete('comments')
874
+ end
875
+
876
+ it "should order by CLOB column" do
877
+ @employee = TestEmployee.create!(
878
+ :first_name => "First",
879
+ :last_name => "Last",
880
+ :comments => "comments"
881
+ )
882
+ TestEmployee.find(:all, :order => "comments ASC").should_not be_empty
883
+ TestEmployee.find(:all, :order => " comments ASC ").should_not be_empty
884
+ TestEmployee.find(:all, :order => "comments").should_not be_empty
885
+ TestEmployee.find(:all, :order => " comments ").should_not be_empty
886
+ TestEmployee.find(:all, :order => :comments).should_not be_empty
887
+ TestEmployee.find(:all, :order => " first_name DESC, last_name ASC ").should_not be_empty
888
+ end
889
+
890
+ it "should accept Symbol value for CLOB column" do
891
+ @employee = TestEmployee.create!(
892
+ :comments => :test_comment
893
+ )
894
+ @employee.should be_valid
895
+ end
896
+
897
+ end
898
+
899
+ describe "OracleEnhancedAdapter handling of BLOB columns" do
900
+ before(:all) do
901
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
902
+ @conn = ActiveRecord::Base.connection
903
+ @conn.execute <<-SQL
904
+ CREATE TABLE test_employees (
905
+ employee_id NUMBER(6,0),
906
+ first_name VARCHAR2(20),
907
+ last_name VARCHAR2(25),
908
+ binary_data BLOB
909
+ )
910
+ SQL
911
+ @conn.execute <<-SQL
912
+ CREATE SEQUENCE test_employees_seq MINVALUE 1
913
+ INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
914
+ SQL
915
+ @binary_data = "\0\1\2\3\4\5\6\7\8\9"*10000
916
+ @binary_data2 = "\1\2\3\4\5\6\7\8\9\0"*10000
917
+ end
918
+
919
+ after(:all) do
920
+ @conn.execute "DROP TABLE test_employees"
921
+ @conn.execute "DROP SEQUENCE test_employees_seq"
922
+ end
923
+
924
+ before(:each) do
925
+ class ::TestEmployee < ActiveRecord::Base
926
+ set_primary_key :employee_id
927
+ end
928
+ end
929
+
930
+ after(:each) do
931
+ Object.send(:remove_const, "TestEmployee")
932
+ end
933
+
934
+ it "should create record with BLOB data" do
935
+ @employee = TestEmployee.create!(
936
+ :first_name => "First",
937
+ :last_name => "Last",
938
+ :binary_data => @binary_data
939
+ )
940
+ @employee.reload
941
+ @employee.binary_data.should == @binary_data
942
+ end
943
+
944
+ it "should update record with BLOB data" do
945
+ @employee = TestEmployee.create!(
946
+ :first_name => "First",
947
+ :last_name => "Last"
948
+ )
949
+ @employee.reload
950
+ @employee.binary_data.should be_nil
951
+ @employee.binary_data = @binary_data
952
+ @employee.save!
953
+ @employee.reload
954
+ @employee.binary_data.should == @binary_data
955
+ end
956
+
957
+ it "should update record that has existing BLOB data with different BLOB data" do
958
+ @employee = TestEmployee.create!(
959
+ :first_name => "First",
960
+ :last_name => "Last",
961
+ :binary_data => @binary_data
962
+ )
963
+ @employee.reload
964
+ @employee.binary_data = @binary_data2
965
+ @employee.save!
966
+ @employee.reload
967
+ @employee.binary_data.should == @binary_data2
968
+ end
969
+
970
+ it "should update record that has existing BLOB data with nil" do
971
+ @employee = TestEmployee.create!(
972
+ :first_name => "First",
973
+ :last_name => "Last",
974
+ :binary_data => @binary_data
975
+ )
976
+ @employee.reload
977
+ @employee.binary_data = nil
978
+ @employee.save!
979
+ @employee.reload
980
+ @employee.binary_data.should be_nil
981
+ end
982
+
983
+ end
984
+