activerecord-oracle_enhanced-adapter 1.7.3 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +288 -0
- data/README.md +44 -0
- 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 -63
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -52
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +13 -16
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -119
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +33 -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 +59 -77
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +56 -82
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +77 -77
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +16 -45
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -65
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -51
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +149 -162
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +119 -122
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +69 -107
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +315 -538
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -11
- data/lib/active_record/oracle_enhanced/type/integer.rb +4 -5
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -2
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -4
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -4
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +14 -13
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +129 -166
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +50 -33
- 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 +283 -378
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -7
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +5 -7
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +118 -127
- 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 +74 -78
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +68 -83
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +308 -321
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +103 -48
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -60
- 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 -50
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -95
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -21
- 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
|
|
@@ -171,7 +141,7 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
|
171
141
|
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
|
172
142
|
SQL
|
|
173
143
|
end
|
|
174
|
-
|
|
144
|
+
|
|
175
145
|
after(:all) do
|
|
176
146
|
@conn.execute "DROP TABLE test2_employees"
|
|
177
147
|
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
|
@@ -182,84 +152,74 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
|
182
152
|
class ::Test2Employee < ActiveRecord::Base
|
|
183
153
|
end
|
|
184
154
|
end
|
|
185
|
-
|
|
155
|
+
|
|
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
|
-
it "should return
|
|
210
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
|
178
|
+
it "should return Integer value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
|
|
211
179
|
class ::Test2Employee < ActiveRecord::Base
|
|
212
180
|
attribute :job_id, :integer
|
|
213
181
|
end
|
|
214
182
|
create_employee2
|
|
215
|
-
expect(@employee2.job_id
|
|
183
|
+
expect(@employee2.job_id).to be_a(Integer)
|
|
216
184
|
end
|
|
217
185
|
|
|
218
|
-
it "should return
|
|
219
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
|
186
|
+
it "should return Integer value from NUMBER column with integer value using _before_type_cast method" do
|
|
220
187
|
create_employee2
|
|
221
|
-
expect(@employee2.job_id_before_type_cast
|
|
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
|
-
it "should return
|
|
231
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = false
|
|
232
|
-
# Test2Employee.set_integer_columns :job_id
|
|
196
|
+
it "should return Integer value from NUMBER column if column specified in set_integer_columns" do
|
|
233
197
|
class ::Test2Employee < ActiveRecord::Base
|
|
234
198
|
attribute :job_id, :integer
|
|
235
199
|
end
|
|
236
200
|
create_employee2
|
|
237
|
-
expect(@employee2.job_id
|
|
201
|
+
expect(@employee2.job_id).to be_a(Integer)
|
|
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
|
-
it "should return
|
|
247
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = false
|
|
209
|
+
it "should return Integer value from NUMBER(1) column if emulate booleans is not used" do
|
|
248
210
|
class ::Test2Employee < ActiveRecord::Base
|
|
249
211
|
attribute :is_manager, :integer
|
|
250
212
|
end
|
|
251
213
|
create_employee2
|
|
252
|
-
expect(@employee2.is_manager
|
|
214
|
+
expect(@employee2.is_manager).to be_a(Integer)
|
|
253
215
|
end
|
|
254
216
|
|
|
255
|
-
it "should return
|
|
256
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
|
|
257
|
-
# Test2Employee.set_integer_columns :is_manager
|
|
217
|
+
it "should return Integer value from NUMBER(1) column if column specified in set_integer_columns" do
|
|
258
218
|
class ::Test2Employee < ActiveRecord::Base
|
|
259
219
|
attribute :is_manager, :integer
|
|
260
220
|
end
|
|
261
221
|
create_employee2
|
|
262
|
-
expect(@employee2.is_manager
|
|
222
|
+
expect(@employee2.is_manager).to be_a(Integer)
|
|
263
223
|
end
|
|
264
224
|
|
|
265
225
|
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
|
|
@@ -440,11 +397,13 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
|
440
397
|
end
|
|
441
398
|
|
|
442
399
|
describe "OracleEnhancedAdapter boolean support when emulate_booleans_from_strings = true" do
|
|
400
|
+
include SchemaSpecHelper
|
|
401
|
+
|
|
443
402
|
before(:all) do
|
|
444
403
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
|
445
404
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
446
|
-
|
|
447
|
-
create_table :posts, :
|
|
405
|
+
schema_define do
|
|
406
|
+
create_table :posts, force: true do |t|
|
|
448
407
|
t.string :name, null: false
|
|
449
408
|
t.boolean :is_default, default: false
|
|
450
409
|
end
|
|
@@ -466,7 +425,7 @@ describe "OracleEnhancedAdapter boolean support when emulate_booleans_from_strin
|
|
|
466
425
|
end
|
|
467
426
|
|
|
468
427
|
it "boolean should not change after reload" do
|
|
469
|
-
post = Post.create(name:
|
|
428
|
+
post = Post.create(name: "Test 1", is_default: false)
|
|
470
429
|
expect(post.is_default).to be false
|
|
471
430
|
post.reload
|
|
472
431
|
expect(post.is_default).to be false
|
|
@@ -475,7 +434,8 @@ end
|
|
|
475
434
|
|
|
476
435
|
describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
477
436
|
before(:all) do
|
|
478
|
-
ActiveRecord::Base.
|
|
437
|
+
ActiveRecord::Base.default_timezone = :local
|
|
438
|
+
ActiveRecord::Base.establish_connection(CONNECTION_WITH_TIMEZONE_PARAMS)
|
|
479
439
|
@conn = ActiveRecord::Base.connection
|
|
480
440
|
@conn.execute <<-SQL
|
|
481
441
|
CREATE TABLE test_employees (
|
|
@@ -504,13 +464,7 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
|
504
464
|
after(:all) do
|
|
505
465
|
@conn.execute "DROP TABLE test_employees"
|
|
506
466
|
@conn.execute "DROP SEQUENCE test_employees_seq"
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
it "should set TIMESTAMP columns type as datetime" do
|
|
510
|
-
skip "TIMESTAMP sql_type should be :datetime in Rails 5"
|
|
511
|
-
columns = @conn.columns('test_employees')
|
|
512
|
-
ts_columns = columns.select{|c| c.name =~ /created_at/}
|
|
513
|
-
ts_columns.each {|c| expect(c.type).to eq(:timestamp)}
|
|
467
|
+
ActiveRecord::Base.default_timezone = :utc
|
|
514
468
|
end
|
|
515
469
|
|
|
516
470
|
describe "/ TIMESTAMP WITH TIME ZONE values from ActiveRecord model" do
|
|
@@ -518,21 +472,19 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
|
518
472
|
class ::TestEmployee < ActiveRecord::Base
|
|
519
473
|
self.primary_key = "employee_id"
|
|
520
474
|
end
|
|
521
|
-
ActiveRecord::Base.default_timezone = :local
|
|
522
475
|
end
|
|
523
476
|
|
|
524
477
|
after(:all) do
|
|
525
478
|
Object.send(:remove_const, "TestEmployee")
|
|
526
|
-
ActiveRecord::Base.clear_cache!
|
|
527
|
-
ActiveRecord::Base.default_timezone = :utc
|
|
479
|
+
ActiveRecord::Base.clear_cache!
|
|
528
480
|
end
|
|
529
481
|
|
|
530
482
|
it "should return Time value from TIMESTAMP columns" do
|
|
531
|
-
@now = Time.local(2008,5,26,23,11,11,0)
|
|
483
|
+
@now = Time.local(2008, 5, 26, 23, 11, 11, 0)
|
|
532
484
|
@employee = TestEmployee.create(
|
|
533
|
-
:
|
|
534
|
-
:
|
|
535
|
-
:
|
|
485
|
+
created_at: @now,
|
|
486
|
+
created_at_tz: @now,
|
|
487
|
+
created_at_ltz: @now
|
|
536
488
|
)
|
|
537
489
|
@employee.reload
|
|
538
490
|
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
|
@@ -542,11 +494,11 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
|
542
494
|
end
|
|
543
495
|
|
|
544
496
|
it "should return Time value with fractional seconds from TIMESTAMP columns" do
|
|
545
|
-
@now = Time.local(2008,5,26,23,11,11,10)
|
|
497
|
+
@now = Time.local(2008, 5, 26, 23, 11, 11, 10)
|
|
546
498
|
@employee = TestEmployee.create(
|
|
547
|
-
:
|
|
548
|
-
:
|
|
549
|
-
:
|
|
499
|
+
created_at: @now,
|
|
500
|
+
created_at_tz: @now,
|
|
501
|
+
created_at_ltz: @now
|
|
550
502
|
)
|
|
551
503
|
@employee.reload
|
|
552
504
|
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
|
@@ -559,106 +511,6 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
|
559
511
|
|
|
560
512
|
end
|
|
561
513
|
|
|
562
|
-
|
|
563
|
-
describe "OracleEnhancedAdapter date and timestamp with different NLS date formats" do
|
|
564
|
-
before(:all) do
|
|
565
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
566
|
-
@conn = ActiveRecord::Base.connection
|
|
567
|
-
@conn.execute <<-SQL
|
|
568
|
-
CREATE TABLE test_employees (
|
|
569
|
-
employee_id NUMBER(6,0) PRIMARY KEY,
|
|
570
|
-
first_name VARCHAR2(20),
|
|
571
|
-
last_name VARCHAR2(25),
|
|
572
|
-
email VARCHAR2(25),
|
|
573
|
-
phone_number VARCHAR2(20),
|
|
574
|
-
hire_date DATE,
|
|
575
|
-
job_id NUMBER(6,0),
|
|
576
|
-
salary NUMBER(8,2),
|
|
577
|
-
commission_pct NUMBER(2,2),
|
|
578
|
-
manager_id NUMBER(6,0),
|
|
579
|
-
department_id NUMBER(4,0),
|
|
580
|
-
created_at DATE,
|
|
581
|
-
created_at_ts TIMESTAMP
|
|
582
|
-
)
|
|
583
|
-
SQL
|
|
584
|
-
@conn.execute <<-SQL
|
|
585
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
|
586
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
|
587
|
-
SQL
|
|
588
|
-
# @conn.execute %q{alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'}
|
|
589
|
-
@conn.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
|
|
590
|
-
# @conn.execute %q{alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'}
|
|
591
|
-
@conn.execute %q{alter session set nls_timestamp_format = 'DD-MON-YYYY HH24:MI:SS'}
|
|
592
|
-
end
|
|
593
|
-
|
|
594
|
-
after(:all) do
|
|
595
|
-
@conn.execute "DROP TABLE test_employees"
|
|
596
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
|
597
|
-
end
|
|
598
|
-
|
|
599
|
-
before(:each) do
|
|
600
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
|
|
601
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
|
602
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
603
|
-
self.primary_key = "employee_id"
|
|
604
|
-
end
|
|
605
|
-
@today = Date.new(2008,6,28)
|
|
606
|
-
@now = Time.local(2008,6,28,13,34,33)
|
|
607
|
-
end
|
|
608
|
-
|
|
609
|
-
after(:each) do
|
|
610
|
-
Object.send(:remove_const, "TestEmployee")
|
|
611
|
-
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
|
612
|
-
ActiveRecord::Base.default_timezone = :utc
|
|
613
|
-
end
|
|
614
|
-
|
|
615
|
-
def create_test_employee
|
|
616
|
-
@employee = TestEmployee.create(
|
|
617
|
-
:first_name => "First",
|
|
618
|
-
:last_name => "Last",
|
|
619
|
-
:hire_date => @today,
|
|
620
|
-
:created_at => @now,
|
|
621
|
-
:created_at_ts => @now
|
|
622
|
-
)
|
|
623
|
-
@employee.reload
|
|
624
|
-
end
|
|
625
|
-
|
|
626
|
-
it "should return Time value from DATE column if emulate_dates_by_column_name is false" do
|
|
627
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
|
628
|
-
ActiveRecord::Base.default_timezone = :local
|
|
629
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
630
|
-
attribute :hire_date, :datetime
|
|
631
|
-
end
|
|
632
|
-
create_test_employee
|
|
633
|
-
expect(@employee.hire_date.class).to eq(Time)
|
|
634
|
-
expect(@employee.hire_date).to eq(@today.to_time)
|
|
635
|
-
end
|
|
636
|
-
|
|
637
|
-
it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
|
638
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
|
639
|
-
create_test_employee
|
|
640
|
-
expect(@employee.hire_date.class).to eq(Date)
|
|
641
|
-
expect(@employee.hire_date).to eq(@today)
|
|
642
|
-
end
|
|
643
|
-
|
|
644
|
-
it "should return Time value from DATE column if column name does not contain 'date' and emulate_dates_by_column_name is true" do
|
|
645
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
|
646
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
647
|
-
attribute :created_at, :datetime
|
|
648
|
-
end
|
|
649
|
-
create_test_employee
|
|
650
|
-
expect(@employee.created_at.class).to eq(Time)
|
|
651
|
-
expect(@employee.created_at).to eq(@now)
|
|
652
|
-
end
|
|
653
|
-
|
|
654
|
-
it "should return Time value from TIMESTAMP columns" do
|
|
655
|
-
create_test_employee
|
|
656
|
-
expect(@employee.created_at_ts.class).to eq(Time)
|
|
657
|
-
expect(@employee.created_at_ts).to eq(@now)
|
|
658
|
-
end
|
|
659
|
-
|
|
660
|
-
end
|
|
661
|
-
|
|
662
514
|
describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
663
515
|
before(:all) do
|
|
664
516
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
@@ -681,11 +533,11 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
681
533
|
self.primary_key = "employee_id"
|
|
682
534
|
attribute :last_login_at, :datetime
|
|
683
535
|
end
|
|
684
|
-
@today = Date.new(2008,6,28)
|
|
536
|
+
@today = Date.new(2008, 6, 28)
|
|
685
537
|
@today_iso = "2008-06-28"
|
|
686
538
|
@today_nls = "28.06.2008"
|
|
687
539
|
@nls_date_format = "%d.%m.%Y"
|
|
688
|
-
@now = Time.local(2008,6,28,13,34,33)
|
|
540
|
+
@now = Time.local(2008, 6, 28, 13, 34, 33)
|
|
689
541
|
@now_iso = "2008-06-28 13:34:33"
|
|
690
542
|
@now_nls = "28.06.2008 13:34:33"
|
|
691
543
|
@nls_time_format = "%d.%m.%Y %H:%M:%S"
|
|
@@ -698,11 +550,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
698
550
|
Object.send(:remove_const, "TestEmployee")
|
|
699
551
|
@conn.execute "DROP TABLE test_employees"
|
|
700
552
|
@conn.execute "DROP SEQUENCE test_employees_seq"
|
|
701
|
-
ActiveRecord::Base.clear_cache!
|
|
702
|
-
end
|
|
703
|
-
|
|
704
|
-
before(:each) do
|
|
705
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
|
553
|
+
ActiveRecord::Base.clear_cache!
|
|
706
554
|
end
|
|
707
555
|
|
|
708
556
|
after(:each) do
|
|
@@ -711,9 +559,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
711
559
|
|
|
712
560
|
it "should assign ISO string to date column" do
|
|
713
561
|
@employee = TestEmployee.create(
|
|
714
|
-
:
|
|
715
|
-
:
|
|
716
|
-
:
|
|
562
|
+
first_name: "First",
|
|
563
|
+
last_name: "Last",
|
|
564
|
+
hire_date: @today_iso
|
|
717
565
|
)
|
|
718
566
|
expect(@employee.hire_date).to eq(@today)
|
|
719
567
|
@employee.reload
|
|
@@ -721,11 +569,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
721
569
|
end
|
|
722
570
|
|
|
723
571
|
it "should assign NLS string to date column" do
|
|
724
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
|
725
572
|
@employee = TestEmployee.create(
|
|
726
|
-
:
|
|
727
|
-
:
|
|
728
|
-
:
|
|
573
|
+
first_name: "First",
|
|
574
|
+
last_name: "Last",
|
|
575
|
+
hire_date: @today_nls
|
|
729
576
|
)
|
|
730
577
|
expect(@employee.hire_date).to eq(@today)
|
|
731
578
|
@employee.reload
|
|
@@ -734,9 +581,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
734
581
|
|
|
735
582
|
it "should assign ISO time string to date column" do
|
|
736
583
|
@employee = TestEmployee.create(
|
|
737
|
-
:
|
|
738
|
-
:
|
|
739
|
-
:
|
|
584
|
+
first_name: "First",
|
|
585
|
+
last_name: "Last",
|
|
586
|
+
hire_date: @now_iso
|
|
740
587
|
)
|
|
741
588
|
expect(@employee.hire_date).to eq(@today)
|
|
742
589
|
@employee.reload
|
|
@@ -744,12 +591,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
744
591
|
end
|
|
745
592
|
|
|
746
593
|
it "should assign NLS time string to date column" do
|
|
747
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
|
748
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
|
749
594
|
@employee = TestEmployee.create(
|
|
750
|
-
:
|
|
751
|
-
:
|
|
752
|
-
:
|
|
595
|
+
first_name: "First",
|
|
596
|
+
last_name: "Last",
|
|
597
|
+
hire_date: @now_nls
|
|
753
598
|
)
|
|
754
599
|
expect(@employee.hire_date).to eq(@today)
|
|
755
600
|
@employee.reload
|
|
@@ -759,9 +604,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
759
604
|
it "should assign ISO time string to datetime column" do
|
|
760
605
|
ActiveRecord::Base.default_timezone = :local
|
|
761
606
|
@employee = TestEmployee.create(
|
|
762
|
-
:
|
|
763
|
-
:
|
|
764
|
-
:
|
|
607
|
+
first_name: "First",
|
|
608
|
+
last_name: "Last",
|
|
609
|
+
last_login_at: @now_iso
|
|
765
610
|
)
|
|
766
611
|
expect(@employee.last_login_at).to eq(@now)
|
|
767
612
|
@employee.reload
|
|
@@ -770,11 +615,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
770
615
|
|
|
771
616
|
it "should assign NLS time string to datetime column" do
|
|
772
617
|
ActiveRecord::Base.default_timezone = :local
|
|
773
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
|
774
618
|
@employee = TestEmployee.create(
|
|
775
|
-
:
|
|
776
|
-
:
|
|
777
|
-
:
|
|
619
|
+
first_name: "First",
|
|
620
|
+
last_name: "Last",
|
|
621
|
+
last_login_at: @now_nls
|
|
778
622
|
)
|
|
779
623
|
expect(@employee.last_login_at).to eq(@now)
|
|
780
624
|
@employee.reload
|
|
@@ -782,11 +626,10 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
782
626
|
end
|
|
783
627
|
|
|
784
628
|
it "should assign NLS time string with time zone to datetime column" do
|
|
785
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_with_tz_time_format
|
|
786
629
|
@employee = TestEmployee.create(
|
|
787
|
-
:
|
|
788
|
-
:
|
|
789
|
-
:
|
|
630
|
+
first_name: "First",
|
|
631
|
+
last_name: "Last",
|
|
632
|
+
last_login_at: @now_nls_with_tz
|
|
790
633
|
)
|
|
791
634
|
expect(@employee.last_login_at).to eq(@now_with_tz)
|
|
792
635
|
@employee.reload
|
|
@@ -796,9 +639,9 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
796
639
|
it "should assign ISO date string to datetime column" do
|
|
797
640
|
ActiveRecord::Base.default_timezone = :local
|
|
798
641
|
@employee = TestEmployee.create(
|
|
799
|
-
:
|
|
800
|
-
:
|
|
801
|
-
:
|
|
642
|
+
first_name: "First",
|
|
643
|
+
last_name: "Last",
|
|
644
|
+
last_login_at: @today_iso
|
|
802
645
|
)
|
|
803
646
|
expect(@employee.last_login_at).to eq(@today.to_time)
|
|
804
647
|
@employee.reload
|
|
@@ -807,18 +650,16 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
|
807
650
|
|
|
808
651
|
it "should assign NLS date string to datetime column" do
|
|
809
652
|
ActiveRecord::Base.default_timezone = :local
|
|
810
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
|
811
|
-
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
|
812
653
|
@employee = TestEmployee.create(
|
|
813
|
-
:
|
|
814
|
-
:
|
|
815
|
-
:
|
|
654
|
+
first_name: "First",
|
|
655
|
+
last_name: "Last",
|
|
656
|
+
last_login_at: @today_nls
|
|
816
657
|
)
|
|
817
658
|
expect(@employee.last_login_at).to eq(@today.to_time)
|
|
818
659
|
@employee.reload
|
|
819
660
|
expect(@employee.last_login_at).to eq(@today.to_time)
|
|
820
661
|
end
|
|
821
|
-
|
|
662
|
+
|
|
822
663
|
end
|
|
823
664
|
|
|
824
665
|
describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
@@ -890,13 +731,13 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
|
890
731
|
Object.send(:remove_const, "Test2Employee")
|
|
891
732
|
Object.send(:remove_const, "TestEmployeeReadOnlyClob")
|
|
892
733
|
Object.send(:remove_const, "TestSerializeEmployee")
|
|
893
|
-
ActiveRecord::Base.clear_cache!
|
|
734
|
+
ActiveRecord::Base.clear_cache!
|
|
894
735
|
end
|
|
895
736
|
|
|
896
737
|
it "should create record without CLOB data when attribute is serialized" do
|
|
897
738
|
@employee = Test2Employee.create!(
|
|
898
|
-
:
|
|
899
|
-
:
|
|
739
|
+
first_name: "First",
|
|
740
|
+
last_name: "Last"
|
|
900
741
|
)
|
|
901
742
|
expect(@employee).to be_valid
|
|
902
743
|
@employee.reload
|
|
@@ -905,29 +746,29 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
|
905
746
|
|
|
906
747
|
it "should accept Symbol value for CLOB column" do
|
|
907
748
|
@employee = TestEmployee.create!(
|
|
908
|
-
:
|
|
749
|
+
comments: :test_comment
|
|
909
750
|
)
|
|
910
751
|
expect(@employee).to be_valid
|
|
911
752
|
end
|
|
912
753
|
|
|
913
754
|
it "should respect attr_readonly setting for CLOB column" do
|
|
914
755
|
@employee = TestEmployeeReadOnlyClob.create!(
|
|
915
|
-
:
|
|
916
|
-
:
|
|
756
|
+
first_name: "First",
|
|
757
|
+
comments: "initial"
|
|
917
758
|
)
|
|
918
759
|
expect(@employee).to be_valid
|
|
919
760
|
@employee.reload
|
|
920
|
-
expect(@employee.comments).to eq(
|
|
761
|
+
expect(@employee.comments).to eq("initial")
|
|
921
762
|
@employee.comments = "changed"
|
|
922
763
|
expect(@employee.save).to eq(true)
|
|
923
764
|
@employee.reload
|
|
924
|
-
expect(@employee.comments).to eq(
|
|
765
|
+
expect(@employee.comments).to eq("initial")
|
|
925
766
|
end
|
|
926
767
|
|
|
927
768
|
it "should work for serialized readonly CLOB columns", serialized: true do
|
|
928
769
|
@employee = TestSerializeEmployee.new(
|
|
929
|
-
:
|
|
930
|
-
:
|
|
770
|
+
first_name: "First",
|
|
771
|
+
comments: nil
|
|
931
772
|
)
|
|
932
773
|
expect(@employee.comments).to be_nil
|
|
933
774
|
expect(@employee.save).to eq(true)
|
|
@@ -941,12 +782,11 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
|
941
782
|
expect(@employee.comments).to be_nil
|
|
942
783
|
end
|
|
943
784
|
|
|
944
|
-
|
|
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
|
|
@@ -1321,7 +1157,6 @@ describe "OracleEnhancedAdapter handling of RAW columns" do
|
|
|
1321
1157
|
end
|
|
1322
1158
|
end
|
|
1323
1159
|
|
|
1324
|
-
|
|
1325
1160
|
describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
|
|
1326
1161
|
before(:all) do
|
|
1327
1162
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
@@ -1350,25 +1185,27 @@ describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
|
|
|
1350
1185
|
|
|
1351
1186
|
after(:each) do
|
|
1352
1187
|
Object.send(:remove_const, "TestItem")
|
|
1353
|
-
ActiveRecord::Base.clear_cache!
|
|
1188
|
+
ActiveRecord::Base.clear_cache!
|
|
1354
1189
|
end
|
|
1355
1190
|
|
|
1356
1191
|
it "should quote with N prefix" do
|
|
1357
|
-
columns = @conn.columns(
|
|
1192
|
+
columns = @conn.columns("test_items")
|
|
1358
1193
|
%w(nchar_column nvarchar2_column char_column varchar2_column).each do |col|
|
|
1359
|
-
column = columns.detect{|c| c.name == col}
|
|
1360
|
-
|
|
1361
|
-
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")
|
|
1362
1199
|
end
|
|
1363
1200
|
end
|
|
1364
1201
|
|
|
1365
1202
|
it "should create record" do
|
|
1366
|
-
nchar_data =
|
|
1203
|
+
nchar_data = "āčē"
|
|
1367
1204
|
item = TestItem.create(
|
|
1368
|
-
:
|
|
1369
|
-
:
|
|
1205
|
+
nchar_column: nchar_data,
|
|
1206
|
+
nvarchar2_column: nchar_data
|
|
1370
1207
|
).reload
|
|
1371
|
-
expect(item.nchar_column).to eq(nchar_data +
|
|
1208
|
+
expect(item.nchar_column).to eq(nchar_data + " " * 17)
|
|
1372
1209
|
expect(item.nvarchar2_column).to eq(nchar_data)
|
|
1373
1210
|
end
|
|
1374
1211
|
|
|
@@ -1402,16 +1239,84 @@ describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
|
|
|
1402
1239
|
CREATE SEQUENCE test2_employees_seq MINVALUE 1
|
|
1403
1240
|
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
|
1404
1241
|
SQL
|
|
1242
|
+
|
|
1243
|
+
class ::Test2Employee < ActiveRecord::Base
|
|
1244
|
+
end
|
|
1405
1245
|
end
|
|
1406
|
-
|
|
1246
|
+
|
|
1407
1247
|
after(:all) do
|
|
1248
|
+
Object.send(:remove_const, "Test2Employee")
|
|
1249
|
+
|
|
1408
1250
|
@conn.execute "DROP TABLE test2_employees"
|
|
1409
1251
|
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
|
1410
1252
|
end
|
|
1411
1253
|
|
|
1412
1254
|
it "should set BINARY_FLOAT column type as float" do
|
|
1413
|
-
columns = @conn.columns(
|
|
1414
|
-
column = columns.detect{|c| c.name == "hourly_rate"}
|
|
1255
|
+
columns = @conn.columns("test2_employees")
|
|
1256
|
+
column = columns.detect { |c| c.name == "hourly_rate" }
|
|
1415
1257
|
expect(column.type).to eq(:float)
|
|
1416
1258
|
end
|
|
1259
|
+
|
|
1260
|
+
it "should BINARY_FLOAT column type returns an approximate value" do
|
|
1261
|
+
employee = Test2Employee.create(hourly_rate: 4.4)
|
|
1262
|
+
|
|
1263
|
+
employee.reload
|
|
1264
|
+
|
|
1265
|
+
expect(employee.hourly_rate).to eq(4.400000095367432)
|
|
1266
|
+
end
|
|
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
|
|
1417
1322
|
end
|