activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +206 -4
- data/README.md +37 -1
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +7 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +37 -27
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +56 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +14 -43
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +150 -160
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +95 -133
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +66 -101
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +290 -533
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
- data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +55 -162
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +44 -42
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +250 -357
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +115 -124
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +68 -72
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +64 -80
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +223 -329
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +18 -20
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -59
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +25 -25
- data/.rspec +0 -2
- data/Gemfile +0 -22
- data/RUNNING_TESTS.md +0 -83
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -94
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -19
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe "OracleEnhancedAdapter date type detection based on column names" do
|
4
2
|
before(:all) do
|
5
3
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
@@ -36,21 +34,19 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
36
34
|
|
37
35
|
describe "/ DATE values from ActiveRecord model" do
|
38
36
|
before(:each) do
|
39
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
40
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
|
41
37
|
class ::TestEmployee < ActiveRecord::Base
|
42
38
|
self.primary_key = "employee_id"
|
43
39
|
end
|
44
40
|
end
|
45
41
|
|
46
|
-
def create_test_employee(params={})
|
47
|
-
@today = params[:today] || Date.new(2008,8,19)
|
48
|
-
@now = params[:now] || Time.local(2008,8,19,17,03,59)
|
42
|
+
def create_test_employee(params = {})
|
43
|
+
@today = params[:today] || Date.new(2008, 8, 19)
|
44
|
+
@now = params[:now] || Time.local(2008, 8, 19, 17, 03, 59)
|
49
45
|
@employee = TestEmployee.create(
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
46
|
+
first_name: "First",
|
47
|
+
last_name: "Last",
|
48
|
+
hire_date: @today,
|
49
|
+
created_at: @now
|
54
50
|
)
|
55
51
|
@employee.reload
|
56
52
|
end
|
@@ -58,11 +54,10 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
58
54
|
after(:each) do
|
59
55
|
# @employee.destroy if @employee
|
60
56
|
Object.send(:remove_const, "TestEmployee")
|
61
|
-
ActiveRecord::Base.clear_cache!
|
57
|
+
ActiveRecord::Base.clear_cache!
|
62
58
|
end
|
63
59
|
|
64
60
|
it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
|
65
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
66
61
|
class ::TestEmployee < ActiveRecord::Base
|
67
62
|
attribute :hire_date, :datetime
|
68
63
|
end
|
@@ -71,19 +66,16 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
71
66
|
end
|
72
67
|
|
73
68
|
it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
74
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
75
69
|
create_test_employee
|
76
70
|
expect(@employee.hire_date.class).to eq(Date)
|
77
71
|
end
|
78
72
|
|
79
73
|
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
|
80
|
-
|
81
|
-
create_test_employee(:today => Date.new(1900,1,1))
|
74
|
+
create_test_employee(today: Date.new(1900, 1, 1))
|
82
75
|
expect(@employee.hire_date.class).to eq(Date)
|
83
76
|
end
|
84
77
|
|
85
78
|
it "should return Time value from DATE column if column name does not contain 'date' and emulate_dates_by_column_name is true" do
|
86
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
87
79
|
class ::TestEmployee < ActiveRecord::Base
|
88
80
|
# set_date_columns :created_at
|
89
81
|
attribute :created_at, :datetime
|
@@ -92,32 +84,11 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
92
84
|
expect(@employee.created_at.class).to eq(Time)
|
93
85
|
end
|
94
86
|
|
95
|
-
it "should return Date value from DATE column if emulate_dates_by_column_name is false but column is defined as date" do
|
96
|
-
class ::TestEmployee < ActiveRecord::Base
|
97
|
-
# set_date_columns :hire_date
|
98
|
-
attribute :hire_date, :date
|
99
|
-
end
|
100
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
101
|
-
create_test_employee
|
102
|
-
expect(@employee.hire_date.class).to eq(Date)
|
103
|
-
end
|
104
|
-
|
105
|
-
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
|
106
|
-
class ::TestEmployee < ActiveRecord::Base
|
107
|
-
# set_date_columns :hire_date
|
108
|
-
attribute :hire_date, :date
|
109
|
-
end
|
110
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
111
|
-
create_test_employee(:today => Date.new(1900,1,1))
|
112
|
-
expect(@employee.hire_date.class).to eq(Date)
|
113
|
-
end
|
114
|
-
|
115
87
|
it "should return Time value from DATE column if emulate_dates_by_column_name is true but column is defined as datetime" do
|
116
88
|
class ::TestEmployee < ActiveRecord::Base
|
117
89
|
# set_datetime_columns :hire_date
|
118
90
|
attribute :hire_date, :datetime
|
119
91
|
end
|
120
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
121
92
|
create_test_employee
|
122
93
|
expect(@employee.hire_date.class).to eq(Time)
|
123
94
|
# change to current time with hours, minutes and seconds
|
@@ -129,7 +100,6 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
129
100
|
end
|
130
101
|
|
131
102
|
it "should guess Date or Time value if emulate_dates is true" do
|
132
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = true
|
133
103
|
class ::TestEmployee < ActiveRecord::Base
|
134
104
|
attribute :hire_date, :date
|
135
105
|
attribute :created_at, :datetime
|
@@ -186,28 +156,26 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
186
156
|
after(:each) do
|
187
157
|
Object.send(:remove_const, "Test2Employee")
|
188
158
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
|
189
|
-
ActiveRecord::Base.clear_cache!
|
159
|
+
ActiveRecord::Base.clear_cache!
|
190
160
|
end
|
191
161
|
|
192
162
|
def create_employee2
|
193
163
|
@employee2 = Test2Employee.create(
|
194
|
-
:
|
195
|
-
:
|
196
|
-
:
|
197
|
-
:
|
198
|
-
:
|
164
|
+
first_name: "First",
|
165
|
+
last_name: "Last",
|
166
|
+
job_id: 1,
|
167
|
+
is_manager: 1,
|
168
|
+
salary: 1000
|
199
169
|
)
|
200
170
|
@employee2.reload
|
201
171
|
end
|
202
172
|
|
203
173
|
it "should return BigDecimal value from NUMBER column if emulate_integers_by_column_name is false" do
|
204
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
|
205
174
|
create_employee2
|
206
175
|
expect(@employee2.job_id.class).to eq(BigDecimal)
|
207
176
|
end
|
208
177
|
|
209
178
|
it "should return Integer value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
|
210
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
211
179
|
class ::Test2Employee < ActiveRecord::Base
|
212
180
|
attribute :job_id, :integer
|
213
181
|
end
|
@@ -216,20 +184,16 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
216
184
|
end
|
217
185
|
|
218
186
|
it "should return Integer value from NUMBER column with integer value using _before_type_cast method" do
|
219
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
220
187
|
create_employee2
|
221
188
|
expect(@employee2.job_id_before_type_cast).to be_a(Integer)
|
222
189
|
end
|
223
190
|
|
224
191
|
it "should return BigDecimal value from NUMBER column if column name does not contain 'id' and emulate_integers_by_column_name is true" do
|
225
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
226
192
|
create_employee2
|
227
193
|
expect(@employee2.salary.class).to eq(BigDecimal)
|
228
194
|
end
|
229
195
|
|
230
196
|
it "should return Integer value from NUMBER column if column specified in set_integer_columns" do
|
231
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
|
232
|
-
# Test2Employee.set_integer_columns :job_id
|
233
197
|
class ::Test2Employee < ActiveRecord::Base
|
234
198
|
attribute :job_id, :integer
|
235
199
|
end
|
@@ -238,13 +202,11 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
238
202
|
end
|
239
203
|
|
240
204
|
it "should return Boolean value from NUMBER(1) column if emulate booleans is used" do
|
241
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
|
242
205
|
create_employee2
|
243
206
|
expect(@employee2.is_manager.class).to eq(TrueClass)
|
244
207
|
end
|
245
208
|
|
246
209
|
it "should return Integer value from NUMBER(1) column if emulate booleans is not used" do
|
247
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = false
|
248
210
|
class ::Test2Employee < ActiveRecord::Base
|
249
211
|
attribute :is_manager, :integer
|
250
212
|
end
|
@@ -253,8 +215,6 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
253
215
|
end
|
254
216
|
|
255
217
|
it "should return Integer value from NUMBER(1) column if column specified in set_integer_columns" do
|
256
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
|
257
|
-
# Test2Employee.set_integer_columns :is_manager
|
258
218
|
class ::Test2Employee < ActiveRecord::Base
|
259
219
|
attribute :is_manager, :integer
|
260
220
|
end
|
@@ -300,7 +260,6 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
300
260
|
after(:all) do
|
301
261
|
@conn.execute "DROP TABLE test3_employees"
|
302
262
|
@conn.execute "DROP SEQUENCE test3_employees_seq"
|
303
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
304
263
|
end
|
305
264
|
|
306
265
|
before(:each) do
|
@@ -310,7 +269,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
310
269
|
|
311
270
|
after(:each) do
|
312
271
|
Object.send(:remove_const, "Test3Employee")
|
313
|
-
ActiveRecord::Base.clear_cache!
|
272
|
+
ActiveRecord::Base.clear_cache!
|
314
273
|
end
|
315
274
|
|
316
275
|
describe "default values in new records" do
|
@@ -321,8 +280,8 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
321
280
|
|
322
281
|
it "are Y or N" do
|
323
282
|
subject = Test3Employee.new
|
324
|
-
expect(subject.has_phone).to eq(
|
325
|
-
expect(subject.manager_yn).to eq(
|
283
|
+
expect(subject.has_phone).to eq("Y")
|
284
|
+
expect(subject.manager_yn).to eq("N")
|
326
285
|
end
|
327
286
|
end
|
328
287
|
|
@@ -345,8 +304,8 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
345
304
|
|
346
305
|
it "should translate boolean type to NUMBER(1) if emulate_booleans_from_strings is false" do
|
347
306
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
348
|
-
|
349
|
-
|
307
|
+
sql_type = ActiveRecord::Base.connection.type_to_sql(:boolean)
|
308
|
+
expect(sql_type).to eq("NUMBER(1)")
|
350
309
|
end
|
351
310
|
|
352
311
|
describe "/ VARCHAR2 boolean values from ActiveRecord model" do
|
@@ -355,18 +314,18 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
355
314
|
end
|
356
315
|
|
357
316
|
after(:each) do
|
358
|
-
ActiveRecord::Base.clear_cache!
|
317
|
+
ActiveRecord::Base.clear_cache!
|
359
318
|
end
|
360
319
|
|
361
|
-
def create_employee3(params={})
|
320
|
+
def create_employee3(params = {})
|
362
321
|
@employee3 = Test3Employee.create(
|
363
322
|
{
|
364
|
-
:
|
365
|
-
:
|
366
|
-
:
|
367
|
-
:
|
368
|
-
:
|
369
|
-
:
|
323
|
+
first_name: "First",
|
324
|
+
last_name: "Last",
|
325
|
+
has_email: true,
|
326
|
+
has_phone: false,
|
327
|
+
active_flag: true,
|
328
|
+
manager_yn: false
|
370
329
|
}.merge(params)
|
371
330
|
)
|
372
331
|
@employee3.reload
|
@@ -391,11 +350,11 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
391
350
|
create_employee3
|
392
351
|
%w(has_email active_flag).each do |col|
|
393
352
|
expect(@employee3.send(col.to_sym).class).to eq(TrueClass)
|
394
|
-
expect(@employee3.send((col+"_before_type_cast").to_sym)).to eq("Y")
|
353
|
+
expect(@employee3.send((col + "_before_type_cast").to_sym)).to eq("Y")
|
395
354
|
end
|
396
355
|
%w(has_phone manager_yn).each do |col|
|
397
356
|
expect(@employee3.send(col.to_sym).class).to eq(FalseClass)
|
398
|
-
expect(@employee3.send((col+"_before_type_cast").to_sym)).to eq("N")
|
357
|
+
expect(@employee3.send((col + "_before_type_cast").to_sym)).to eq("N")
|
399
358
|
end
|
400
359
|
end
|
401
360
|
|
@@ -407,27 +366,25 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
407
366
|
|
408
367
|
it "should return boolean value from VARCHAR2 boolean column if column specified in set_boolean_columns" do
|
409
368
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
410
|
-
# Test3Employee.set_boolean_columns :test_boolean
|
411
369
|
class ::Test3Employee < ActiveRecord::Base
|
412
370
|
attribute :test_boolean, :boolean
|
413
371
|
end
|
414
|
-
create_employee3(:
|
372
|
+
create_employee3(test_boolean: true)
|
415
373
|
expect(@employee3.test_boolean.class).to eq(TrueClass)
|
416
374
|
expect(@employee3.test_boolean_before_type_cast).to eq("Y")
|
417
|
-
create_employee3(:
|
375
|
+
create_employee3(test_boolean: false)
|
418
376
|
expect(@employee3.test_boolean.class).to eq(FalseClass)
|
419
377
|
expect(@employee3.test_boolean_before_type_cast).to eq("N")
|
420
|
-
create_employee3(:
|
378
|
+
create_employee3(test_boolean: nil)
|
421
379
|
expect(@employee3.test_boolean.class).to eq(NilClass)
|
422
380
|
expect(@employee3.test_boolean_before_type_cast).to eq(nil)
|
423
|
-
create_employee3(:
|
381
|
+
create_employee3(test_boolean: "")
|
424
382
|
expect(@employee3.test_boolean.class).to eq(NilClass)
|
425
383
|
expect(@employee3.test_boolean_before_type_cast).to eq(nil)
|
426
384
|
end
|
427
385
|
|
428
386
|
it "should return string value from VARCHAR2 column with boolean column name but is specified in set_string_columns" do
|
429
387
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
430
|
-
# Test3Employee.set_string_columns :active_flag
|
431
388
|
class ::Test3Employee < ActiveRecord::Base
|
432
389
|
attribute :active_flag, :string
|
433
390
|
end
|
@@ -446,7 +403,7 @@ describe "OracleEnhancedAdapter boolean support when emulate_booleans_from_strin
|
|
446
403
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
447
404
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
448
405
|
schema_define do
|
449
|
-
create_table :posts, :
|
406
|
+
create_table :posts, force: true do |t|
|
450
407
|
t.string :name, null: false
|
451
408
|
t.boolean :is_default, default: false
|
452
409
|
end
|
@@ -468,7 +425,7 @@ describe "OracleEnhancedAdapter boolean support when emulate_booleans_from_strin
|
|
468
425
|
end
|
469
426
|
|
470
427
|
it "boolean should not change after reload" do
|
471
|
-
post = Post.create(name:
|
428
|
+
post = Post.create(name: "Test 1", is_default: false)
|
472
429
|
expect(post.is_default).to be false
|
473
430
|
post.reload
|
474
431
|
expect(post.is_default).to be false
|
@@ -510,13 +467,6 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
510
467
|
ActiveRecord::Base.default_timezone = :utc
|
511
468
|
end
|
512
469
|
|
513
|
-
it "should set TIMESTAMP columns type as datetime" do
|
514
|
-
skip "TIMESTAMP sql_type should be :datetime in Rails 5"
|
515
|
-
columns = @conn.columns('test_employees')
|
516
|
-
ts_columns = columns.select{|c| c.name =~ /created_at/}
|
517
|
-
ts_columns.each {|c| expect(c.type).to eq(:timestamp)}
|
518
|
-
end
|
519
|
-
|
520
470
|
describe "/ TIMESTAMP WITH TIME ZONE values from ActiveRecord model" do
|
521
471
|
before(:all) do
|
522
472
|
class ::TestEmployee < ActiveRecord::Base
|
@@ -526,15 +476,15 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
526
476
|
|
527
477
|
after(:all) do
|
528
478
|
Object.send(:remove_const, "TestEmployee")
|
529
|
-
ActiveRecord::Base.clear_cache!
|
479
|
+
ActiveRecord::Base.clear_cache!
|
530
480
|
end
|
531
481
|
|
532
482
|
it "should return Time value from TIMESTAMP columns" do
|
533
|
-
@now = Time.local(2008,5,26,23,11,11,0)
|
483
|
+
@now = Time.local(2008, 5, 26, 23, 11, 11, 0)
|
534
484
|
@employee = TestEmployee.create(
|
535
|
-
:
|
536
|
-
:
|
537
|
-
:
|
485
|
+
created_at: @now,
|
486
|
+
created_at_tz: @now,
|
487
|
+
created_at_ltz: @now
|
538
488
|
)
|
539
489
|
@employee.reload
|
540
490
|
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
@@ -544,11 +494,11 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
544
494
|
end
|
545
495
|
|
546
496
|
it "should return Time value with fractional seconds from TIMESTAMP columns" do
|
547
|
-
@now = Time.local(2008,5,26,23,11,11,10)
|
497
|
+
@now = Time.local(2008, 5, 26, 23, 11, 11, 10)
|
548
498
|
@employee = TestEmployee.create(
|
549
|
-
:
|
550
|
-
:
|
551
|
-
:
|
499
|
+
created_at: @now,
|
500
|
+
created_at_tz: @now,
|
501
|
+
created_at_ltz: @now
|
552
502
|
)
|
553
503
|
@employee.reload
|
554
504
|
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
@@ -561,105 +511,6 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
561
511
|
|
562
512
|
end
|
563
513
|
|
564
|
-
describe "OracleEnhancedAdapter date and timestamp with different NLS date formats" do
|
565
|
-
before(:all) do
|
566
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
567
|
-
@conn = ActiveRecord::Base.connection
|
568
|
-
@conn.execute <<-SQL
|
569
|
-
CREATE TABLE test_employees (
|
570
|
-
employee_id NUMBER(6,0) PRIMARY KEY,
|
571
|
-
first_name VARCHAR2(20),
|
572
|
-
last_name VARCHAR2(25),
|
573
|
-
email VARCHAR2(25),
|
574
|
-
phone_number VARCHAR2(20),
|
575
|
-
hire_date DATE,
|
576
|
-
job_id NUMBER(6,0),
|
577
|
-
salary NUMBER(8,2),
|
578
|
-
commission_pct NUMBER(2,2),
|
579
|
-
manager_id NUMBER(6,0),
|
580
|
-
department_id NUMBER(4,0),
|
581
|
-
created_at DATE,
|
582
|
-
created_at_ts TIMESTAMP
|
583
|
-
)
|
584
|
-
SQL
|
585
|
-
@conn.execute <<-SQL
|
586
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
587
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
588
|
-
SQL
|
589
|
-
# @conn.execute %q{alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'}
|
590
|
-
@conn.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
|
591
|
-
# @conn.execute %q{alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'}
|
592
|
-
@conn.execute %q{alter session set nls_timestamp_format = 'DD-MON-YYYY HH24:MI:SS'}
|
593
|
-
end
|
594
|
-
|
595
|
-
after(:all) do
|
596
|
-
@conn.execute "DROP TABLE test_employees"
|
597
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
598
|
-
end
|
599
|
-
|
600
|
-
before(:each) do
|
601
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
|
602
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
603
|
-
class ::TestEmployee < ActiveRecord::Base
|
604
|
-
self.primary_key = "employee_id"
|
605
|
-
end
|
606
|
-
@today = Date.new(2008,6,28)
|
607
|
-
@now = Time.local(2008,6,28,13,34,33)
|
608
|
-
end
|
609
|
-
|
610
|
-
after(:each) do
|
611
|
-
Object.send(:remove_const, "TestEmployee")
|
612
|
-
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
613
|
-
ActiveRecord::Base.default_timezone = :utc
|
614
|
-
end
|
615
|
-
|
616
|
-
def create_test_employee
|
617
|
-
@employee = TestEmployee.create(
|
618
|
-
:first_name => "First",
|
619
|
-
:last_name => "Last",
|
620
|
-
:hire_date => @today,
|
621
|
-
:created_at => @now,
|
622
|
-
:created_at_ts => @now
|
623
|
-
)
|
624
|
-
@employee.reload
|
625
|
-
end
|
626
|
-
|
627
|
-
it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
|
628
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
629
|
-
ActiveRecord::Base.default_timezone = :local
|
630
|
-
class ::TestEmployee < ActiveRecord::Base
|
631
|
-
attribute :hire_date, :datetime
|
632
|
-
end
|
633
|
-
create_test_employee
|
634
|
-
expect(@employee.hire_date.class).to eq(Time)
|
635
|
-
expect(@employee.hire_date).to eq(@today.to_time)
|
636
|
-
end
|
637
|
-
|
638
|
-
it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
639
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
640
|
-
create_test_employee
|
641
|
-
expect(@employee.hire_date.class).to eq(Date)
|
642
|
-
expect(@employee.hire_date).to eq(@today)
|
643
|
-
end
|
644
|
-
|
645
|
-
it "should return Time value from DATE column if column name does not contain 'date' and emulate_dates_by_column_name is true" do
|
646
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
647
|
-
class ::TestEmployee < ActiveRecord::Base
|
648
|
-
attribute :created_at, :datetime
|
649
|
-
end
|
650
|
-
create_test_employee
|
651
|
-
expect(@employee.created_at.class).to eq(Time)
|
652
|
-
expect(@employee.created_at).to eq(@now)
|
653
|
-
end
|
654
|
-
|
655
|
-
it "should return Time value from TIMESTAMP columns" do
|
656
|
-
create_test_employee
|
657
|
-
expect(@employee.created_at_ts.class).to eq(Time)
|
658
|
-
expect(@employee.created_at_ts).to eq(@now)
|
659
|
-
end
|
660
|
-
|
661
|
-
end
|
662
|
-
|
663
514
|
describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
664
515
|
before(:all) do
|
665
516
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
@@ -682,11 +533,11 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
682
533
|
self.primary_key = "employee_id"
|
683
534
|
attribute :last_login_at, :datetime
|
684
535
|
end
|
685
|
-
@today = Date.new(2008,6,28)
|
536
|
+
@today = Date.new(2008, 6, 28)
|
686
537
|
@today_iso = "2008-06-28"
|
687
538
|
@today_nls = "28.06.2008"
|
688
539
|
@nls_date_format = "%d.%m.%Y"
|
689
|
-
@now = Time.local(2008,6,28,13,34,33)
|
540
|
+
@now = Time.local(2008, 6, 28, 13, 34, 33)
|
690
541
|
@now_iso = "2008-06-28 13:34:33"
|
691
542
|
@now_nls = "28.06.2008 13:34:33"
|
692
543
|
@nls_time_format = "%d.%m.%Y %H:%M:%S"
|
@@ -699,11 +550,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
699
550
|
Object.send(:remove_const, "TestEmployee")
|
700
551
|
@conn.execute "DROP TABLE test_employees"
|
701
552
|
@conn.execute "DROP SEQUENCE test_employees_seq"
|
702
|
-
ActiveRecord::Base.clear_cache!
|
703
|
-
end
|
704
|
-
|
705
|
-
before(:each) do
|
706
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
553
|
+
ActiveRecord::Base.clear_cache!
|
707
554
|
end
|
708
555
|
|
709
556
|
after(:each) do
|
@@ -712,9 +559,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
712
559
|
|
713
560
|
it "should assign ISO string to date column" do
|
714
561
|
@employee = TestEmployee.create(
|
715
|
-
:
|
716
|
-
:
|
717
|
-
:
|
562
|
+
first_name: "First",
|
563
|
+
last_name: "Last",
|
564
|
+
hire_date: @today_iso
|
718
565
|
)
|
719
566
|
expect(@employee.hire_date).to eq(@today)
|
720
567
|
@employee.reload
|
@@ -722,11 +569,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
722
569
|
end
|
723
570
|
|
724
571
|
it "should assign NLS string to date column" do
|
725
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
726
572
|
@employee = TestEmployee.create(
|
727
|
-
:
|
728
|
-
:
|
729
|
-
:
|
573
|
+
first_name: "First",
|
574
|
+
last_name: "Last",
|
575
|
+
hire_date: @today_nls
|
730
576
|
)
|
731
577
|
expect(@employee.hire_date).to eq(@today)
|
732
578
|
@employee.reload
|
@@ -735,9 +581,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
735
581
|
|
736
582
|
it "should assign ISO time string to date column" do
|
737
583
|
@employee = TestEmployee.create(
|
738
|
-
:
|
739
|
-
:
|
740
|
-
:
|
584
|
+
first_name: "First",
|
585
|
+
last_name: "Last",
|
586
|
+
hire_date: @now_iso
|
741
587
|
)
|
742
588
|
expect(@employee.hire_date).to eq(@today)
|
743
589
|
@employee.reload
|
@@ -745,12 +591,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
745
591
|
end
|
746
592
|
|
747
593
|
it "should assign NLS time string to date column" do
|
748
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
749
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
750
594
|
@employee = TestEmployee.create(
|
751
|
-
:
|
752
|
-
:
|
753
|
-
:
|
595
|
+
first_name: "First",
|
596
|
+
last_name: "Last",
|
597
|
+
hire_date: @now_nls
|
754
598
|
)
|
755
599
|
expect(@employee.hire_date).to eq(@today)
|
756
600
|
@employee.reload
|
@@ -760,9 +604,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
760
604
|
it "should assign ISO time string to datetime column" do
|
761
605
|
ActiveRecord::Base.default_timezone = :local
|
762
606
|
@employee = TestEmployee.create(
|
763
|
-
:
|
764
|
-
:
|
765
|
-
:
|
607
|
+
first_name: "First",
|
608
|
+
last_name: "Last",
|
609
|
+
last_login_at: @now_iso
|
766
610
|
)
|
767
611
|
expect(@employee.last_login_at).to eq(@now)
|
768
612
|
@employee.reload
|
@@ -771,11 +615,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
771
615
|
|
772
616
|
it "should assign NLS time string to datetime column" do
|
773
617
|
ActiveRecord::Base.default_timezone = :local
|
774
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
775
618
|
@employee = TestEmployee.create(
|
776
|
-
:
|
777
|
-
:
|
778
|
-
:
|
619
|
+
first_name: "First",
|
620
|
+
last_name: "Last",
|
621
|
+
last_login_at: @now_nls
|
779
622
|
)
|
780
623
|
expect(@employee.last_login_at).to eq(@now)
|
781
624
|
@employee.reload
|
@@ -783,11 +626,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
783
626
|
end
|
784
627
|
|
785
628
|
it "should assign NLS time string with time zone to datetime column" do
|
786
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_with_tz_time_format
|
787
629
|
@employee = TestEmployee.create(
|
788
|
-
:
|
789
|
-
:
|
790
|
-
:
|
630
|
+
first_name: "First",
|
631
|
+
last_name: "Last",
|
632
|
+
last_login_at: @now_nls_with_tz
|
791
633
|
)
|
792
634
|
expect(@employee.last_login_at).to eq(@now_with_tz)
|
793
635
|
@employee.reload
|
@@ -797,9 +639,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
797
639
|
it "should assign ISO date string to datetime column" do
|
798
640
|
ActiveRecord::Base.default_timezone = :local
|
799
641
|
@employee = TestEmployee.create(
|
800
|
-
:
|
801
|
-
:
|
802
|
-
:
|
642
|
+
first_name: "First",
|
643
|
+
last_name: "Last",
|
644
|
+
last_login_at: @today_iso
|
803
645
|
)
|
804
646
|
expect(@employee.last_login_at).to eq(@today.to_time)
|
805
647
|
@employee.reload
|
@@ -808,12 +650,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
808
650
|
|
809
651
|
it "should assign NLS date string to datetime column" do
|
810
652
|
ActiveRecord::Base.default_timezone = :local
|
811
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
812
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
813
653
|
@employee = TestEmployee.create(
|
814
|
-
:
|
815
|
-
:
|
816
|
-
:
|
654
|
+
first_name: "First",
|
655
|
+
last_name: "Last",
|
656
|
+
last_login_at: @today_nls
|
817
657
|
)
|
818
658
|
expect(@employee.last_login_at).to eq(@today.to_time)
|
819
659
|
@employee.reload
|
@@ -891,13 +731,13 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
891
731
|
Object.send(:remove_const, "Test2Employee")
|
892
732
|
Object.send(:remove_const, "TestEmployeeReadOnlyClob")
|
893
733
|
Object.send(:remove_const, "TestSerializeEmployee")
|
894
|
-
ActiveRecord::Base.clear_cache!
|
734
|
+
ActiveRecord::Base.clear_cache!
|
895
735
|
end
|
896
736
|
|
897
737
|
it "should create record without CLOB data when attribute is serialized" do
|
898
738
|
@employee = Test2Employee.create!(
|
899
|
-
:
|
900
|
-
:
|
739
|
+
first_name: "First",
|
740
|
+
last_name: "Last"
|
901
741
|
)
|
902
742
|
expect(@employee).to be_valid
|
903
743
|
@employee.reload
|
@@ -906,29 +746,29 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
906
746
|
|
907
747
|
it "should accept Symbol value for CLOB column" do
|
908
748
|
@employee = TestEmployee.create!(
|
909
|
-
:
|
749
|
+
comments: :test_comment
|
910
750
|
)
|
911
751
|
expect(@employee).to be_valid
|
912
752
|
end
|
913
753
|
|
914
754
|
it "should respect attr_readonly setting for CLOB column" do
|
915
755
|
@employee = TestEmployeeReadOnlyClob.create!(
|
916
|
-
:
|
917
|
-
:
|
756
|
+
first_name: "First",
|
757
|
+
comments: "initial"
|
918
758
|
)
|
919
759
|
expect(@employee).to be_valid
|
920
760
|
@employee.reload
|
921
|
-
expect(@employee.comments).to eq(
|
761
|
+
expect(@employee.comments).to eq("initial")
|
922
762
|
@employee.comments = "changed"
|
923
763
|
expect(@employee.save).to eq(true)
|
924
764
|
@employee.reload
|
925
|
-
expect(@employee.comments).to eq(
|
765
|
+
expect(@employee.comments).to eq("initial")
|
926
766
|
end
|
927
767
|
|
928
768
|
it "should work for serialized readonly CLOB columns", serialized: true do
|
929
769
|
@employee = TestSerializeEmployee.new(
|
930
|
-
:
|
931
|
-
:
|
770
|
+
first_name: "First",
|
771
|
+
comments: nil
|
932
772
|
)
|
933
773
|
expect(@employee.comments).to be_nil
|
934
774
|
expect(@employee.save).to eq(true)
|
@@ -944,9 +784,9 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
944
784
|
|
945
785
|
it "should create record with CLOB data" do
|
946
786
|
@employee = TestEmployee.create!(
|
947
|
-
:
|
948
|
-
:
|
949
|
-
:
|
787
|
+
first_name: "First",
|
788
|
+
last_name: "Last",
|
789
|
+
comments: @char_data
|
950
790
|
)
|
951
791
|
@employee.reload
|
952
792
|
expect(@employee.comments).to eq(@char_data)
|
@@ -954,8 +794,8 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
954
794
|
|
955
795
|
it "should update record with CLOB data" do
|
956
796
|
@employee = TestEmployee.create!(
|
957
|
-
:
|
958
|
-
:
|
797
|
+
first_name: "First",
|
798
|
+
last_name: "Last"
|
959
799
|
)
|
960
800
|
@employee.reload
|
961
801
|
expect(@employee.comments).to be_nil
|
@@ -967,22 +807,22 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
967
807
|
|
968
808
|
it "should update record with zero-length CLOB data" do
|
969
809
|
@employee = TestEmployee.create!(
|
970
|
-
:
|
971
|
-
:
|
810
|
+
first_name: "First",
|
811
|
+
last_name: "Last"
|
972
812
|
)
|
973
813
|
@employee.reload
|
974
814
|
expect(@employee.comments).to be_nil
|
975
|
-
@employee.comments =
|
815
|
+
@employee.comments = ""
|
976
816
|
@employee.save!
|
977
817
|
@employee.reload
|
978
|
-
expect(@employee.comments).to eq(
|
818
|
+
expect(@employee.comments).to eq("")
|
979
819
|
end
|
980
820
|
|
981
821
|
it "should update record that has existing CLOB data with different CLOB data" do
|
982
822
|
@employee = TestEmployee.create!(
|
983
|
-
:
|
984
|
-
:
|
985
|
-
:
|
823
|
+
first_name: "First",
|
824
|
+
last_name: "Last",
|
825
|
+
comments: @char_data
|
986
826
|
)
|
987
827
|
@employee.reload
|
988
828
|
@employee.comments = @char_data2
|
@@ -993,9 +833,9 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
993
833
|
|
994
834
|
it "should update record that has existing CLOB data with nil" do
|
995
835
|
@employee = TestEmployee.create!(
|
996
|
-
:
|
997
|
-
:
|
998
|
-
:
|
836
|
+
first_name: "First",
|
837
|
+
last_name: "Last",
|
838
|
+
comments: @char_data
|
999
839
|
)
|
1000
840
|
@employee.reload
|
1001
841
|
@employee.comments = nil
|
@@ -1006,25 +846,25 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
1006
846
|
|
1007
847
|
it "should update record that has existing CLOB data with zero-length CLOB data" do
|
1008
848
|
@employee = TestEmployee.create!(
|
1009
|
-
:
|
1010
|
-
:
|
1011
|
-
:
|
849
|
+
first_name: "First",
|
850
|
+
last_name: "Last",
|
851
|
+
comments: @char_data
|
1012
852
|
)
|
1013
853
|
@employee.reload
|
1014
|
-
@employee.comments =
|
854
|
+
@employee.comments = ""
|
1015
855
|
@employee.save!
|
1016
856
|
@employee.reload
|
1017
|
-
expect(@employee.comments).to eq(
|
857
|
+
expect(@employee.comments).to eq("")
|
1018
858
|
end
|
1019
859
|
|
1020
860
|
it "should update record that has zero-length CLOB data with non-empty CLOB data" do
|
1021
861
|
@employee = TestEmployee.create!(
|
1022
|
-
:
|
1023
|
-
:
|
1024
|
-
:
|
862
|
+
first_name: "First",
|
863
|
+
last_name: "Last",
|
864
|
+
comments: ""
|
1025
865
|
)
|
1026
866
|
@employee.reload
|
1027
|
-
expect(@employee.comments).to eq(
|
867
|
+
expect(@employee.comments).to eq("")
|
1028
868
|
@employee.comments = @char_data
|
1029
869
|
@employee.save!
|
1030
870
|
@employee.reload
|
@@ -1032,10 +872,10 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
1032
872
|
end
|
1033
873
|
|
1034
874
|
it "should store serializable ruby data structures" do
|
1035
|
-
ruby_data1 = {"arbitrary1" => ["ruby", :data, 123]}
|
1036
|
-
ruby_data2 = {"arbitrary2" => ["ruby", :data, 123]}
|
875
|
+
ruby_data1 = { "arbitrary1" => ["ruby", :data, 123] }
|
876
|
+
ruby_data2 = { "arbitrary2" => ["ruby", :data, 123] }
|
1037
877
|
@employee = Test2Employee.create!(
|
1038
|
-
:
|
878
|
+
comments: ruby_data1
|
1039
879
|
)
|
1040
880
|
@employee.reload
|
1041
881
|
expect(@employee.comments).to eq(ruby_data1)
|
@@ -1047,9 +887,9 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
1047
887
|
|
1048
888
|
it "should keep unchanged serialized data when other columns changed" do
|
1049
889
|
@employee = Test2Employee.create!(
|
1050
|
-
:
|
1051
|
-
:
|
1052
|
-
:
|
890
|
+
first_name: "First",
|
891
|
+
last_name: "Last",
|
892
|
+
comments: "initial serialized data"
|
1053
893
|
)
|
1054
894
|
@employee.first_name = "Steve"
|
1055
895
|
@employee.save
|
@@ -1059,14 +899,14 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
1059
899
|
|
1060
900
|
it "should keep serialized data after save" do
|
1061
901
|
@employee = Test2Employee.new
|
1062
|
-
@employee.comments = {:
|
902
|
+
@employee.comments = { length: { is: 1 } }
|
1063
903
|
@employee.save
|
1064
904
|
@employee.reload
|
1065
|
-
expect(@employee.comments).to eq(
|
1066
|
-
@employee.comments = {:
|
905
|
+
expect(@employee.comments).to eq(length: { is: 1 })
|
906
|
+
@employee.comments = { length: { is: 2 } }
|
1067
907
|
@employee.save
|
1068
908
|
@employee.reload
|
1069
|
-
expect(@employee.comments).to eq(
|
909
|
+
expect(@employee.comments).to eq(length: { is: 2 })
|
1070
910
|
end
|
1071
911
|
end
|
1072
912
|
|
@@ -1086,8 +926,8 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
1086
926
|
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
1087
927
|
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
1088
928
|
SQL
|
1089
|
-
@binary_data = "\0\1\2\3\4\5\6\7\8\9"*10000
|
1090
|
-
@binary_data2 = "\1\2\3\4\5\6\7\8\9\0"*10000
|
929
|
+
@binary_data = "\0\1\2\3\4\5\6\7\8\9" * 10000
|
930
|
+
@binary_data2 = "\1\2\3\4\5\6\7\8\9\0" * 10000
|
1091
931
|
end
|
1092
932
|
|
1093
933
|
after(:all) do
|
@@ -1103,14 +943,14 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
1103
943
|
|
1104
944
|
after(:each) do
|
1105
945
|
Object.send(:remove_const, "TestEmployee")
|
1106
|
-
ActiveRecord::Base.clear_cache!
|
946
|
+
ActiveRecord::Base.clear_cache!
|
1107
947
|
end
|
1108
948
|
|
1109
949
|
it "should create record with BLOB data" do
|
1110
950
|
@employee = TestEmployee.create!(
|
1111
|
-
:
|
1112
|
-
:
|
1113
|
-
:
|
951
|
+
first_name: "First",
|
952
|
+
last_name: "Last",
|
953
|
+
binary_data: @binary_data
|
1114
954
|
)
|
1115
955
|
@employee.reload
|
1116
956
|
expect(@employee.binary_data).to eq(@binary_data)
|
@@ -1118,8 +958,8 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
1118
958
|
|
1119
959
|
it "should update record with BLOB data" do
|
1120
960
|
@employee = TestEmployee.create!(
|
1121
|
-
:
|
1122
|
-
:
|
961
|
+
first_name: "First",
|
962
|
+
last_name: "Last"
|
1123
963
|
)
|
1124
964
|
@employee.reload
|
1125
965
|
expect(@employee.binary_data).to be_nil
|
@@ -1131,22 +971,22 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
1131
971
|
|
1132
972
|
it "should update record with zero-length BLOB data" do
|
1133
973
|
@employee = TestEmployee.create!(
|
1134
|
-
:
|
1135
|
-
:
|
974
|
+
first_name: "First",
|
975
|
+
last_name: "Last"
|
1136
976
|
)
|
1137
977
|
@employee.reload
|
1138
978
|
expect(@employee.binary_data).to be_nil
|
1139
|
-
@employee.binary_data =
|
979
|
+
@employee.binary_data = ""
|
1140
980
|
@employee.save!
|
1141
981
|
@employee.reload
|
1142
|
-
expect(@employee.binary_data).to eq(
|
982
|
+
expect(@employee.binary_data).to eq("")
|
1143
983
|
end
|
1144
984
|
|
1145
985
|
it "should update record that has existing BLOB data with different BLOB data" do
|
1146
986
|
@employee = TestEmployee.create!(
|
1147
|
-
:
|
1148
|
-
:
|
1149
|
-
:
|
987
|
+
first_name: "First",
|
988
|
+
last_name: "Last",
|
989
|
+
binary_data: @binary_data
|
1150
990
|
)
|
1151
991
|
@employee.reload
|
1152
992
|
@employee.binary_data = @binary_data2
|
@@ -1157,9 +997,9 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
1157
997
|
|
1158
998
|
it "should update record that has existing BLOB data with nil" do
|
1159
999
|
@employee = TestEmployee.create!(
|
1160
|
-
:
|
1161
|
-
:
|
1162
|
-
:
|
1000
|
+
first_name: "First",
|
1001
|
+
last_name: "Last",
|
1002
|
+
binary_data: @binary_data
|
1163
1003
|
)
|
1164
1004
|
@employee.reload
|
1165
1005
|
@employee.binary_data = nil
|
@@ -1170,25 +1010,25 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
1170
1010
|
|
1171
1011
|
it "should update record that has existing BLOB data with zero-length BLOB data" do
|
1172
1012
|
@employee = TestEmployee.create!(
|
1173
|
-
:
|
1174
|
-
:
|
1175
|
-
:
|
1013
|
+
first_name: "First",
|
1014
|
+
last_name: "Last",
|
1015
|
+
binary_data: @binary_data
|
1176
1016
|
)
|
1177
1017
|
@employee.reload
|
1178
|
-
@employee.binary_data =
|
1018
|
+
@employee.binary_data = ""
|
1179
1019
|
@employee.save!
|
1180
1020
|
@employee.reload
|
1181
|
-
expect(@employee.binary_data).to eq(
|
1021
|
+
expect(@employee.binary_data).to eq("")
|
1182
1022
|
end
|
1183
1023
|
|
1184
1024
|
it "should update record that has zero-length BLOB data with non-empty BLOB data" do
|
1185
1025
|
@employee = TestEmployee.create!(
|
1186
|
-
:
|
1187
|
-
:
|
1188
|
-
:
|
1026
|
+
first_name: "First",
|
1027
|
+
last_name: "Last",
|
1028
|
+
binary_data: ""
|
1189
1029
|
)
|
1190
1030
|
@employee.reload
|
1191
|
-
expect(@employee.binary_data).to eq(
|
1031
|
+
expect(@employee.binary_data).to eq("")
|
1192
1032
|
@employee.binary_data = @binary_data
|
1193
1033
|
@employee.save!
|
1194
1034
|
@employee.reload
|
@@ -1197,46 +1037,42 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
|
|
1197
1037
|
end
|
1198
1038
|
|
1199
1039
|
describe "OracleEnhancedAdapter handling of RAW columns" do
|
1040
|
+
include SchemaSpecHelper
|
1041
|
+
|
1200
1042
|
before(:all) do
|
1201
1043
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
@conn.execute <<-SQL
|
1212
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
1213
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
1214
|
-
SQL
|
1215
|
-
@binary_data = "\0\1\2\3\4\5\6\7\8\9"*100
|
1216
|
-
@binary_data2 = "\1\2\3\4\5\6\7\8\9\0"*100
|
1044
|
+
schema_define do
|
1045
|
+
create_table :test_employees, force: true do |t|
|
1046
|
+
t.string :first_name, limit: 20
|
1047
|
+
t.string :last_name, limit: 25
|
1048
|
+
t.raw :binary_data, limit: 1024
|
1049
|
+
end
|
1050
|
+
end
|
1051
|
+
@binary_data = "\0\1\2\3\4\5\6\7\8\9" * 100
|
1052
|
+
@binary_data2 = "\1\2\3\4\5\6\7\8\9\0" * 100
|
1217
1053
|
end
|
1218
1054
|
|
1219
1055
|
after(:all) do
|
1220
|
-
|
1221
|
-
|
1056
|
+
schema_define do
|
1057
|
+
drop_table :test_employees
|
1058
|
+
end
|
1222
1059
|
end
|
1223
1060
|
|
1224
1061
|
before(:each) do
|
1225
1062
|
class ::TestEmployee < ActiveRecord::Base
|
1226
|
-
self.primary_key = "employee_id"
|
1227
1063
|
end
|
1228
1064
|
end
|
1229
1065
|
|
1230
1066
|
after(:each) do
|
1231
1067
|
Object.send(:remove_const, "TestEmployee")
|
1232
|
-
ActiveRecord::Base.clear_cache!
|
1068
|
+
ActiveRecord::Base.clear_cache!
|
1233
1069
|
end
|
1234
1070
|
|
1235
1071
|
it "should create record with RAW data" do
|
1236
1072
|
@employee = TestEmployee.create!(
|
1237
|
-
:
|
1238
|
-
:
|
1239
|
-
:
|
1073
|
+
first_name: "First",
|
1074
|
+
last_name: "Last",
|
1075
|
+
binary_data: @binary_data
|
1240
1076
|
)
|
1241
1077
|
@employee.reload
|
1242
1078
|
expect(@employee.binary_data).to eq(@binary_data)
|
@@ -1244,8 +1080,8 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
1244
1080
|
|
1245
1081
|
it "should update record with RAW data" do
|
1246
1082
|
@employee = TestEmployee.create!(
|
1247
|
-
:
|
1248
|
-
:
|
1083
|
+
first_name: "First",
|
1084
|
+
last_name: "Last"
|
1249
1085
|
)
|
1250
1086
|
@employee.reload
|
1251
1087
|
expect(@employee.binary_data).to be_nil
|
@@ -1257,12 +1093,12 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
1257
1093
|
|
1258
1094
|
it "should update record with zero-length RAW data" do
|
1259
1095
|
@employee = TestEmployee.create!(
|
1260
|
-
:
|
1261
|
-
:
|
1096
|
+
first_name: "First",
|
1097
|
+
last_name: "Last"
|
1262
1098
|
)
|
1263
1099
|
@employee.reload
|
1264
1100
|
expect(@employee.binary_data).to be_nil
|
1265
|
-
@employee.binary_data =
|
1101
|
+
@employee.binary_data = ""
|
1266
1102
|
@employee.save!
|
1267
1103
|
@employee.reload
|
1268
1104
|
expect(@employee.binary_data).to be_nil
|
@@ -1270,9 +1106,9 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
1270
1106
|
|
1271
1107
|
it "should update record that has existing RAW data with different RAW data" do
|
1272
1108
|
@employee = TestEmployee.create!(
|
1273
|
-
:
|
1274
|
-
:
|
1275
|
-
:
|
1109
|
+
first_name: "First",
|
1110
|
+
last_name: "Last",
|
1111
|
+
binary_data: @binary_data
|
1276
1112
|
)
|
1277
1113
|
@employee.reload
|
1278
1114
|
@employee.binary_data = @binary_data2
|
@@ -1283,9 +1119,9 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
1283
1119
|
|
1284
1120
|
it "should update record that has existing RAW data with nil" do
|
1285
1121
|
@employee = TestEmployee.create!(
|
1286
|
-
:
|
1287
|
-
:
|
1288
|
-
:
|
1122
|
+
first_name: "First",
|
1123
|
+
last_name: "Last",
|
1124
|
+
binary_data: @binary_data
|
1289
1125
|
)
|
1290
1126
|
@employee.reload
|
1291
1127
|
@employee.binary_data = nil
|
@@ -1296,12 +1132,12 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
1296
1132
|
|
1297
1133
|
it "should update record that has existing RAW data with zero-length RAW data" do
|
1298
1134
|
@employee = TestEmployee.create!(
|
1299
|
-
:
|
1300
|
-
:
|
1301
|
-
:
|
1135
|
+
first_name: "First",
|
1136
|
+
last_name: "Last",
|
1137
|
+
binary_data: @binary_data
|
1302
1138
|
)
|
1303
1139
|
@employee.reload
|
1304
|
-
@employee.binary_data =
|
1140
|
+
@employee.binary_data = ""
|
1305
1141
|
@employee.save!
|
1306
1142
|
@employee.reload
|
1307
1143
|
expect(@employee.binary_data).to be_nil
|
@@ -1309,9 +1145,9 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
1309
1145
|
|
1310
1146
|
it "should update record that has zero-length BLOB data with non-empty RAW data" do
|
1311
1147
|
@employee = TestEmployee.create!(
|
1312
|
-
:
|
1313
|
-
:
|
1314
|
-
:
|
1148
|
+
first_name: "First",
|
1149
|
+
last_name: "Last",
|
1150
|
+
binary_data: ""
|
1315
1151
|
)
|
1316
1152
|
@employee.reload
|
1317
1153
|
@employee.binary_data = @binary_data
|
@@ -1349,25 +1185,27 @@ describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
|
|
1349
1185
|
|
1350
1186
|
after(:each) do
|
1351
1187
|
Object.send(:remove_const, "TestItem")
|
1352
|
-
ActiveRecord::Base.clear_cache!
|
1188
|
+
ActiveRecord::Base.clear_cache!
|
1353
1189
|
end
|
1354
1190
|
|
1355
1191
|
it "should quote with N prefix" do
|
1356
|
-
columns = @conn.columns(
|
1192
|
+
columns = @conn.columns("test_items")
|
1357
1193
|
%w(nchar_column nvarchar2_column char_column varchar2_column).each do |col|
|
1358
|
-
column = columns.detect{|c| c.name == col}
|
1359
|
-
|
1360
|
-
expect(@conn.quote(
|
1194
|
+
column = columns.detect { |c| c.name == col }
|
1195
|
+
value = @conn.type_cast_from_column(column, "abc")
|
1196
|
+
expect(@conn.quote(value)).to eq(column.sql_type[0, 1] == "N" ? "N'abc'" : "'abc'")
|
1197
|
+
nilvalue = @conn.type_cast_from_column(column, nil)
|
1198
|
+
expect(@conn.quote(nilvalue)).to eq("NULL")
|
1361
1199
|
end
|
1362
1200
|
end
|
1363
1201
|
|
1364
1202
|
it "should create record" do
|
1365
|
-
nchar_data =
|
1203
|
+
nchar_data = "āčē"
|
1366
1204
|
item = TestItem.create(
|
1367
|
-
:
|
1368
|
-
:
|
1205
|
+
nchar_column: nchar_data,
|
1206
|
+
nvarchar2_column: nchar_data
|
1369
1207
|
).reload
|
1370
|
-
expect(item.nchar_column).to eq(nchar_data +
|
1208
|
+
expect(item.nchar_column).to eq(nchar_data + " " * 17)
|
1371
1209
|
expect(item.nvarchar2_column).to eq(nchar_data)
|
1372
1210
|
end
|
1373
1211
|
|
@@ -1414,8 +1252,8 @@ describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
|
|
1414
1252
|
end
|
1415
1253
|
|
1416
1254
|
it "should set BINARY_FLOAT column type as float" do
|
1417
|
-
columns = @conn.columns(
|
1418
|
-
column = columns.detect{|c| c.name == "hourly_rate"}
|
1255
|
+
columns = @conn.columns("test2_employees")
|
1256
|
+
column = columns.detect { |c| c.name == "hourly_rate" }
|
1419
1257
|
expect(column.type).to eq(:float)
|
1420
1258
|
end
|
1421
1259
|
|
@@ -1427,3 +1265,58 @@ describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
|
|
1427
1265
|
expect(employee.hourly_rate).to eq(4.400000095367432)
|
1428
1266
|
end
|
1429
1267
|
end
|
1268
|
+
|
1269
|
+
describe "OracleEnhancedAdapter attribute API support for JSON type" do
|
1270
|
+
|
1271
|
+
include SchemaSpecHelper
|
1272
|
+
|
1273
|
+
before(:all) do
|
1274
|
+
@conn = ActiveRecord::Base.connection
|
1275
|
+
@oracle12c_or_higher = !! @conn.select_value(
|
1276
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 12")
|
1277
|
+
skip "Not supported in this database version" unless @oracle12c_or_higher
|
1278
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
1279
|
+
schema_define do
|
1280
|
+
create_table :test_posts, force: true do |t|
|
1281
|
+
t.string :title
|
1282
|
+
t.text :article
|
1283
|
+
end
|
1284
|
+
execute "alter table test_posts add constraint test_posts_title_is_json check (title is json)"
|
1285
|
+
execute "alter table test_posts add constraint test_posts_article_is_json check (article is json)"
|
1286
|
+
end
|
1287
|
+
|
1288
|
+
class ::TestPost < ActiveRecord::Base
|
1289
|
+
attribute :title, :json
|
1290
|
+
attribute :article, :json
|
1291
|
+
end
|
1292
|
+
end
|
1293
|
+
|
1294
|
+
after(:all) do
|
1295
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
1296
|
+
schema_define do
|
1297
|
+
drop_table :test_posts, if_exists: true
|
1298
|
+
end
|
1299
|
+
end
|
1300
|
+
|
1301
|
+
before(:each) do
|
1302
|
+
TestPost.delete_all
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
it "should support attribute api for JSON" do
|
1306
|
+
post = TestPost.create!(title: { "publish" => true, "foo" => "bar" }, article: { "bar" => "baz" })
|
1307
|
+
post.reload
|
1308
|
+
expect(post.title).to eq ({ "publish" => true, "foo" => "bar" })
|
1309
|
+
expect(post.article).to eq ({ "bar" => "baz" })
|
1310
|
+
post.title = ({ "publish" => false, "foo" => "bar2" })
|
1311
|
+
post.save
|
1312
|
+
expect(post.reload.title).to eq ({ "publish" => false, "foo" => "bar2" })
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
it "should support IS JSON" do
|
1316
|
+
post = TestPost.create!(title: { "publish" => true, "foo" => "bar" })
|
1317
|
+
count_json = TestPost.where("title is json")
|
1318
|
+
expect(count_json.size).to eq 1
|
1319
|
+
count_non_json = TestPost.where("title is not json")
|
1320
|
+
expect(count_non_json.size).to eq 0
|
1321
|
+
end
|
1322
|
+
end
|