activerecord-oracle_enhanced-adapter 1.8.2 → 5.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.md +190 -5
- data/README.md +10 -10
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +9 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +84 -73
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +12 -12
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +52 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +35 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +59 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +379 -402
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +7 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +46 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +242 -247
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +9 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +3 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +25 -9
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +9 -6
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +10 -5
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +48 -51
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +261 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +2 -34
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +267 -222
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +33 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +136 -547
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/boolean.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/integer.rb +4 -2
- data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/national_character_string.rb +5 -3
- data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/raw.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/string.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/text.rb +4 -2
- data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/timestamptz.rb +4 -2
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -6
- data/spec/active_record/connection_adapters/{oracle_enhanced_emulate_oracle_adapter_spec.rb → emulation/oracle_adapter_spec.rb} +2 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_connection_spec.rb → oracle_enhanced/connection_spec.rb} +82 -38
- data/spec/active_record/connection_adapters/{oracle_enhanced_context_index_spec.rb → oracle_enhanced/context_index_spec.rb} +20 -16
- data/spec/active_record/connection_adapters/{oracle_enhanced_database_tasks_spec.rb → oracle_enhanced/database_tasks_spec.rb} +17 -5
- data/spec/active_record/connection_adapters/{oracle_enhanced_dbms_output_spec.rb → oracle_enhanced/dbms_output_spec.rb} +2 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_procedures_spec.rb → oracle_enhanced/procedures_spec.rb} +26 -33
- data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +196 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_schema_dump_spec.rb → oracle_enhanced/schema_dumper_spec.rb} +61 -90
- data/spec/active_record/connection_adapters/{oracle_enhanced_schema_statements_spec.rb → oracle_enhanced/schema_statements_spec.rb} +95 -28
- data/spec/active_record/connection_adapters/{oracle_enhanced_structure_dump_spec.rb → oracle_enhanced/structure_dump_spec.rb} +48 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +202 -331
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +15 -1106
- data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +207 -0
- data/spec/active_record/{connection_adapters/oracle_enhanced_dirty_spec.rb → oracle_enhanced/type/dirty_spec.rb} +3 -1
- data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
- data/spec/active_record/oracle_enhanced/type/integer_spec.rb +91 -0
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +57 -0
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
- data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
- data/spec/active_record/oracle_enhanced/type/raw_spec.rb +122 -0
- data/spec/active_record/oracle_enhanced/type/text_spec.rb +229 -0
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +75 -0
- data/spec/spec_helper.rb +15 -1
- data/spec/support/alter_system_set_open_cursors.sql +1 -0
- metadata +63 -48
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +0 -28
- data/lib/active_record/oracle_enhanced/type/json.rb +0 -8
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe "OracleEnhancedAdapter date and datetime type detection based on attribute settings" do
|
2
4
|
before(:all) do
|
3
5
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
4
6
|
@conn = ActiveRecord::Base.connection
|
@@ -52,41 +54,22 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
52
54
|
end
|
53
55
|
|
54
56
|
after(:each) do
|
55
|
-
# @employee.destroy if @employee
|
56
57
|
Object.send(:remove_const, "TestEmployee")
|
57
58
|
ActiveRecord::Base.clear_cache!
|
58
59
|
end
|
59
60
|
|
60
|
-
it "should return
|
61
|
-
class ::TestEmployee < ActiveRecord::Base
|
62
|
-
attribute :hire_date, :datetime
|
63
|
-
end
|
64
|
-
create_test_employee
|
65
|
-
expect(@employee.hire_date.class).to eq(Time)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return Date value from DATE column if column name contains 'date' and emulate_dates_by_column_name is true" do
|
61
|
+
it "should return Date value from DATE column by default" do
|
69
62
|
create_test_employee
|
70
63
|
expect(@employee.hire_date.class).to eq(Date)
|
71
64
|
end
|
72
65
|
|
73
|
-
it "should return Date value from DATE column with old date value
|
66
|
+
it "should return Date value from DATE column with old date value by default" do
|
74
67
|
create_test_employee(today: Date.new(1900, 1, 1))
|
75
68
|
expect(@employee.hire_date.class).to eq(Date)
|
76
69
|
end
|
77
70
|
|
78
|
-
it "should return Time value from DATE column if
|
71
|
+
it "should return Time value from DATE column if attribute is set to :datetime" do
|
79
72
|
class ::TestEmployee < ActiveRecord::Base
|
80
|
-
# set_date_columns :created_at
|
81
|
-
attribute :created_at, :datetime
|
82
|
-
end
|
83
|
-
create_test_employee
|
84
|
-
expect(@employee.created_at.class).to eq(Time)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should return Time value from DATE column if emulate_dates_by_column_name is true but column is defined as datetime" do
|
88
|
-
class ::TestEmployee < ActiveRecord::Base
|
89
|
-
# set_datetime_columns :hire_date
|
90
73
|
attribute :hire_date, :datetime
|
91
74
|
end
|
92
75
|
create_test_employee
|
@@ -98,439 +81,25 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
98
81
|
expect(@employee.hire_date.class).to eq(Time)
|
99
82
|
expect(@employee.hire_date).to eq(@now)
|
100
83
|
end
|
101
|
-
|
102
|
-
it "should guess Date or Time value if emulate_dates is true" do
|
103
|
-
class ::TestEmployee < ActiveRecord::Base
|
104
|
-
attribute :hire_date, :date
|
105
|
-
attribute :created_at, :datetime
|
106
|
-
end
|
107
|
-
create_test_employee
|
108
|
-
expect(@employee.hire_date.class).to eq(Date)
|
109
|
-
expect(@employee.created_at.class).to eq(Time)
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "OracleEnhancedAdapter integer type detection based on column names" do
|
117
|
-
before(:all) do
|
118
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
119
|
-
@conn = ActiveRecord::Base.connection
|
120
|
-
@conn.execute "DROP TABLE test2_employees" rescue nil
|
121
|
-
@conn.execute <<-SQL
|
122
|
-
CREATE TABLE test2_employees (
|
123
|
-
id NUMBER PRIMARY KEY,
|
124
|
-
first_name VARCHAR2(20),
|
125
|
-
last_name VARCHAR2(25),
|
126
|
-
email VARCHAR2(25),
|
127
|
-
phone_number VARCHAR2(20),
|
128
|
-
hire_date DATE,
|
129
|
-
job_id NUMBER,
|
130
|
-
salary NUMBER,
|
131
|
-
commission_pct NUMBER(2,2),
|
132
|
-
manager_id NUMBER(6),
|
133
|
-
is_manager NUMBER(1),
|
134
|
-
department_id NUMBER(4,0),
|
135
|
-
created_at DATE
|
136
|
-
)
|
137
|
-
SQL
|
138
|
-
@conn.execute "DROP SEQUENCE test2_employees_seq" rescue nil
|
139
|
-
@conn.execute <<-SQL
|
140
|
-
CREATE SEQUENCE test2_employees_seq MINVALUE 1
|
141
|
-
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
142
|
-
SQL
|
143
|
-
end
|
144
|
-
|
145
|
-
after(:all) do
|
146
|
-
@conn.execute "DROP TABLE test2_employees"
|
147
|
-
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "/ NUMBER values from ActiveRecord model" do
|
151
|
-
before(:each) do
|
152
|
-
class ::Test2Employee < ActiveRecord::Base
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
after(:each) do
|
157
|
-
Object.send(:remove_const, "Test2Employee")
|
158
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
|
159
|
-
ActiveRecord::Base.clear_cache!
|
160
|
-
end
|
161
|
-
|
162
|
-
def create_employee2
|
163
|
-
@employee2 = Test2Employee.create(
|
164
|
-
first_name: "First",
|
165
|
-
last_name: "Last",
|
166
|
-
job_id: 1,
|
167
|
-
is_manager: 1,
|
168
|
-
salary: 1000
|
169
|
-
)
|
170
|
-
@employee2.reload
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should return BigDecimal value from NUMBER column if emulate_integers_by_column_name is false" do
|
174
|
-
create_employee2
|
175
|
-
expect(@employee2.job_id.class).to eq(BigDecimal)
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should return Integer value from NUMBER column if column name contains 'id' and emulate_integers_by_column_name is true" do
|
179
|
-
class ::Test2Employee < ActiveRecord::Base
|
180
|
-
attribute :job_id, :integer
|
181
|
-
end
|
182
|
-
create_employee2
|
183
|
-
expect(@employee2.job_id).to be_a(Integer)
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should return Integer value from NUMBER column with integer value using _before_type_cast method" do
|
187
|
-
create_employee2
|
188
|
-
expect(@employee2.job_id_before_type_cast).to be_a(Integer)
|
189
|
-
end
|
190
|
-
|
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
|
192
|
-
create_employee2
|
193
|
-
expect(@employee2.salary.class).to eq(BigDecimal)
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should return Integer value from NUMBER column if column specified in set_integer_columns" do
|
197
|
-
class ::Test2Employee < ActiveRecord::Base
|
198
|
-
attribute :job_id, :integer
|
199
|
-
end
|
200
|
-
create_employee2
|
201
|
-
expect(@employee2.job_id).to be_a(Integer)
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should return Boolean value from NUMBER(1) column if emulate booleans is used" do
|
205
|
-
create_employee2
|
206
|
-
expect(@employee2.is_manager.class).to eq(TrueClass)
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should return Integer value from NUMBER(1) column if emulate booleans is not used" do
|
210
|
-
class ::Test2Employee < ActiveRecord::Base
|
211
|
-
attribute :is_manager, :integer
|
212
|
-
end
|
213
|
-
create_employee2
|
214
|
-
expect(@employee2.is_manager).to be_a(Integer)
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should return Integer value from NUMBER(1) column if column specified in set_integer_columns" do
|
218
|
-
class ::Test2Employee < ActiveRecord::Base
|
219
|
-
attribute :is_manager, :integer
|
220
|
-
end
|
221
|
-
create_employee2
|
222
|
-
expect(@employee2.is_manager).to be_a(Integer)
|
223
|
-
end
|
224
|
-
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
describe "OracleEnhancedAdapter boolean type detection based on string column types and names" do
|
230
|
-
before(:all) do
|
231
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
232
|
-
@conn = ActiveRecord::Base.connection
|
233
|
-
@conn.execute <<-SQL
|
234
|
-
CREATE TABLE test3_employees (
|
235
|
-
id NUMBER PRIMARY KEY,
|
236
|
-
first_name VARCHAR2(20),
|
237
|
-
last_name VARCHAR2(25),
|
238
|
-
email VARCHAR2(25),
|
239
|
-
phone_number VARCHAR2(20),
|
240
|
-
hire_date DATE,
|
241
|
-
job_id NUMBER,
|
242
|
-
salary NUMBER,
|
243
|
-
commission_pct NUMBER(2,2),
|
244
|
-
manager_id NUMBER(6),
|
245
|
-
department_id NUMBER(4,0),
|
246
|
-
created_at DATE,
|
247
|
-
has_email CHAR(1),
|
248
|
-
has_phone VARCHAR2(1) DEFAULT 'Y',
|
249
|
-
active_flag VARCHAR2(2),
|
250
|
-
manager_yn VARCHAR2(3) DEFAULT 'N',
|
251
|
-
test_boolean VARCHAR2(3)
|
252
|
-
)
|
253
|
-
SQL
|
254
|
-
@conn.execute <<-SQL
|
255
|
-
CREATE SEQUENCE test3_employees_seq MINVALUE 1
|
256
|
-
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
257
|
-
SQL
|
258
|
-
end
|
259
|
-
|
260
|
-
after(:all) do
|
261
|
-
@conn.execute "DROP TABLE test3_employees"
|
262
|
-
@conn.execute "DROP SEQUENCE test3_employees_seq"
|
263
|
-
end
|
264
|
-
|
265
|
-
before(:each) do
|
266
|
-
class ::Test3Employee < ActiveRecord::Base
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
after(:each) do
|
271
|
-
Object.send(:remove_const, "Test3Employee")
|
272
|
-
ActiveRecord::Base.clear_cache!
|
273
|
-
end
|
274
|
-
|
275
|
-
describe "default values in new records" do
|
276
|
-
context "when emulate_booleans_from_strings is false" do
|
277
|
-
before do
|
278
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
279
|
-
end
|
280
|
-
|
281
|
-
it "are Y or N" do
|
282
|
-
subject = Test3Employee.new
|
283
|
-
expect(subject.has_phone).to eq("Y")
|
284
|
-
expect(subject.manager_yn).to eq("N")
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
context "when emulate_booleans_from_strings is true" do
|
289
|
-
before do
|
290
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
291
|
-
end
|
292
|
-
|
293
|
-
it "are True or False" do
|
294
|
-
class ::Test3Employee < ActiveRecord::Base
|
295
|
-
attribute :has_phone, :boolean
|
296
|
-
attribute :manager_yn, :boolean, default: false
|
297
|
-
end
|
298
|
-
subject = Test3Employee.new
|
299
|
-
expect(subject.has_phone).to be_a(TrueClass)
|
300
|
-
expect(subject.manager_yn).to be_a(FalseClass)
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
it "should translate boolean type to NUMBER(1) if emulate_booleans_from_strings is false" do
|
306
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
307
|
-
sql_type = ActiveRecord::Base.connection.type_to_sql(:boolean)
|
308
|
-
expect(sql_type).to eq("NUMBER(1)")
|
309
|
-
end
|
310
|
-
|
311
|
-
describe "/ VARCHAR2 boolean values from ActiveRecord model" do
|
312
|
-
before(:each) do
|
313
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
314
|
-
end
|
315
|
-
|
316
|
-
after(:each) do
|
317
|
-
ActiveRecord::Base.clear_cache!
|
318
|
-
end
|
319
|
-
|
320
|
-
def create_employee3(params = {})
|
321
|
-
@employee3 = Test3Employee.create(
|
322
|
-
{
|
323
|
-
first_name: "First",
|
324
|
-
last_name: "Last",
|
325
|
-
has_email: true,
|
326
|
-
has_phone: false,
|
327
|
-
active_flag: true,
|
328
|
-
manager_yn: false
|
329
|
-
}.merge(params)
|
330
|
-
)
|
331
|
-
@employee3.reload
|
332
|
-
end
|
333
|
-
|
334
|
-
it "should return String value from VARCHAR2 boolean column if emulate_booleans_from_strings is false" do
|
335
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
336
|
-
create_employee3
|
337
|
-
%w(has_email has_phone active_flag manager_yn).each do |col|
|
338
|
-
expect(@employee3.send(col.to_sym).class).to eq(String)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
it "should return boolean value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
|
343
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
344
|
-
class ::Test3Employee < ActiveRecord::Base
|
345
|
-
attribute :has_email, :boolean
|
346
|
-
attribute :active_flag, :boolean
|
347
|
-
attribute :has_phone, :boolean, default: false
|
348
|
-
attribute :manager_yn, :boolean, default: false
|
349
|
-
end
|
350
|
-
create_employee3
|
351
|
-
%w(has_email active_flag).each do |col|
|
352
|
-
expect(@employee3.send(col.to_sym).class).to eq(TrueClass)
|
353
|
-
expect(@employee3.send((col + "_before_type_cast").to_sym)).to eq("Y")
|
354
|
-
end
|
355
|
-
%w(has_phone manager_yn).each do |col|
|
356
|
-
expect(@employee3.send(col.to_sym).class).to eq(FalseClass)
|
357
|
-
expect(@employee3.send((col + "_before_type_cast").to_sym)).to eq("N")
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
it "should return string value from VARCHAR2 column if it is not boolean column and emulate_booleans_from_strings is true" do
|
362
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
363
|
-
create_employee3
|
364
|
-
expect(@employee3.first_name.class).to eq(String)
|
365
|
-
end
|
366
|
-
|
367
|
-
it "should return boolean value from VARCHAR2 boolean column if column specified in set_boolean_columns" do
|
368
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
369
|
-
class ::Test3Employee < ActiveRecord::Base
|
370
|
-
attribute :test_boolean, :boolean
|
371
|
-
end
|
372
|
-
create_employee3(test_boolean: true)
|
373
|
-
expect(@employee3.test_boolean.class).to eq(TrueClass)
|
374
|
-
expect(@employee3.test_boolean_before_type_cast).to eq("Y")
|
375
|
-
create_employee3(test_boolean: false)
|
376
|
-
expect(@employee3.test_boolean.class).to eq(FalseClass)
|
377
|
-
expect(@employee3.test_boolean_before_type_cast).to eq("N")
|
378
|
-
create_employee3(test_boolean: nil)
|
379
|
-
expect(@employee3.test_boolean.class).to eq(NilClass)
|
380
|
-
expect(@employee3.test_boolean_before_type_cast).to eq(nil)
|
381
|
-
create_employee3(test_boolean: "")
|
382
|
-
expect(@employee3.test_boolean.class).to eq(NilClass)
|
383
|
-
expect(@employee3.test_boolean_before_type_cast).to eq(nil)
|
384
|
-
end
|
385
|
-
|
386
|
-
it "should return string value from VARCHAR2 column with boolean column name but is specified in set_string_columns" do
|
387
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
388
|
-
class ::Test3Employee < ActiveRecord::Base
|
389
|
-
attribute :active_flag, :string
|
390
|
-
end
|
391
|
-
create_employee3
|
392
|
-
expect(@employee3.active_flag.class).to eq(String)
|
393
|
-
end
|
394
|
-
|
395
84
|
end
|
396
|
-
|
397
85
|
end
|
398
86
|
|
399
|
-
describe "OracleEnhancedAdapter
|
87
|
+
describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
400
88
|
include SchemaSpecHelper
|
401
89
|
|
402
90
|
before(:all) do
|
403
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
404
91
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
405
|
-
schema_define do
|
406
|
-
create_table :posts, force: true do |t|
|
407
|
-
t.string :name, null: false
|
408
|
-
t.boolean :is_default, default: false
|
409
|
-
end
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
after(:all) do
|
414
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
415
|
-
end
|
416
|
-
|
417
|
-
before(:each) do
|
418
|
-
class ::Post < ActiveRecord::Base
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
after(:each) do
|
423
|
-
Object.send(:remove_const, "Post")
|
424
|
-
ActiveRecord::Base.clear_cache!
|
425
|
-
end
|
426
|
-
|
427
|
-
it "boolean should not change after reload" do
|
428
|
-
post = Post.create(name: "Test 1", is_default: false)
|
429
|
-
expect(post.is_default).to be false
|
430
|
-
post.reload
|
431
|
-
expect(post.is_default).to be false
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
describe "OracleEnhancedAdapter timestamp with timezone support" do
|
436
|
-
before(:all) do
|
437
|
-
ActiveRecord::Base.default_timezone = :local
|
438
|
-
ActiveRecord::Base.establish_connection(CONNECTION_WITH_TIMEZONE_PARAMS)
|
439
92
|
@conn = ActiveRecord::Base.connection
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
hire_date DATE,
|
448
|
-
job_id NUMBER(6,0),
|
449
|
-
salary NUMBER(8,2),
|
450
|
-
commission_pct NUMBER(2,2),
|
451
|
-
manager_id NUMBER(6,0),
|
452
|
-
department_id NUMBER(4,0),
|
453
|
-
created_at TIMESTAMP,
|
454
|
-
created_at_tz TIMESTAMP WITH TIME ZONE,
|
455
|
-
created_at_ltz TIMESTAMP WITH LOCAL TIME ZONE
|
456
|
-
)
|
457
|
-
SQL
|
458
|
-
@conn.execute <<-SQL
|
459
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
460
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
461
|
-
SQL
|
462
|
-
end
|
463
|
-
|
464
|
-
after(:all) do
|
465
|
-
@conn.execute "DROP TABLE test_employees"
|
466
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
467
|
-
ActiveRecord::Base.default_timezone = :utc
|
468
|
-
end
|
469
|
-
|
470
|
-
describe "/ TIMESTAMP WITH TIME ZONE values from ActiveRecord model" do
|
471
|
-
before(:all) do
|
472
|
-
class ::TestEmployee < ActiveRecord::Base
|
473
|
-
self.primary_key = "employee_id"
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
after(:all) do
|
478
|
-
Object.send(:remove_const, "TestEmployee")
|
479
|
-
ActiveRecord::Base.clear_cache!
|
480
|
-
end
|
481
|
-
|
482
|
-
it "should return Time value from TIMESTAMP columns" do
|
483
|
-
@now = Time.local(2008, 5, 26, 23, 11, 11, 0)
|
484
|
-
@employee = TestEmployee.create(
|
485
|
-
created_at: @now,
|
486
|
-
created_at_tz: @now,
|
487
|
-
created_at_ltz: @now
|
488
|
-
)
|
489
|
-
@employee.reload
|
490
|
-
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
491
|
-
expect(@employee.send(c).class).to eq(Time)
|
492
|
-
expect(@employee.send(c).to_f).to eq(@now.to_f)
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
it "should return Time value with fractional seconds from TIMESTAMP columns" do
|
497
|
-
@now = Time.local(2008, 5, 26, 23, 11, 11, 10)
|
498
|
-
@employee = TestEmployee.create(
|
499
|
-
created_at: @now,
|
500
|
-
created_at_tz: @now,
|
501
|
-
created_at_ltz: @now
|
502
|
-
)
|
503
|
-
@employee.reload
|
504
|
-
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
505
|
-
expect(@employee.send(c).class).to eq(Time)
|
506
|
-
expect(@employee.send(c).to_f).to eq(@now.to_f)
|
93
|
+
schema_define do
|
94
|
+
create_table :test_employees, force: true do |t|
|
95
|
+
t.string :first_name, limit: 20
|
96
|
+
t.string :last_name, limit: 25
|
97
|
+
t.date :hire_date
|
98
|
+
t.date :last_login_at
|
99
|
+
t.datetime :last_login_at_ts
|
507
100
|
end
|
508
101
|
end
|
509
|
-
|
510
|
-
end
|
511
|
-
|
512
|
-
end
|
513
|
-
|
514
|
-
describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
515
|
-
before(:all) do
|
516
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
517
|
-
@conn = ActiveRecord::Base.connection
|
518
|
-
@conn.execute <<-SQL
|
519
|
-
CREATE TABLE test_employees (
|
520
|
-
employee_id NUMBER(6,0) PRIMARY KEY,
|
521
|
-
first_name VARCHAR2(20),
|
522
|
-
last_name VARCHAR2(25),
|
523
|
-
hire_date DATE,
|
524
|
-
last_login_at DATE,
|
525
|
-
last_login_at_ts TIMESTAMP
|
526
|
-
)
|
527
|
-
SQL
|
528
|
-
@conn.execute <<-SQL
|
529
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
530
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
531
|
-
SQL
|
532
102
|
class ::TestEmployee < ActiveRecord::Base
|
533
|
-
self.primary_key = "employee_id"
|
534
103
|
attribute :last_login_at, :datetime
|
535
104
|
end
|
536
105
|
@today = Date.new(2008, 6, 28)
|
@@ -548,8 +117,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
548
117
|
|
549
118
|
after(:all) do
|
550
119
|
Object.send(:remove_const, "TestEmployee")
|
551
|
-
@conn.
|
552
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
120
|
+
@conn.drop_table :test_employees, if_exists: true
|
553
121
|
ActiveRecord::Base.clear_cache!
|
554
122
|
end
|
555
123
|
|
@@ -661,662 +229,3 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
661
229
|
end
|
662
230
|
|
663
231
|
end
|
664
|
-
|
665
|
-
describe "OracleEnhancedAdapter handling of CLOB columns" do
|
666
|
-
before(:all) do
|
667
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
668
|
-
@conn = ActiveRecord::Base.connection
|
669
|
-
@conn.execute <<-SQL
|
670
|
-
CREATE TABLE test_employees (
|
671
|
-
id NUMBER(6,0) PRIMARY KEY,
|
672
|
-
first_name VARCHAR2(20),
|
673
|
-
last_name VARCHAR2(25),
|
674
|
-
comments CLOB
|
675
|
-
)
|
676
|
-
SQL
|
677
|
-
@conn.execute <<-SQL
|
678
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
679
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
680
|
-
SQL
|
681
|
-
@conn.execute <<-SQL
|
682
|
-
CREATE TABLE test2_employees (
|
683
|
-
id NUMBER(6,0) PRIMARY KEY,
|
684
|
-
first_name VARCHAR2(20),
|
685
|
-
last_name VARCHAR2(25),
|
686
|
-
comments CLOB
|
687
|
-
)
|
688
|
-
SQL
|
689
|
-
@conn.execute <<-SQL
|
690
|
-
CREATE SEQUENCE test2_employees_seq MINVALUE 1
|
691
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
692
|
-
SQL
|
693
|
-
@conn.execute <<-SQL
|
694
|
-
CREATE TABLE test_serialize_employees (
|
695
|
-
id NUMBER(6,0) PRIMARY KEY,
|
696
|
-
first_name VARCHAR2(20),
|
697
|
-
last_name VARCHAR2(25)
|
698
|
-
)
|
699
|
-
SQL
|
700
|
-
@conn.execute <<-SQL
|
701
|
-
CREATE SEQUENCE test_serialize_employees_seq MINVALUE 1
|
702
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
703
|
-
SQL
|
704
|
-
ActiveRecord::Base.connection.add_column(:test_serialize_employees, :comments, :text)
|
705
|
-
|
706
|
-
@char_data = (0..127).to_a.pack("C*") * 800
|
707
|
-
@char_data2 = ((1..127).to_a.pack("C*") + "\0") * 800
|
708
|
-
|
709
|
-
class ::TestEmployee < ActiveRecord::Base; end
|
710
|
-
class ::Test2Employee < ActiveRecord::Base
|
711
|
-
serialize :comments
|
712
|
-
end
|
713
|
-
class ::TestEmployeeReadOnlyClob < ActiveRecord::Base
|
714
|
-
self.table_name = "test_employees"
|
715
|
-
attr_readonly :comments
|
716
|
-
end
|
717
|
-
class ::TestSerializeEmployee < ActiveRecord::Base
|
718
|
-
serialize :comments
|
719
|
-
attr_readonly :comments
|
720
|
-
end
|
721
|
-
end
|
722
|
-
|
723
|
-
after(:all) do
|
724
|
-
@conn.execute "DROP TABLE test_employees"
|
725
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
726
|
-
@conn.execute "DROP TABLE test2_employees"
|
727
|
-
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
728
|
-
@conn.execute "DROP TABLE test_serialize_employees"
|
729
|
-
@conn.execute "DROP SEQUENCE test_serialize_employees_seq"
|
730
|
-
Object.send(:remove_const, "TestEmployee")
|
731
|
-
Object.send(:remove_const, "Test2Employee")
|
732
|
-
Object.send(:remove_const, "TestEmployeeReadOnlyClob")
|
733
|
-
Object.send(:remove_const, "TestSerializeEmployee")
|
734
|
-
ActiveRecord::Base.clear_cache!
|
735
|
-
end
|
736
|
-
|
737
|
-
it "should create record without CLOB data when attribute is serialized" do
|
738
|
-
@employee = Test2Employee.create!(
|
739
|
-
first_name: "First",
|
740
|
-
last_name: "Last"
|
741
|
-
)
|
742
|
-
expect(@employee).to be_valid
|
743
|
-
@employee.reload
|
744
|
-
expect(@employee.comments).to be_nil
|
745
|
-
end
|
746
|
-
|
747
|
-
it "should accept Symbol value for CLOB column" do
|
748
|
-
@employee = TestEmployee.create!(
|
749
|
-
comments: :test_comment
|
750
|
-
)
|
751
|
-
expect(@employee).to be_valid
|
752
|
-
end
|
753
|
-
|
754
|
-
it "should respect attr_readonly setting for CLOB column" do
|
755
|
-
@employee = TestEmployeeReadOnlyClob.create!(
|
756
|
-
first_name: "First",
|
757
|
-
comments: "initial"
|
758
|
-
)
|
759
|
-
expect(@employee).to be_valid
|
760
|
-
@employee.reload
|
761
|
-
expect(@employee.comments).to eq("initial")
|
762
|
-
@employee.comments = "changed"
|
763
|
-
expect(@employee.save).to eq(true)
|
764
|
-
@employee.reload
|
765
|
-
expect(@employee.comments).to eq("initial")
|
766
|
-
end
|
767
|
-
|
768
|
-
it "should work for serialized readonly CLOB columns", serialized: true do
|
769
|
-
@employee = TestSerializeEmployee.new(
|
770
|
-
first_name: "First",
|
771
|
-
comments: nil
|
772
|
-
)
|
773
|
-
expect(@employee.comments).to be_nil
|
774
|
-
expect(@employee.save).to eq(true)
|
775
|
-
expect(@employee).to be_valid
|
776
|
-
@employee.reload
|
777
|
-
expect(@employee.comments).to be_nil
|
778
|
-
@employee.comments = {}
|
779
|
-
expect(@employee.save).to eq(true)
|
780
|
-
@employee.reload
|
781
|
-
#should not set readonly
|
782
|
-
expect(@employee.comments).to be_nil
|
783
|
-
end
|
784
|
-
|
785
|
-
it "should create record with CLOB data" do
|
786
|
-
@employee = TestEmployee.create!(
|
787
|
-
first_name: "First",
|
788
|
-
last_name: "Last",
|
789
|
-
comments: @char_data
|
790
|
-
)
|
791
|
-
@employee.reload
|
792
|
-
expect(@employee.comments).to eq(@char_data)
|
793
|
-
end
|
794
|
-
|
795
|
-
it "should update record with CLOB data" do
|
796
|
-
@employee = TestEmployee.create!(
|
797
|
-
first_name: "First",
|
798
|
-
last_name: "Last"
|
799
|
-
)
|
800
|
-
@employee.reload
|
801
|
-
expect(@employee.comments).to be_nil
|
802
|
-
@employee.comments = @char_data
|
803
|
-
@employee.save!
|
804
|
-
@employee.reload
|
805
|
-
expect(@employee.comments).to eq(@char_data)
|
806
|
-
end
|
807
|
-
|
808
|
-
it "should update record with zero-length CLOB data" do
|
809
|
-
@employee = TestEmployee.create!(
|
810
|
-
first_name: "First",
|
811
|
-
last_name: "Last"
|
812
|
-
)
|
813
|
-
@employee.reload
|
814
|
-
expect(@employee.comments).to be_nil
|
815
|
-
@employee.comments = ""
|
816
|
-
@employee.save!
|
817
|
-
@employee.reload
|
818
|
-
expect(@employee.comments).to eq("")
|
819
|
-
end
|
820
|
-
|
821
|
-
it "should update record that has existing CLOB data with different CLOB data" do
|
822
|
-
@employee = TestEmployee.create!(
|
823
|
-
first_name: "First",
|
824
|
-
last_name: "Last",
|
825
|
-
comments: @char_data
|
826
|
-
)
|
827
|
-
@employee.reload
|
828
|
-
@employee.comments = @char_data2
|
829
|
-
@employee.save!
|
830
|
-
@employee.reload
|
831
|
-
expect(@employee.comments).to eq(@char_data2)
|
832
|
-
end
|
833
|
-
|
834
|
-
it "should update record that has existing CLOB data with nil" do
|
835
|
-
@employee = TestEmployee.create!(
|
836
|
-
first_name: "First",
|
837
|
-
last_name: "Last",
|
838
|
-
comments: @char_data
|
839
|
-
)
|
840
|
-
@employee.reload
|
841
|
-
@employee.comments = nil
|
842
|
-
@employee.save!
|
843
|
-
@employee.reload
|
844
|
-
expect(@employee.comments).to be_nil
|
845
|
-
end
|
846
|
-
|
847
|
-
it "should update record that has existing CLOB data with zero-length CLOB data" do
|
848
|
-
@employee = TestEmployee.create!(
|
849
|
-
first_name: "First",
|
850
|
-
last_name: "Last",
|
851
|
-
comments: @char_data
|
852
|
-
)
|
853
|
-
@employee.reload
|
854
|
-
@employee.comments = ""
|
855
|
-
@employee.save!
|
856
|
-
@employee.reload
|
857
|
-
expect(@employee.comments).to eq("")
|
858
|
-
end
|
859
|
-
|
860
|
-
it "should update record that has zero-length CLOB data with non-empty CLOB data" do
|
861
|
-
@employee = TestEmployee.create!(
|
862
|
-
first_name: "First",
|
863
|
-
last_name: "Last",
|
864
|
-
comments: ""
|
865
|
-
)
|
866
|
-
@employee.reload
|
867
|
-
expect(@employee.comments).to eq("")
|
868
|
-
@employee.comments = @char_data
|
869
|
-
@employee.save!
|
870
|
-
@employee.reload
|
871
|
-
expect(@employee.comments).to eq(@char_data)
|
872
|
-
end
|
873
|
-
|
874
|
-
it "should store serializable ruby data structures" do
|
875
|
-
ruby_data1 = { "arbitrary1" => ["ruby", :data, 123] }
|
876
|
-
ruby_data2 = { "arbitrary2" => ["ruby", :data, 123] }
|
877
|
-
@employee = Test2Employee.create!(
|
878
|
-
comments: ruby_data1
|
879
|
-
)
|
880
|
-
@employee.reload
|
881
|
-
expect(@employee.comments).to eq(ruby_data1)
|
882
|
-
@employee.comments = ruby_data2
|
883
|
-
@employee.save
|
884
|
-
@employee.reload
|
885
|
-
expect(@employee.comments).to eq(ruby_data2)
|
886
|
-
end
|
887
|
-
|
888
|
-
it "should keep unchanged serialized data when other columns changed" do
|
889
|
-
@employee = Test2Employee.create!(
|
890
|
-
first_name: "First",
|
891
|
-
last_name: "Last",
|
892
|
-
comments: "initial serialized data"
|
893
|
-
)
|
894
|
-
@employee.first_name = "Steve"
|
895
|
-
@employee.save
|
896
|
-
@employee.reload
|
897
|
-
expect(@employee.comments).to eq("initial serialized data")
|
898
|
-
end
|
899
|
-
|
900
|
-
it "should keep serialized data after save" do
|
901
|
-
@employee = Test2Employee.new
|
902
|
-
@employee.comments = { length: { is: 1 } }
|
903
|
-
@employee.save
|
904
|
-
@employee.reload
|
905
|
-
expect(@employee.comments).to eq(length: { is: 1 })
|
906
|
-
@employee.comments = { length: { is: 2 } }
|
907
|
-
@employee.save
|
908
|
-
@employee.reload
|
909
|
-
expect(@employee.comments).to eq(length: { is: 2 })
|
910
|
-
end
|
911
|
-
end
|
912
|
-
|
913
|
-
describe "OracleEnhancedAdapter handling of BLOB columns" do
|
914
|
-
before(:all) do
|
915
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
916
|
-
@conn = ActiveRecord::Base.connection
|
917
|
-
@conn.execute <<-SQL
|
918
|
-
CREATE TABLE test_employees (
|
919
|
-
employee_id NUMBER(6,0) PRIMARY KEY,
|
920
|
-
first_name VARCHAR2(20),
|
921
|
-
last_name VARCHAR2(25),
|
922
|
-
binary_data BLOB
|
923
|
-
)
|
924
|
-
SQL
|
925
|
-
@conn.execute <<-SQL
|
926
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
927
|
-
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
928
|
-
SQL
|
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
|
931
|
-
end
|
932
|
-
|
933
|
-
after(:all) do
|
934
|
-
@conn.execute "DROP TABLE test_employees"
|
935
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
936
|
-
end
|
937
|
-
|
938
|
-
before(:each) do
|
939
|
-
class ::TestEmployee < ActiveRecord::Base
|
940
|
-
self.primary_key = "employee_id"
|
941
|
-
end
|
942
|
-
end
|
943
|
-
|
944
|
-
after(:each) do
|
945
|
-
Object.send(:remove_const, "TestEmployee")
|
946
|
-
ActiveRecord::Base.clear_cache!
|
947
|
-
end
|
948
|
-
|
949
|
-
it "should create record with BLOB data" do
|
950
|
-
@employee = TestEmployee.create!(
|
951
|
-
first_name: "First",
|
952
|
-
last_name: "Last",
|
953
|
-
binary_data: @binary_data
|
954
|
-
)
|
955
|
-
@employee.reload
|
956
|
-
expect(@employee.binary_data).to eq(@binary_data)
|
957
|
-
end
|
958
|
-
|
959
|
-
it "should update record with BLOB data" do
|
960
|
-
@employee = TestEmployee.create!(
|
961
|
-
first_name: "First",
|
962
|
-
last_name: "Last"
|
963
|
-
)
|
964
|
-
@employee.reload
|
965
|
-
expect(@employee.binary_data).to be_nil
|
966
|
-
@employee.binary_data = @binary_data
|
967
|
-
@employee.save!
|
968
|
-
@employee.reload
|
969
|
-
expect(@employee.binary_data).to eq(@binary_data)
|
970
|
-
end
|
971
|
-
|
972
|
-
it "should update record with zero-length BLOB data" do
|
973
|
-
@employee = TestEmployee.create!(
|
974
|
-
first_name: "First",
|
975
|
-
last_name: "Last"
|
976
|
-
)
|
977
|
-
@employee.reload
|
978
|
-
expect(@employee.binary_data).to be_nil
|
979
|
-
@employee.binary_data = ""
|
980
|
-
@employee.save!
|
981
|
-
@employee.reload
|
982
|
-
expect(@employee.binary_data).to eq("")
|
983
|
-
end
|
984
|
-
|
985
|
-
it "should update record that has existing BLOB data with different BLOB data" do
|
986
|
-
@employee = TestEmployee.create!(
|
987
|
-
first_name: "First",
|
988
|
-
last_name: "Last",
|
989
|
-
binary_data: @binary_data
|
990
|
-
)
|
991
|
-
@employee.reload
|
992
|
-
@employee.binary_data = @binary_data2
|
993
|
-
@employee.save!
|
994
|
-
@employee.reload
|
995
|
-
expect(@employee.binary_data).to eq(@binary_data2)
|
996
|
-
end
|
997
|
-
|
998
|
-
it "should update record that has existing BLOB data with nil" do
|
999
|
-
@employee = TestEmployee.create!(
|
1000
|
-
first_name: "First",
|
1001
|
-
last_name: "Last",
|
1002
|
-
binary_data: @binary_data
|
1003
|
-
)
|
1004
|
-
@employee.reload
|
1005
|
-
@employee.binary_data = nil
|
1006
|
-
@employee.save!
|
1007
|
-
@employee.reload
|
1008
|
-
expect(@employee.binary_data).to be_nil
|
1009
|
-
end
|
1010
|
-
|
1011
|
-
it "should update record that has existing BLOB data with zero-length BLOB data" do
|
1012
|
-
@employee = TestEmployee.create!(
|
1013
|
-
first_name: "First",
|
1014
|
-
last_name: "Last",
|
1015
|
-
binary_data: @binary_data
|
1016
|
-
)
|
1017
|
-
@employee.reload
|
1018
|
-
@employee.binary_data = ""
|
1019
|
-
@employee.save!
|
1020
|
-
@employee.reload
|
1021
|
-
expect(@employee.binary_data).to eq("")
|
1022
|
-
end
|
1023
|
-
|
1024
|
-
it "should update record that has zero-length BLOB data with non-empty BLOB data" do
|
1025
|
-
@employee = TestEmployee.create!(
|
1026
|
-
first_name: "First",
|
1027
|
-
last_name: "Last",
|
1028
|
-
binary_data: ""
|
1029
|
-
)
|
1030
|
-
@employee.reload
|
1031
|
-
expect(@employee.binary_data).to eq("")
|
1032
|
-
@employee.binary_data = @binary_data
|
1033
|
-
@employee.save!
|
1034
|
-
@employee.reload
|
1035
|
-
expect(@employee.binary_data).to eq(@binary_data)
|
1036
|
-
end
|
1037
|
-
end
|
1038
|
-
|
1039
|
-
describe "OracleEnhancedAdapter handling of RAW columns" do
|
1040
|
-
include SchemaSpecHelper
|
1041
|
-
|
1042
|
-
before(:all) do
|
1043
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
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
|
1053
|
-
end
|
1054
|
-
|
1055
|
-
after(:all) do
|
1056
|
-
schema_define do
|
1057
|
-
drop_table :test_employees
|
1058
|
-
end
|
1059
|
-
end
|
1060
|
-
|
1061
|
-
before(:each) do
|
1062
|
-
class ::TestEmployee < ActiveRecord::Base
|
1063
|
-
end
|
1064
|
-
end
|
1065
|
-
|
1066
|
-
after(:each) do
|
1067
|
-
Object.send(:remove_const, "TestEmployee")
|
1068
|
-
ActiveRecord::Base.clear_cache!
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
it "should create record with RAW data" do
|
1072
|
-
@employee = TestEmployee.create!(
|
1073
|
-
first_name: "First",
|
1074
|
-
last_name: "Last",
|
1075
|
-
binary_data: @binary_data
|
1076
|
-
)
|
1077
|
-
@employee.reload
|
1078
|
-
expect(@employee.binary_data).to eq(@binary_data)
|
1079
|
-
end
|
1080
|
-
|
1081
|
-
it "should update record with RAW data" do
|
1082
|
-
@employee = TestEmployee.create!(
|
1083
|
-
first_name: "First",
|
1084
|
-
last_name: "Last"
|
1085
|
-
)
|
1086
|
-
@employee.reload
|
1087
|
-
expect(@employee.binary_data).to be_nil
|
1088
|
-
@employee.binary_data = @binary_data
|
1089
|
-
@employee.save!
|
1090
|
-
@employee.reload
|
1091
|
-
expect(@employee.binary_data).to eq(@binary_data)
|
1092
|
-
end
|
1093
|
-
|
1094
|
-
it "should update record with zero-length RAW data" do
|
1095
|
-
@employee = TestEmployee.create!(
|
1096
|
-
first_name: "First",
|
1097
|
-
last_name: "Last"
|
1098
|
-
)
|
1099
|
-
@employee.reload
|
1100
|
-
expect(@employee.binary_data).to be_nil
|
1101
|
-
@employee.binary_data = ""
|
1102
|
-
@employee.save!
|
1103
|
-
@employee.reload
|
1104
|
-
expect(@employee.binary_data).to be_nil
|
1105
|
-
end
|
1106
|
-
|
1107
|
-
it "should update record that has existing RAW data with different RAW data" do
|
1108
|
-
@employee = TestEmployee.create!(
|
1109
|
-
first_name: "First",
|
1110
|
-
last_name: "Last",
|
1111
|
-
binary_data: @binary_data
|
1112
|
-
)
|
1113
|
-
@employee.reload
|
1114
|
-
@employee.binary_data = @binary_data2
|
1115
|
-
@employee.save!
|
1116
|
-
@employee.reload
|
1117
|
-
expect(@employee.binary_data).to eq(@binary_data2)
|
1118
|
-
end
|
1119
|
-
|
1120
|
-
it "should update record that has existing RAW data with nil" do
|
1121
|
-
@employee = TestEmployee.create!(
|
1122
|
-
first_name: "First",
|
1123
|
-
last_name: "Last",
|
1124
|
-
binary_data: @binary_data
|
1125
|
-
)
|
1126
|
-
@employee.reload
|
1127
|
-
@employee.binary_data = nil
|
1128
|
-
@employee.save!
|
1129
|
-
@employee.reload
|
1130
|
-
expect(@employee.binary_data).to be_nil
|
1131
|
-
end
|
1132
|
-
|
1133
|
-
it "should update record that has existing RAW data with zero-length RAW data" do
|
1134
|
-
@employee = TestEmployee.create!(
|
1135
|
-
first_name: "First",
|
1136
|
-
last_name: "Last",
|
1137
|
-
binary_data: @binary_data
|
1138
|
-
)
|
1139
|
-
@employee.reload
|
1140
|
-
@employee.binary_data = ""
|
1141
|
-
@employee.save!
|
1142
|
-
@employee.reload
|
1143
|
-
expect(@employee.binary_data).to be_nil
|
1144
|
-
end
|
1145
|
-
|
1146
|
-
it "should update record that has zero-length BLOB data with non-empty RAW data" do
|
1147
|
-
@employee = TestEmployee.create!(
|
1148
|
-
first_name: "First",
|
1149
|
-
last_name: "Last",
|
1150
|
-
binary_data: ""
|
1151
|
-
)
|
1152
|
-
@employee.reload
|
1153
|
-
@employee.binary_data = @binary_data
|
1154
|
-
@employee.save!
|
1155
|
-
@employee.reload
|
1156
|
-
expect(@employee.binary_data).to eq(@binary_data)
|
1157
|
-
end
|
1158
|
-
end
|
1159
|
-
|
1160
|
-
describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
|
1161
|
-
before(:all) do
|
1162
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
1163
|
-
@conn = ActiveRecord::Base.connection
|
1164
|
-
@conn.execute <<-SQL
|
1165
|
-
CREATE TABLE test_items (
|
1166
|
-
id NUMBER(6,0) PRIMARY KEY,
|
1167
|
-
nchar_column NCHAR(20),
|
1168
|
-
nvarchar2_column NVARCHAR2(20),
|
1169
|
-
char_column CHAR(20),
|
1170
|
-
varchar2_column VARCHAR2(20)
|
1171
|
-
)
|
1172
|
-
SQL
|
1173
|
-
@conn.execute "CREATE SEQUENCE test_items_seq"
|
1174
|
-
end
|
1175
|
-
|
1176
|
-
after(:all) do
|
1177
|
-
@conn.execute "DROP TABLE test_items"
|
1178
|
-
@conn.execute "DROP SEQUENCE test_items_seq"
|
1179
|
-
end
|
1180
|
-
|
1181
|
-
before(:each) do
|
1182
|
-
class ::TestItem < ActiveRecord::Base
|
1183
|
-
end
|
1184
|
-
end
|
1185
|
-
|
1186
|
-
after(:each) do
|
1187
|
-
Object.send(:remove_const, "TestItem")
|
1188
|
-
ActiveRecord::Base.clear_cache!
|
1189
|
-
end
|
1190
|
-
|
1191
|
-
it "should quote with N prefix" do
|
1192
|
-
columns = @conn.columns("test_items")
|
1193
|
-
%w(nchar_column nvarchar2_column char_column varchar2_column).each do |col|
|
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")
|
1199
|
-
end
|
1200
|
-
end
|
1201
|
-
|
1202
|
-
it "should create record" do
|
1203
|
-
nchar_data = "āčē"
|
1204
|
-
item = TestItem.create(
|
1205
|
-
nchar_column: nchar_data,
|
1206
|
-
nvarchar2_column: nchar_data
|
1207
|
-
).reload
|
1208
|
-
expect(item.nchar_column).to eq(nchar_data + " " * 17)
|
1209
|
-
expect(item.nvarchar2_column).to eq(nchar_data)
|
1210
|
-
end
|
1211
|
-
|
1212
|
-
end
|
1213
|
-
|
1214
|
-
describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
|
1215
|
-
before(:all) do
|
1216
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
1217
|
-
@conn = ActiveRecord::Base.connection
|
1218
|
-
@conn.execute "DROP TABLE test2_employees" rescue nil
|
1219
|
-
@conn.execute <<-SQL
|
1220
|
-
CREATE TABLE test2_employees (
|
1221
|
-
id NUMBER PRIMARY KEY,
|
1222
|
-
first_name VARCHAR2(20),
|
1223
|
-
last_name VARCHAR2(25),
|
1224
|
-
email VARCHAR2(25),
|
1225
|
-
phone_number VARCHAR2(20),
|
1226
|
-
hire_date DATE,
|
1227
|
-
job_id NUMBER,
|
1228
|
-
salary NUMBER,
|
1229
|
-
commission_pct NUMBER(2,2),
|
1230
|
-
hourly_rate BINARY_FLOAT,
|
1231
|
-
manager_id NUMBER(6),
|
1232
|
-
is_manager NUMBER(1),
|
1233
|
-
department_id NUMBER(4,0),
|
1234
|
-
created_at DATE
|
1235
|
-
)
|
1236
|
-
SQL
|
1237
|
-
@conn.execute "DROP SEQUENCE test2_employees_seq" rescue nil
|
1238
|
-
@conn.execute <<-SQL
|
1239
|
-
CREATE SEQUENCE test2_employees_seq MINVALUE 1
|
1240
|
-
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
1241
|
-
SQL
|
1242
|
-
|
1243
|
-
class ::Test2Employee < ActiveRecord::Base
|
1244
|
-
end
|
1245
|
-
end
|
1246
|
-
|
1247
|
-
after(:all) do
|
1248
|
-
Object.send(:remove_const, "Test2Employee")
|
1249
|
-
|
1250
|
-
@conn.execute "DROP TABLE test2_employees"
|
1251
|
-
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
1252
|
-
end
|
1253
|
-
|
1254
|
-
it "should set BINARY_FLOAT column type as float" do
|
1255
|
-
columns = @conn.columns("test2_employees")
|
1256
|
-
column = columns.detect { |c| c.name == "hourly_rate" }
|
1257
|
-
expect(column.type).to eq(:float)
|
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
|
1322
|
-
end
|