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