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
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe "OracleEnhancedAdapter handling of BLOB columns" do
|
4
|
+
include SchemaSpecHelper
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
8
|
+
@conn = ActiveRecord::Base.connection
|
9
|
+
schema_define do
|
10
|
+
create_table :test_employees, force: true do |t|
|
11
|
+
t.string :first_name, limit: 20
|
12
|
+
t.string :last_name, limit: 25
|
13
|
+
t.binary :binary_data
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class ::TestEmployee < ActiveRecord::Base
|
17
|
+
end
|
18
|
+
@binary_data = "\0\1\2\3\4\5\6\7\8\9" * 10000
|
19
|
+
@binary_data2 = "\1\2\3\4\5\6\7\8\9\0" * 10000
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:all) do
|
23
|
+
@conn.drop_table :test_employees, if_exists: true
|
24
|
+
Object.send(:remove_const, "TestEmployee")
|
25
|
+
end
|
26
|
+
|
27
|
+
after(:each) do
|
28
|
+
ActiveRecord::Base.clear_cache!
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should create record with BLOB data" do
|
32
|
+
@employee = TestEmployee.create!(
|
33
|
+
first_name: "First",
|
34
|
+
last_name: "Last",
|
35
|
+
binary_data: @binary_data
|
36
|
+
)
|
37
|
+
@employee.reload
|
38
|
+
expect(@employee.binary_data).to eq(@binary_data)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should update record with BLOB data" do
|
42
|
+
@employee = TestEmployee.create!(
|
43
|
+
first_name: "First",
|
44
|
+
last_name: "Last"
|
45
|
+
)
|
46
|
+
@employee.reload
|
47
|
+
expect(@employee.binary_data).to be_nil
|
48
|
+
@employee.binary_data = @binary_data
|
49
|
+
@employee.save!
|
50
|
+
@employee.reload
|
51
|
+
expect(@employee.binary_data).to eq(@binary_data)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should update record with zero-length BLOB data" do
|
55
|
+
@employee = TestEmployee.create!(
|
56
|
+
first_name: "First",
|
57
|
+
last_name: "Last"
|
58
|
+
)
|
59
|
+
@employee.reload
|
60
|
+
expect(@employee.binary_data).to be_nil
|
61
|
+
@employee.binary_data = ""
|
62
|
+
@employee.save!
|
63
|
+
@employee.reload
|
64
|
+
expect(@employee.binary_data).to eq("")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should update record that has existing BLOB data with different BLOB data" do
|
68
|
+
@employee = TestEmployee.create!(
|
69
|
+
first_name: "First",
|
70
|
+
last_name: "Last",
|
71
|
+
binary_data: @binary_data
|
72
|
+
)
|
73
|
+
@employee.reload
|
74
|
+
@employee.binary_data = @binary_data2
|
75
|
+
@employee.save!
|
76
|
+
@employee.reload
|
77
|
+
expect(@employee.binary_data).to eq(@binary_data2)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should update record that has existing BLOB data with nil" do
|
81
|
+
@employee = TestEmployee.create!(
|
82
|
+
first_name: "First",
|
83
|
+
last_name: "Last",
|
84
|
+
binary_data: @binary_data
|
85
|
+
)
|
86
|
+
@employee.reload
|
87
|
+
@employee.binary_data = nil
|
88
|
+
@employee.save!
|
89
|
+
@employee.reload
|
90
|
+
expect(@employee.binary_data).to be_nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should update record that has existing BLOB data with zero-length BLOB data" do
|
94
|
+
@employee = TestEmployee.create!(
|
95
|
+
first_name: "First",
|
96
|
+
last_name: "Last",
|
97
|
+
binary_data: @binary_data
|
98
|
+
)
|
99
|
+
@employee.reload
|
100
|
+
@employee.binary_data = ""
|
101
|
+
@employee.save!
|
102
|
+
@employee.reload
|
103
|
+
expect(@employee.binary_data).to eq("")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should update record that has zero-length BLOB data with non-empty BLOB data" do
|
107
|
+
@employee = TestEmployee.create!(
|
108
|
+
first_name: "First",
|
109
|
+
last_name: "Last",
|
110
|
+
binary_data: ""
|
111
|
+
)
|
112
|
+
@employee.reload
|
113
|
+
expect(@employee.binary_data).to eq("")
|
114
|
+
@employee.binary_data = @binary_data
|
115
|
+
@employee.save!
|
116
|
+
@employee.reload
|
117
|
+
expect(@employee.binary_data).to eq(@binary_data)
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe "OracleEnhancedAdapter boolean type detection based on string column types and names" do
|
4
|
+
before(:all) do
|
5
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
6
|
+
@conn = ActiveRecord::Base.connection
|
7
|
+
@conn.execute <<-SQL
|
8
|
+
CREATE TABLE test3_employees (
|
9
|
+
id NUMBER PRIMARY KEY,
|
10
|
+
first_name VARCHAR2(20),
|
11
|
+
last_name VARCHAR2(25),
|
12
|
+
email VARCHAR2(25),
|
13
|
+
phone_number VARCHAR2(20),
|
14
|
+
hire_date DATE,
|
15
|
+
job_id NUMBER,
|
16
|
+
salary NUMBER,
|
17
|
+
commission_pct NUMBER(2,2),
|
18
|
+
manager_id NUMBER(6),
|
19
|
+
department_id NUMBER(4,0),
|
20
|
+
created_at DATE,
|
21
|
+
has_email CHAR(1),
|
22
|
+
has_phone VARCHAR2(1) DEFAULT 'Y',
|
23
|
+
active_flag VARCHAR2(2),
|
24
|
+
manager_yn VARCHAR2(3) DEFAULT 'N',
|
25
|
+
test_boolean VARCHAR2(3)
|
26
|
+
)
|
27
|
+
SQL
|
28
|
+
@conn.execute <<-SQL
|
29
|
+
CREATE SEQUENCE test3_employees_seq MINVALUE 1
|
30
|
+
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
31
|
+
SQL
|
32
|
+
end
|
33
|
+
|
34
|
+
after(:all) do
|
35
|
+
@conn.execute "DROP TABLE test3_employees"
|
36
|
+
@conn.execute "DROP SEQUENCE test3_employees_seq"
|
37
|
+
end
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
class ::Test3Employee < ActiveRecord::Base
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
after(:each) do
|
45
|
+
Object.send(:remove_const, "Test3Employee")
|
46
|
+
ActiveRecord::Base.clear_cache!
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "default values in new records" do
|
50
|
+
context "when emulate_booleans_from_strings is false" do
|
51
|
+
before do
|
52
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
53
|
+
end
|
54
|
+
|
55
|
+
it "are Y or N" do
|
56
|
+
subject = Test3Employee.new
|
57
|
+
expect(subject.has_phone).to eq("Y")
|
58
|
+
expect(subject.manager_yn).to eq("N")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when emulate_booleans_from_strings is true" do
|
63
|
+
before do
|
64
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "are True or False" do
|
68
|
+
class ::Test3Employee < ActiveRecord::Base
|
69
|
+
attribute :has_phone, :boolean
|
70
|
+
attribute :manager_yn, :boolean, default: false
|
71
|
+
end
|
72
|
+
subject = Test3Employee.new
|
73
|
+
expect(subject.has_phone).to be_a(TrueClass)
|
74
|
+
expect(subject.manager_yn).to be_a(FalseClass)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should translate boolean type to NUMBER(1) if emulate_booleans_from_strings is false" do
|
80
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
81
|
+
sql_type = ActiveRecord::Base.connection.type_to_sql(:boolean)
|
82
|
+
expect(sql_type).to eq("NUMBER(1)")
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "/ VARCHAR2 boolean values from ActiveRecord model" do
|
86
|
+
before(:each) do
|
87
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
88
|
+
end
|
89
|
+
|
90
|
+
after(:each) do
|
91
|
+
ActiveRecord::Base.clear_cache!
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_employee3(params = {})
|
95
|
+
@employee3 = Test3Employee.create(
|
96
|
+
{
|
97
|
+
first_name: "First",
|
98
|
+
last_name: "Last",
|
99
|
+
has_email: true,
|
100
|
+
has_phone: false,
|
101
|
+
active_flag: true,
|
102
|
+
manager_yn: false
|
103
|
+
}.merge(params)
|
104
|
+
)
|
105
|
+
@employee3.reload
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return String value from VARCHAR2 boolean column if emulate_booleans_from_strings is false" do
|
109
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
110
|
+
create_employee3
|
111
|
+
%w(has_email has_phone active_flag manager_yn).each do |col|
|
112
|
+
expect(@employee3.send(col.to_sym).class).to eq(String)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should return boolean value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
|
117
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
118
|
+
class ::Test3Employee < ActiveRecord::Base
|
119
|
+
attribute :has_email, :boolean
|
120
|
+
attribute :active_flag, :boolean
|
121
|
+
attribute :has_phone, :boolean, default: false
|
122
|
+
attribute :manager_yn, :boolean, default: false
|
123
|
+
end
|
124
|
+
create_employee3
|
125
|
+
%w(has_email active_flag).each do |col|
|
126
|
+
expect(@employee3.send(col.to_sym).class).to eq(TrueClass)
|
127
|
+
expect(@employee3.send((col + "_before_type_cast").to_sym)).to eq("Y")
|
128
|
+
end
|
129
|
+
%w(has_phone manager_yn).each do |col|
|
130
|
+
expect(@employee3.send(col.to_sym).class).to eq(FalseClass)
|
131
|
+
expect(@employee3.send((col + "_before_type_cast").to_sym)).to eq("N")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return string value from VARCHAR2 column if it is not boolean column and emulate_booleans_from_strings is true" do
|
136
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
137
|
+
create_employee3
|
138
|
+
expect(@employee3.first_name.class).to eq(String)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return boolean value from VARCHAR2 boolean column if attribute is set to :boolean" do
|
142
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
143
|
+
class ::Test3Employee < ActiveRecord::Base
|
144
|
+
attribute :test_boolean, :boolean
|
145
|
+
end
|
146
|
+
create_employee3(test_boolean: true)
|
147
|
+
expect(@employee3.test_boolean.class).to eq(TrueClass)
|
148
|
+
expect(@employee3.test_boolean_before_type_cast).to eq("Y")
|
149
|
+
create_employee3(test_boolean: false)
|
150
|
+
expect(@employee3.test_boolean.class).to eq(FalseClass)
|
151
|
+
expect(@employee3.test_boolean_before_type_cast).to eq("N")
|
152
|
+
create_employee3(test_boolean: nil)
|
153
|
+
expect(@employee3.test_boolean.class).to eq(NilClass)
|
154
|
+
expect(@employee3.test_boolean_before_type_cast).to eq(nil)
|
155
|
+
create_employee3(test_boolean: "")
|
156
|
+
expect(@employee3.test_boolean.class).to eq(NilClass)
|
157
|
+
expect(@employee3.test_boolean_before_type_cast).to eq(nil)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should return string value from VARCHAR2 column with boolean column name but attribute is set to :string" do
|
161
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
162
|
+
class ::Test3Employee < ActiveRecord::Base
|
163
|
+
attribute :active_flag, :string
|
164
|
+
end
|
165
|
+
create_employee3
|
166
|
+
expect(@employee3.active_flag.class).to eq(String)
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "OracleEnhancedAdapter boolean support when emulate_booleans_from_strings = true" do
|
174
|
+
include SchemaSpecHelper
|
175
|
+
|
176
|
+
before(:all) do
|
177
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
178
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
179
|
+
schema_define do
|
180
|
+
create_table :posts, force: true do |t|
|
181
|
+
t.string :name, null: false
|
182
|
+
t.boolean :is_default, default: false
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
after(:all) do
|
188
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
189
|
+
end
|
190
|
+
|
191
|
+
before(:each) do
|
192
|
+
class ::Post < ActiveRecord::Base
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
after(:each) do
|
197
|
+
Object.send(:remove_const, "Post")
|
198
|
+
ActiveRecord::Base.clear_cache!
|
199
|
+
end
|
200
|
+
|
201
|
+
it "boolean should not change after reload" do
|
202
|
+
post = Post.create(name: "Test 1", is_default: false)
|
203
|
+
expect(post.is_default).to be false
|
204
|
+
post.reload
|
205
|
+
expect(post.is_default).to be false
|
206
|
+
end
|
207
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe "OracleEnhancedAdapter dirty object tracking" do
|
2
4
|
include SchemaSpecHelper
|
3
5
|
|
@@ -113,7 +115,7 @@ describe "OracleEnhancedAdapter dirty object tracking" do
|
|
113
115
|
@conn = nil
|
114
116
|
@connection = nil
|
115
117
|
@employee = TestEmployee.create!(
|
116
|
-
|
118
|
+
comments: "initial"
|
117
119
|
)
|
118
120
|
expect(@employee.save!).to be_truthy
|
119
121
|
@employee.reload
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe "OracleEnhancedAdapter handling of BINARY_FLOAT columns" do
|
4
|
+
include SchemaSpecHelper
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
8
|
+
@conn = ActiveRecord::Base.connection
|
9
|
+
schema_define do
|
10
|
+
create_table :test2_employees, force: true do |t|
|
11
|
+
t.string :first_name, limit: 20
|
12
|
+
t.string :last_name, limit: 25
|
13
|
+
t.string :email, limit: 25
|
14
|
+
t.string :phone_number, limit: 25
|
15
|
+
t.date :hire_date
|
16
|
+
t.integer :job_id
|
17
|
+
t.integer :salary
|
18
|
+
t.decimal :commission_pct, scale: 2, precision: 2
|
19
|
+
t.float :hourly_rate
|
20
|
+
t.integer :manager_id, limit: 6
|
21
|
+
t.integer :is_manager, limit: 1
|
22
|
+
t.decimal :department_id, scale: 0, precision: 4
|
23
|
+
t.timestamps
|
24
|
+
end
|
25
|
+
end
|
26
|
+
class ::Test2Employee < ActiveRecord::Base
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
after(:all) do
|
31
|
+
Object.send(:remove_const, "Test2Employee")
|
32
|
+
@conn.drop_table :test2_employees, if_exists: true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should set BINARY_FLOAT column type as float" do
|
36
|
+
columns = @conn.columns("test2_employees")
|
37
|
+
column = columns.detect { |c| c.name == "hourly_rate" }
|
38
|
+
expect(column.type).to eq(:float)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should BINARY_FLOAT column type returns an approximate value" do
|
42
|
+
employee = Test2Employee.create(hourly_rate: 4.4)
|
43
|
+
|
44
|
+
employee.reload
|
45
|
+
|
46
|
+
expect(employee.hourly_rate).to eq(4.400000095367432)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe "OracleEnhancedAdapter integer type detection based on attribute settings" do
|
4
|
+
before(:all) do
|
5
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
6
|
+
@conn = ActiveRecord::Base.connection
|
7
|
+
@conn.execute "DROP TABLE test2_employees" rescue nil
|
8
|
+
@conn.execute <<-SQL
|
9
|
+
CREATE TABLE test2_employees (
|
10
|
+
id NUMBER PRIMARY KEY,
|
11
|
+
first_name VARCHAR2(20),
|
12
|
+
last_name VARCHAR2(25),
|
13
|
+
email VARCHAR2(25),
|
14
|
+
phone_number VARCHAR2(20),
|
15
|
+
hire_date DATE,
|
16
|
+
job_id NUMBER,
|
17
|
+
salary NUMBER,
|
18
|
+
commission_pct NUMBER(2,2),
|
19
|
+
manager_id NUMBER(6),
|
20
|
+
is_manager NUMBER(1),
|
21
|
+
department_id NUMBER(4,0),
|
22
|
+
created_at DATE
|
23
|
+
)
|
24
|
+
SQL
|
25
|
+
@conn.execute "DROP SEQUENCE test2_employees_seq" rescue nil
|
26
|
+
@conn.execute <<-SQL
|
27
|
+
CREATE SEQUENCE test2_employees_seq MINVALUE 1
|
28
|
+
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
29
|
+
SQL
|
30
|
+
end
|
31
|
+
|
32
|
+
after(:all) do
|
33
|
+
@conn.execute "DROP TABLE test2_employees"
|
34
|
+
@conn.execute "DROP SEQUENCE test2_employees_seq"
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "/ NUMBER values from ActiveRecord model" do
|
38
|
+
before(:each) do
|
39
|
+
class ::Test2Employee < ActiveRecord::Base
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
after(:each) do
|
44
|
+
Object.send(:remove_const, "Test2Employee")
|
45
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = true
|
46
|
+
ActiveRecord::Base.clear_cache!
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_employee2
|
50
|
+
@employee2 = Test2Employee.create(
|
51
|
+
first_name: "First",
|
52
|
+
last_name: "Last",
|
53
|
+
job_id: 1,
|
54
|
+
is_manager: 1,
|
55
|
+
salary: 1000
|
56
|
+
)
|
57
|
+
@employee2.reload
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return BigDecimal value from NUMBER column if by default" do
|
61
|
+
create_employee2
|
62
|
+
expect(@employee2.job_id.class).to eq(BigDecimal)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return Integer value from NUMBER column if attribute is set to integer" do
|
66
|
+
class ::Test2Employee < ActiveRecord::Base
|
67
|
+
attribute :job_id, :integer
|
68
|
+
end
|
69
|
+
create_employee2
|
70
|
+
expect(@employee2.job_id).to be_a(Integer)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return Integer value from NUMBER column with integer value using _before_type_cast method" do
|
74
|
+
create_employee2
|
75
|
+
expect(@employee2.job_id_before_type_cast).to be_a(Integer)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return Boolean value from NUMBER(1) column if emulate booleans is used" do
|
79
|
+
create_employee2
|
80
|
+
expect(@employee2.is_manager.class).to eq(TrueClass)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return Integer value from NUMBER(1) column if attribute is set to integer" do
|
84
|
+
class ::Test2Employee < ActiveRecord::Base
|
85
|
+
attribute :is_manager, :integer
|
86
|
+
end
|
87
|
+
create_employee2
|
88
|
+
expect(@employee2.is_manager).to be_a(Integer)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|