activerecord-oracle_enhanced-adapter 1.4.3 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +1162 -2
  3. data/README.md +567 -155
  4. data/VERSION +1 -1
  5. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +3 -1
  6. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +19 -0
  7. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +132 -0
  8. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +345 -0
  9. data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +52 -0
  10. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +280 -0
  11. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +64 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +59 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +538 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +38 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +46 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +435 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +44 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +196 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +164 -0
  20. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +95 -0
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +79 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +194 -0
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +709 -0
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +28 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +353 -0
  26. data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +33 -0
  27. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +3 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +385 -1083
  29. data/lib/active_record/type/oracle_enhanced/boolean.rb +20 -0
  30. data/lib/active_record/type/oracle_enhanced/integer.rb +15 -0
  31. data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
  32. data/lib/active_record/type/oracle_enhanced/national_character_string.rb +26 -0
  33. data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
  34. data/lib/active_record/type/oracle_enhanced/raw.rb +25 -0
  35. data/lib/active_record/type/oracle_enhanced/string.rb +29 -0
  36. data/lib/active_record/type/oracle_enhanced/text.rb +32 -0
  37. data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
  38. data/lib/active_record/type/oracle_enhanced/timestamptz.rb +25 -0
  39. data/lib/activerecord-oracle_enhanced-adapter.rb +5 -13
  40. data/spec/active_record/connection_adapters/{oracle_enhanced_emulate_oracle_adapter_spec.rb → emulation/oracle_adapter_spec.rb} +5 -4
  41. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +469 -0
  42. data/spec/active_record/connection_adapters/{oracle_enhanced_context_index_spec.rb → oracle_enhanced/context_index_spec.rb} +140 -128
  43. data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +112 -0
  44. data/spec/active_record/connection_adapters/{oracle_enhanced_dbms_output_spec.rb → oracle_enhanced/dbms_output_spec.rb} +13 -13
  45. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +365 -0
  46. data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +196 -0
  47. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +492 -0
  48. data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +1433 -0
  49. data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +478 -0
  50. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +385 -550
  51. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +92 -1249
  52. data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
  53. data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +208 -0
  54. data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +139 -0
  55. data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
  56. data/spec/active_record/oracle_enhanced/type/integer_spec.rb +91 -0
  57. data/spec/active_record/oracle_enhanced/type/json_spec.rb +57 -0
  58. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
  59. data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
  60. data/spec/active_record/oracle_enhanced/type/raw_spec.rb +122 -0
  61. data/spec/active_record/oracle_enhanced/type/text_spec.rb +229 -0
  62. data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +75 -0
  63. data/spec/spec_config.yaml.template +11 -0
  64. data/spec/spec_helper.rb +100 -93
  65. data/spec/support/alter_system_set_open_cursors.sql +1 -0
  66. data/spec/support/alter_system_user_password.sql +2 -0
  67. data/spec/support/create_oracle_enhanced_users.sql +31 -0
  68. metadata +105 -152
  69. data/.rspec +0 -2
  70. data/Gemfile +0 -52
  71. data/RUNNING_TESTS.md +0 -45
  72. data/Rakefile +0 -59
  73. data/activerecord-oracle_enhanced-adapter.gemspec +0 -130
  74. data/lib/active_record/connection_adapters/oracle_enhanced.rake +0 -105
  75. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
  76. data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -121
  77. data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +0 -151
  78. data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +0 -119
  79. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -359
  80. data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +0 -25
  81. data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +0 -21
  82. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -46
  83. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +0 -572
  84. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +0 -497
  85. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +0 -260
  86. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -227
  87. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +0 -260
  88. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -428
  89. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
  90. data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +0 -294
  91. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
  92. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
  93. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +0 -334
  94. data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +0 -19
  95. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
  96. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +0 -141
  97. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +0 -378
  98. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +0 -440
  99. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +0 -1400
  100. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +0 -339
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe "OracleEnhancedAdapter handling of RAW columns" do
4
+ include SchemaSpecHelper
5
+
6
+ before(:all) do
7
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
8
+ schema_define do
9
+ create_table :test_employees, force: true do |t|
10
+ t.string :first_name, limit: 20
11
+ t.string :last_name, limit: 25
12
+ t.raw :binary_data, limit: 1024
13
+ end
14
+ end
15
+ @binary_data = "\0\1\2\3\4\5\6\7\8\9" * 100
16
+ @binary_data2 = "\1\2\3\4\5\6\7\8\9\0" * 100
17
+ end
18
+
19
+ after(:all) do
20
+ schema_define do
21
+ drop_table :test_employees
22
+ end
23
+ end
24
+
25
+ before(:each) do
26
+ class ::TestEmployee < ActiveRecord::Base
27
+ end
28
+ end
29
+
30
+ after(:each) do
31
+ Object.send(:remove_const, "TestEmployee")
32
+ ActiveRecord::Base.clear_cache!
33
+ end
34
+
35
+ it "should create record with RAW data" do
36
+ @employee = TestEmployee.create!(
37
+ first_name: "First",
38
+ last_name: "Last",
39
+ binary_data: @binary_data
40
+ )
41
+ @employee.reload
42
+ expect(@employee.binary_data).to eq(@binary_data)
43
+ end
44
+
45
+ it "should update record with RAW data" do
46
+ @employee = TestEmployee.create!(
47
+ first_name: "First",
48
+ last_name: "Last"
49
+ )
50
+ @employee.reload
51
+ expect(@employee.binary_data).to be_nil
52
+ @employee.binary_data = @binary_data
53
+ @employee.save!
54
+ @employee.reload
55
+ expect(@employee.binary_data).to eq(@binary_data)
56
+ end
57
+
58
+ it "should update record with zero-length RAW data" do
59
+ @employee = TestEmployee.create!(
60
+ first_name: "First",
61
+ last_name: "Last"
62
+ )
63
+ @employee.reload
64
+ expect(@employee.binary_data).to be_nil
65
+ @employee.binary_data = ""
66
+ @employee.save!
67
+ @employee.reload
68
+ expect(@employee.binary_data).to be_nil
69
+ end
70
+
71
+ it "should update record that has existing RAW data with different RAW data" do
72
+ @employee = TestEmployee.create!(
73
+ first_name: "First",
74
+ last_name: "Last",
75
+ binary_data: @binary_data
76
+ )
77
+ @employee.reload
78
+ @employee.binary_data = @binary_data2
79
+ @employee.save!
80
+ @employee.reload
81
+ expect(@employee.binary_data).to eq(@binary_data2)
82
+ end
83
+
84
+ it "should update record that has existing RAW data with nil" do
85
+ @employee = TestEmployee.create!(
86
+ first_name: "First",
87
+ last_name: "Last",
88
+ binary_data: @binary_data
89
+ )
90
+ @employee.reload
91
+ @employee.binary_data = nil
92
+ @employee.save!
93
+ @employee.reload
94
+ expect(@employee.binary_data).to be_nil
95
+ end
96
+
97
+ it "should update record that has existing RAW data with zero-length RAW data" do
98
+ @employee = TestEmployee.create!(
99
+ first_name: "First",
100
+ last_name: "Last",
101
+ binary_data: @binary_data
102
+ )
103
+ @employee.reload
104
+ @employee.binary_data = ""
105
+ @employee.save!
106
+ @employee.reload
107
+ expect(@employee.binary_data).to be_nil
108
+ end
109
+
110
+ it "should update record that has zero-length BLOB data with non-empty RAW data" do
111
+ @employee = TestEmployee.create!(
112
+ first_name: "First",
113
+ last_name: "Last",
114
+ binary_data: ""
115
+ )
116
+ @employee.reload
117
+ @employee.binary_data = @binary_data
118
+ @employee.save!
119
+ @employee.reload
120
+ expect(@employee.binary_data).to eq(@binary_data)
121
+ end
122
+ end
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe "OracleEnhancedAdapter handling of CLOB 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.text :comments
14
+ end
15
+ create_table :test2_employees, force: true do |t|
16
+ t.string :first_name, limit: 20
17
+ t.string :last_name, limit: 25
18
+ t.text :comments
19
+ end
20
+ create_table :test_serialize_employees, force: true do |t|
21
+ t.string :first_name, limit: 20
22
+ t.string :last_name, limit: 25
23
+ end
24
+ add_column :test_serialize_employees, :comments, :text
25
+ end
26
+
27
+ @char_data = (0..127).to_a.pack("C*") * 800
28
+ @char_data2 = ((1..127).to_a.pack("C*") + "\0") * 800
29
+
30
+ class ::TestEmployee < ActiveRecord::Base; end
31
+ class ::Test2Employee < ActiveRecord::Base
32
+ serialize :comments
33
+ end
34
+ class ::TestEmployeeReadOnlyClob < ActiveRecord::Base
35
+ self.table_name = "test_employees"
36
+ attr_readonly :comments
37
+ end
38
+ class ::TestSerializeEmployee < ActiveRecord::Base
39
+ serialize :comments
40
+ attr_readonly :comments
41
+ end
42
+ end
43
+
44
+ after(:all) do
45
+ @conn.drop_table :test_employees, if_exists: true
46
+ @conn.drop_table :test2_employees, if_exists: true
47
+ @conn.drop_table :test_serialize_employees, if_exists: true
48
+ Object.send(:remove_const, "TestEmployee")
49
+ Object.send(:remove_const, "Test2Employee")
50
+ Object.send(:remove_const, "TestEmployeeReadOnlyClob")
51
+ Object.send(:remove_const, "TestSerializeEmployee")
52
+ ActiveRecord::Base.clear_cache!
53
+ end
54
+
55
+ it "should create record without CLOB data when attribute is serialized" do
56
+ @employee = Test2Employee.create!(
57
+ first_name: "First",
58
+ last_name: "Last"
59
+ )
60
+ expect(@employee).to be_valid
61
+ @employee.reload
62
+ expect(@employee.comments).to be_nil
63
+ end
64
+
65
+ it "should accept Symbol value for CLOB column" do
66
+ @employee = TestEmployee.create!(
67
+ comments: :test_comment
68
+ )
69
+ expect(@employee).to be_valid
70
+ end
71
+
72
+ it "should respect attr_readonly setting for CLOB column" do
73
+ @employee = TestEmployeeReadOnlyClob.create!(
74
+ first_name: "First",
75
+ comments: "initial"
76
+ )
77
+ expect(@employee).to be_valid
78
+ @employee.reload
79
+ expect(@employee.comments).to eq("initial")
80
+ @employee.comments = "changed"
81
+ expect(@employee.save).to eq(true)
82
+ @employee.reload
83
+ expect(@employee.comments).to eq("initial")
84
+ end
85
+
86
+ it "should work for serialized readonly CLOB columns", serialized: true do
87
+ @employee = TestSerializeEmployee.new(
88
+ first_name: "First",
89
+ comments: nil
90
+ )
91
+ expect(@employee.comments).to be_nil
92
+ expect(@employee.save).to eq(true)
93
+ expect(@employee).to be_valid
94
+ @employee.reload
95
+ expect(@employee.comments).to be_nil
96
+ @employee.comments = {}
97
+ expect(@employee.save).to eq(true)
98
+ @employee.reload
99
+ # should not set readonly
100
+ expect(@employee.comments).to be_nil
101
+ end
102
+
103
+ it "should create record with CLOB data" do
104
+ @employee = TestEmployee.create!(
105
+ first_name: "First",
106
+ last_name: "Last",
107
+ comments: @char_data
108
+ )
109
+ @employee.reload
110
+ expect(@employee.comments).to eq(@char_data)
111
+ end
112
+
113
+ it "should update record with CLOB data" do
114
+ @employee = TestEmployee.create!(
115
+ first_name: "First",
116
+ last_name: "Last"
117
+ )
118
+ @employee.reload
119
+ expect(@employee.comments).to be_nil
120
+ @employee.comments = @char_data
121
+ @employee.save!
122
+ @employee.reload
123
+ expect(@employee.comments).to eq(@char_data)
124
+ end
125
+
126
+ it "should update record with zero-length CLOB data" do
127
+ @employee = TestEmployee.create!(
128
+ first_name: "First",
129
+ last_name: "Last"
130
+ )
131
+ @employee.reload
132
+ expect(@employee.comments).to be_nil
133
+ @employee.comments = ""
134
+ @employee.save!
135
+ @employee.reload
136
+ expect(@employee.comments).to eq("")
137
+ end
138
+
139
+ it "should update record that has existing CLOB data with different CLOB data" do
140
+ @employee = TestEmployee.create!(
141
+ first_name: "First",
142
+ last_name: "Last",
143
+ comments: @char_data
144
+ )
145
+ @employee.reload
146
+ @employee.comments = @char_data2
147
+ @employee.save!
148
+ @employee.reload
149
+ expect(@employee.comments).to eq(@char_data2)
150
+ end
151
+
152
+ it "should update record that has existing CLOB data with nil" do
153
+ @employee = TestEmployee.create!(
154
+ first_name: "First",
155
+ last_name: "Last",
156
+ comments: @char_data
157
+ )
158
+ @employee.reload
159
+ @employee.comments = nil
160
+ @employee.save!
161
+ @employee.reload
162
+ expect(@employee.comments).to be_nil
163
+ end
164
+
165
+ it "should update record that has existing CLOB data with zero-length CLOB data" do
166
+ @employee = TestEmployee.create!(
167
+ first_name: "First",
168
+ last_name: "Last",
169
+ comments: @char_data
170
+ )
171
+ @employee.reload
172
+ @employee.comments = ""
173
+ @employee.save!
174
+ @employee.reload
175
+ expect(@employee.comments).to eq("")
176
+ end
177
+
178
+ it "should update record that has zero-length CLOB data with non-empty CLOB data" do
179
+ @employee = TestEmployee.create!(
180
+ first_name: "First",
181
+ last_name: "Last",
182
+ comments: ""
183
+ )
184
+ @employee.reload
185
+ expect(@employee.comments).to eq("")
186
+ @employee.comments = @char_data
187
+ @employee.save!
188
+ @employee.reload
189
+ expect(@employee.comments).to eq(@char_data)
190
+ end
191
+
192
+ it "should store serializable ruby data structures" do
193
+ ruby_data1 = { "arbitrary1" => ["ruby", :data, 123] }
194
+ ruby_data2 = { "arbitrary2" => ["ruby", :data, 123] }
195
+ @employee = Test2Employee.create!(
196
+ comments: ruby_data1
197
+ )
198
+ @employee.reload
199
+ expect(@employee.comments).to eq(ruby_data1)
200
+ @employee.comments = ruby_data2
201
+ @employee.save
202
+ @employee.reload
203
+ expect(@employee.comments).to eq(ruby_data2)
204
+ end
205
+
206
+ it "should keep unchanged serialized data when other columns changed" do
207
+ @employee = Test2Employee.create!(
208
+ first_name: "First",
209
+ last_name: "Last",
210
+ comments: "initial serialized data"
211
+ )
212
+ @employee.first_name = "Steve"
213
+ @employee.save
214
+ @employee.reload
215
+ expect(@employee.comments).to eq("initial serialized data")
216
+ end
217
+
218
+ it "should keep serialized data after save" do
219
+ @employee = Test2Employee.new
220
+ @employee.comments = { length: { is: 1 } }
221
+ @employee.save
222
+ @employee.reload
223
+ expect(@employee.comments).to eq(length: { is: 1 })
224
+ @employee.comments = { length: { is: 2 } }
225
+ @employee.save
226
+ @employee.reload
227
+ expect(@employee.comments).to eq(length: { is: 2 })
228
+ end
229
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe "OracleEnhancedAdapter timestamp with timezone support" do
4
+ include SchemaSpecHelper
5
+
6
+ before(:all) do
7
+ ActiveRecord::Base.default_timezone = :local
8
+ ActiveRecord::Base.establish_connection(CONNECTION_WITH_TIMEZONE_PARAMS)
9
+ @conn = ActiveRecord::Base.connection
10
+ schema_define do
11
+ create_table :test_employees, force: true do |t|
12
+ t.string :first_name, limit: 20
13
+ t.string :last_name, limit: 25
14
+ t.string :email, limit: 25
15
+ t.string :phone_number, limit: 20
16
+ t.date :hire_date
17
+ t.decimal :job_id, scale: 0, precision: 6
18
+ t.decimal :salary, scale: 2, precision: 8
19
+ t.decimal :commission_pct, scale: 2, precision: 2
20
+ t.decimal :manager_id, scale: 0, precision: 6
21
+ t.decimal :department_id, scale: 0, precision: 4
22
+ t.timestamp :created_at
23
+ t.timestamptz :created_at_tz
24
+ t.timestampltz :created_at_ltz
25
+ end
26
+ end
27
+ end
28
+
29
+ after(:all) do
30
+ @conn.drop_table :test_employees, if_exists: true
31
+ ActiveRecord::Base.default_timezone = :utc
32
+ end
33
+
34
+ describe "/ TIMESTAMP WITH TIME ZONE values from ActiveRecord model" do
35
+ before(:all) do
36
+ class ::TestEmployee < ActiveRecord::Base
37
+ end
38
+ end
39
+
40
+ after(:all) do
41
+ Object.send(:remove_const, "TestEmployee")
42
+ ActiveRecord::Base.clear_cache!
43
+ end
44
+
45
+ it "should return Time value from TIMESTAMP columns" do
46
+ @now = Time.local(2008, 5, 26, 23, 11, 11, 0)
47
+ @employee = TestEmployee.create(
48
+ created_at: @now,
49
+ created_at_tz: @now,
50
+ created_at_ltz: @now
51
+ )
52
+ @employee.reload
53
+ [:created_at, :created_at_tz, :created_at_ltz].each do |c|
54
+ expect(@employee.send(c).class).to eq(Time)
55
+ expect(@employee.send(c).to_f).to eq(@now.to_f)
56
+ end
57
+ end
58
+
59
+ it "should return Time value with fractional seconds from TIMESTAMP columns" do
60
+ @now = Time.local(2008, 5, 26, 23, 11, 11, 10)
61
+ @employee = TestEmployee.create(
62
+ created_at: @now,
63
+ created_at_tz: @now,
64
+ created_at_ltz: @now
65
+ )
66
+ @employee.reload
67
+ [:created_at, :created_at_tz, :created_at_ltz].each do |c|
68
+ expect(@employee.send(c).class).to eq(Time)
69
+ expect(@employee.send(c).to_f).to eq(@now.to_f)
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,11 @@
1
+ # copy this file to spec/config.yaml and set appropriate values
2
+ # you can also use environment variables, see spec_helper.rb
3
+ database:
4
+ name: 'orcl'
5
+ host: '127.0.0.1'
6
+ port: 1521
7
+ user: 'oracle_enhanced'
8
+ password: 'oracle_enhanced'
9
+ sys_password: 'admin'
10
+ non_default_tablespace: 'SYSTEM'
11
+ timezone: 'Europe/Riga'
data/spec/spec_helper.rb CHANGED
@@ -1,80 +1,61 @@
1
- require 'rubygems'
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+ SimpleCov.start
5
+ require "rubygems"
2
6
  require "bundler"
7
+ require "yaml"
3
8
  Bundler.setup(:default, :development)
4
9
 
5
- $:.unshift(File.expand_path('../../lib', __FILE__))
10
+ $:.unshift(File.expand_path("../../lib", __FILE__))
11
+ config_path = File.expand_path("../spec_config.yaml", __FILE__)
12
+ if File.exist?(config_path)
13
+ puts "==> Loading config from #{config_path}"
14
+ config = YAML.load_file(config_path)
15
+ else
16
+ puts "==> Loading config from ENV or use default"
17
+ config = { "rails" => {}, "database" => {} }
18
+ end
6
19
 
7
- require 'rspec'
20
+ require "rspec"
8
21
 
9
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
22
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
10
23
  puts "==> Running specs with MRI version #{RUBY_VERSION}"
11
- require 'oci8'
12
- elsif RUBY_ENGINE == 'jruby'
24
+ require "oci8"
25
+ elsif RUBY_ENGINE == "jruby"
13
26
  puts "==> Running specs with JRuby version #{JRUBY_VERSION}"
14
27
  end
15
28
 
16
- ENV['RAILS_GEM_VERSION'] ||= '3.2-master'
17
- NO_COMPOSITE_PRIMARY_KEYS = true if ENV['RAILS_GEM_VERSION'] >= '2.3.5' || ENV['RAILS_GEM_VERSION'] =~ /^2\.3\.1\d$/
18
-
19
- puts "==> Running specs with Rails version #{ENV['RAILS_GEM_VERSION']}"
29
+ require "active_record"
20
30
 
21
- require 'active_record'
31
+ require "active_support/core_ext/module/attribute_accessors"
32
+ require "active_support/core_ext/class/attribute_accessors"
22
33
 
23
- if ENV['RAILS_GEM_VERSION'] >= '3.0'
24
- require 'action_dispatch'
25
- require 'active_support/core_ext/module/attribute_accessors'
26
- require 'active_support/core_ext/class/attribute_accessors'
34
+ require "active_support/log_subscriber"
35
+ require "active_record/log_subscriber"
27
36
 
28
- if ENV['RAILS_GEM_VERSION'] =~ /^3.0.0.beta/
29
- require "rails/log_subscriber"
30
- require 'active_record/railties/log_subscriber'
31
- else
32
- require "active_support/log_subscriber"
33
- require 'active_record/log_subscriber'
34
- end
37
+ require "logger"
35
38
 
36
- require 'logger'
37
- elsif ENV['RAILS_GEM_VERSION'] =~ /^2.3/
38
- require 'action_pack'
39
- require 'action_controller/session/abstract_store'
40
- require 'active_record/session_store'
41
- elsif ENV['RAILS_GEM_VERSION'] <= '2.3'
42
- require 'action_pack'
43
- require 'action_controller/session/active_record_store'
44
- end
39
+ require "active_record/connection_adapters/oracle_enhanced_adapter"
40
+ require "ruby-plsql"
45
41
 
46
- require 'active_record/connection_adapters/oracle_enhanced_adapter'
47
- require 'ruby-plsql'
42
+ puts "==> Effective ActiveRecord version #{ActiveRecord::VERSION::STRING}"
48
43
 
49
44
  module LoggerSpecHelper
50
45
  def set_logger
51
46
  @logger = MockLogger.new
52
47
  @old_logger = ActiveRecord::Base.logger
53
48
 
54
- if ENV['RAILS_GEM_VERSION'] >= '3.0'
55
- @notifier = ActiveSupport::Notifications::Fanout.new
49
+ @notifier = ActiveSupport::Notifications::Fanout.new
56
50
 
57
- ActiveSupport::LogSubscriber.colorize_logging = false
51
+ ActiveSupport::LogSubscriber.colorize_logging = false
58
52
 
59
- ActiveRecord::Base.logger = @logger
60
- @old_notifier = ActiveSupport::Notifications.notifier
61
- ActiveSupport::Notifications.notifier = @notifier
62
-
63
- ActiveRecord::LogSubscriber.attach_to(:active_record)
64
- if ENV['RAILS_GEM_VERSION'] >= '3.2'
65
- ActiveSupport::Notifications.subscribe("sql.active_record", ActiveRecord::ExplainSubscriber.new)
66
- end
67
- else # ActiveRecord 2.x
68
- if ActiveRecord::Base.respond_to?(:connection_pool)
69
- ActiveRecord::Base.connection_pool.clear_reloadable_connections!
70
- else
71
- ActiveRecord::Base.clear_active_connections!
72
- end
73
- ActiveRecord::Base.logger = @logger
74
- ActiveRecord::Base.colorize_logging = false
75
- # ActiveRecord::Base.logger.level = Logger::DEBUG
76
- end
53
+ ActiveRecord::Base.logger = @logger
54
+ @old_notifier = ActiveSupport::Notifications.notifier
55
+ ActiveSupport::Notifications.notifier = @notifier
77
56
 
57
+ ActiveRecord::LogSubscriber.attach_to(:active_record)
58
+ ActiveSupport::Notifications.subscribe("sql.active_record", ActiveRecord::ExplainSubscriber.new)
78
59
  end
79
60
 
80
61
  class MockLogger
@@ -82,7 +63,7 @@ module LoggerSpecHelper
82
63
 
83
64
  def initialize
84
65
  @flush_count = 0
85
- @logged = Hash.new { |h,k| h[k] = [] }
66
+ @logged = Hash.new { |h, k| h[k] = [] }
86
67
  end
87
68
 
88
69
  # used in AtiveRecord 2.x
@@ -115,11 +96,8 @@ module LoggerSpecHelper
115
96
  ActiveRecord::Base.logger = @old_logger
116
97
  @logger = nil
117
98
 
118
- if ENV['RAILS_GEM_VERSION'] >= '3.0'
119
- ActiveSupport::Notifications.notifier = @old_notifier
120
- @notifier = nil
121
- end
122
-
99
+ ActiveSupport::Notifications.notifier = @old_notifier
100
+ @notifier = nil
123
101
  end
124
102
 
125
103
  # Wait notifications to be published (for Rails 3.0)
@@ -127,7 +105,6 @@ module LoggerSpecHelper
127
105
  def wait
128
106
  @notifier.wait if @notifier
129
107
  end
130
-
131
108
  end
132
109
 
133
110
  module SchemaSpecHelper
@@ -140,48 +117,78 @@ module SchemaSpecHelper
140
117
  end
141
118
  end
142
119
 
143
- DATABASE_NAME = ENV['DATABASE_NAME'] || 'orcl'
144
- DATABASE_HOST = ENV['DATABASE_HOST']
145
- DATABASE_PORT = ENV['DATABASE_PORT']
146
- DATABASE_USER = ENV['DATABASE_USER'] || 'oracle_enhanced'
147
- DATABASE_PASSWORD = ENV['DATABASE_PASSWORD'] || 'oracle_enhanced'
148
- DATABASE_SYS_PASSWORD = ENV['DATABASE_SYS_PASSWORD'] || 'admin'
120
+ module SchemaDumpingHelper
121
+ def dump_table_schema(table, connection = ActiveRecord::Base.connection)
122
+ old_ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
123
+ ActiveRecord::SchemaDumper.ignore_tables = connection.data_sources - [table]
124
+ stream = StringIO.new
125
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
126
+ stream.string
127
+ ensure
128
+ ActiveRecord::SchemaDumper.ignore_tables = old_ignore_tables
129
+ end
130
+ end
131
+
132
+ DATABASE_NAME = config["database"]["name"] || ENV["DATABASE_NAME"] || "orcl"
133
+ DATABASE_HOST = config["database"]["host"] || ENV["DATABASE_HOST"] || "127.0.0.1"
134
+ DATABASE_PORT = config["database"]["port"] || ENV["DATABASE_PORT"] || 1521
135
+ DATABASE_USER = config["database"]["user"] || ENV["DATABASE_USER"] || "oracle_enhanced"
136
+ DATABASE_PASSWORD = config["database"]["password"] || ENV["DATABASE_PASSWORD"] || "oracle_enhanced"
137
+ DATABASE_SCHEMA = config["database"]["schema"] || ENV["DATABASE_SCHEMA"] || "oracle_enhanced_schema"
138
+ DATABASE_SYS_PASSWORD = config["database"]["sys_password"] || ENV["DATABASE_SYS_PASSWORD"] || "admin"
149
139
 
150
140
  CONNECTION_PARAMS = {
151
- :adapter => "oracle_enhanced",
152
- :database => DATABASE_NAME,
153
- :host => DATABASE_HOST,
154
- :port => DATABASE_PORT,
155
- :username => DATABASE_USER,
156
- :password => DATABASE_PASSWORD
141
+ adapter: "oracle_enhanced",
142
+ database: DATABASE_NAME,
143
+ host: DATABASE_HOST,
144
+ port: DATABASE_PORT,
145
+ username: DATABASE_USER,
146
+ password: DATABASE_PASSWORD
147
+ }
148
+
149
+ CONNECTION_WITH_SCHEMA_PARAMS = {
150
+ adapter: "oracle_enhanced",
151
+ database: DATABASE_NAME,
152
+ host: DATABASE_HOST,
153
+ port: DATABASE_PORT,
154
+ username: DATABASE_USER,
155
+ password: DATABASE_PASSWORD,
156
+ schema: DATABASE_SCHEMA
157
+ }
158
+
159
+ CONNECTION_WITH_TIMEZONE_PARAMS = {
160
+ adapter: "oracle_enhanced",
161
+ database: DATABASE_NAME,
162
+ host: DATABASE_HOST,
163
+ port: DATABASE_PORT,
164
+ username: DATABASE_USER,
165
+ password: DATABASE_PASSWORD,
166
+ time_zone: "Europe/Riga"
157
167
  }
158
168
 
159
169
  SYS_CONNECTION_PARAMS = {
160
- :adapter => "oracle_enhanced",
161
- :database => DATABASE_NAME,
162
- :host => DATABASE_HOST,
163
- :port => DATABASE_PORT,
164
- :username => "sys",
165
- :password => DATABASE_SYS_PASSWORD,
166
- :privilege => "SYSDBA"
170
+ adapter: "oracle_enhanced",
171
+ database: DATABASE_NAME,
172
+ host: DATABASE_HOST,
173
+ port: DATABASE_PORT,
174
+ username: "sys",
175
+ password: DATABASE_SYS_PASSWORD,
176
+ privilege: "SYSDBA"
167
177
  }
168
178
 
169
179
  SYSTEM_CONNECTION_PARAMS = {
170
- :adapter => "oracle_enhanced",
171
- :database => DATABASE_NAME,
172
- :host => DATABASE_HOST,
173
- :port => DATABASE_PORT,
174
- :username => "system",
175
- :password => DATABASE_SYS_PASSWORD
180
+ adapter: "oracle_enhanced",
181
+ database: DATABASE_NAME,
182
+ host: DATABASE_HOST,
183
+ port: DATABASE_PORT,
184
+ username: "system",
185
+ password: DATABASE_SYS_PASSWORD
176
186
  }
177
187
 
178
- DATABASE_NON_DEFAULT_TABLESPACE = ENV['DATABASE_NON_DEFAULT_TABLESPACE'] || "SYSTEM"
179
-
180
- # Set default $KCODE to UTF8
181
- if RUBY_VERSION < "1.9"
182
- $KCODE = "UTF8"
183
- end
188
+ DATABASE_NON_DEFAULT_TABLESPACE = config["database"]["non_default_tablespace"] || ENV["DATABASE_NON_DEFAULT_TABLESPACE"] || "SYSTEM"
184
189
 
185
190
  # set default time zone in TZ environment variable
186
191
  # which will be used to set session time zone
187
- ENV['TZ'] ||= 'Europe/Riga'
192
+ ENV["TZ"] ||= config["timezone"] || "Europe/Riga"
193
+
194
+ ActiveRecord::Base.logger = ActiveSupport::Logger.new("debug.log", 0, 100 * 1024 * 1024)