activerecord-oracle_enhanced-adapter 1.1.9 → 1.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.
- data/History.txt +11 -0
- data/README.txt +6 -2
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +5 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +771 -907
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +71 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +64 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +2 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +352 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +346 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +2 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_reserved_words.rb +126 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +200 -97
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +170 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +40 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +11 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +148 -53
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +13 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +27 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +10 -6
- data/spec/spec_helper.rb +51 -6
- metadata +11 -2
@@ -1,65 +1,79 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
2
|
|
3
3
|
describe "OracleEnhancedAdapter establish connection" do
|
4
|
-
|
4
|
+
|
5
5
|
it "should connect to database" do
|
6
|
-
ActiveRecord::Base.establish_connection(
|
7
|
-
:database => "xe",
|
8
|
-
:username => "hr",
|
9
|
-
:password => "hr")
|
6
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
10
7
|
ActiveRecord::Base.connection.should_not be_nil
|
11
8
|
ActiveRecord::Base.connection.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
|
12
9
|
end
|
13
10
|
|
14
11
|
it "should connect to database as SYSDBA" do
|
15
|
-
ActiveRecord::Base.establish_connection(
|
16
|
-
:database => "xe",
|
17
|
-
:username => "sys",
|
18
|
-
:password => "manager",
|
19
|
-
:privilege => :SYSDBA)
|
12
|
+
ActiveRecord::Base.establish_connection(SYS_CONNECTION_PARAMS)
|
20
13
|
ActiveRecord::Base.connection.should_not be_nil
|
21
14
|
ActiveRecord::Base.connection.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
|
22
15
|
end
|
16
|
+
|
17
|
+
it "should be active after connection to database" do
|
18
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
19
|
+
ActiveRecord::Base.connection.should be_active
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not be active after disconnection to database" do
|
23
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
24
|
+
ActiveRecord::Base.connection.disconnect!
|
25
|
+
ActiveRecord::Base.connection.should_not be_active
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be active after reconnection to database" do
|
29
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
30
|
+
ActiveRecord::Base.connection.reconnect!
|
31
|
+
ActiveRecord::Base.connection.should be_active
|
32
|
+
end
|
23
33
|
|
24
34
|
end
|
25
35
|
|
26
36
|
describe "OracleEnhancedAdapter schema dump" do
|
27
|
-
|
37
|
+
|
28
38
|
before(:all) do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
if !defined?(RUBY_ENGINE)
|
40
|
+
@old_conn = ActiveRecord::Base.oracle_connection(CONNECTION_PARAMS)
|
41
|
+
@old_conn.class.should == ActiveRecord::ConnectionAdapters::OracleAdapter
|
42
|
+
elsif RUBY_ENGINE == 'jruby'
|
43
|
+
@old_conn = ActiveRecord::Base.jdbc_connection(JDBC_CONNECTION_PARAMS)
|
44
|
+
@old_conn.class.should == ActiveRecord::ConnectionAdapters::JdbcAdapter
|
45
|
+
end
|
46
|
+
|
47
|
+
@new_conn = ActiveRecord::Base.oracle_enhanced_connection(CONNECTION_PARAMS)
|
38
48
|
@new_conn.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
|
39
49
|
end
|
40
50
|
|
41
|
-
|
42
|
-
|
43
|
-
|
51
|
+
unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION =~ /^1\.9/
|
52
|
+
it "should return the same tables list as original oracle adapter" do
|
53
|
+
@new_conn.tables.sort.should == @old_conn.tables.sort
|
54
|
+
end
|
44
55
|
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
it "should return the same index list as original oracle adapter" do
|
57
|
+
@new_conn.indexes('employees').sort_by(&:name).should == @old_conn.indexes('employees').sort_by(&:name)
|
58
|
+
end
|
48
59
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
60
|
+
it "should return the same pk_and_sequence_for as original oracle adapter" do
|
61
|
+
if @old_conn.respond_to?(:pk_and_sequence_for)
|
62
|
+
@new_conn.tables.each do |t|
|
63
|
+
@new_conn.pk_and_sequence_for(t).should == @old_conn.pk_and_sequence_for(t)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
54
67
|
|
55
|
-
|
56
|
-
|
57
|
-
|
68
|
+
it "should return the same structure dump as original oracle adapter" do
|
69
|
+
@new_conn.structure_dump.should == @old_conn.structure_dump
|
70
|
+
end
|
58
71
|
|
59
|
-
|
60
|
-
|
72
|
+
it "should return the same structure drop as original oracle adapter" do
|
73
|
+
@new_conn.structure_drop.should == @old_conn.structure_drop
|
74
|
+
end
|
61
75
|
end
|
62
|
-
|
76
|
+
|
63
77
|
it "should return the character size of nvarchar fields" do
|
64
78
|
@new_conn.execute <<-SQL
|
65
79
|
CREATE TABLE nvarchartable (
|
@@ -75,10 +89,7 @@ end
|
|
75
89
|
|
76
90
|
describe "OracleEnhancedAdapter database stucture dump extentions" do
|
77
91
|
before(:all) do
|
78
|
-
ActiveRecord::Base.establish_connection(
|
79
|
-
:database => "xe",
|
80
|
-
:username => "hr",
|
81
|
-
:password => "hr")
|
92
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
82
93
|
@conn = ActiveRecord::Base.connection
|
83
94
|
@conn.execute <<-SQL
|
84
95
|
CREATE TABLE nvarchartable (
|
@@ -86,11 +97,11 @@ describe "OracleEnhancedAdapter database stucture dump extentions" do
|
|
86
97
|
)
|
87
98
|
SQL
|
88
99
|
end
|
89
|
-
|
100
|
+
|
90
101
|
after(:all) do
|
91
102
|
@conn.execute "DROP TABLE nvarchartable"
|
92
103
|
end
|
93
|
-
|
104
|
+
|
94
105
|
it "should return the character size of nvarchar fields" do
|
95
106
|
if /.*unq_nvarchar nvarchar2\((\d+)\).*/ =~ @conn.structure_dump
|
96
107
|
"#$1".should == "255"
|
@@ -100,10 +111,7 @@ end
|
|
100
111
|
|
101
112
|
describe "OracleEnhancedAdapter database session store" do
|
102
113
|
before(:all) do
|
103
|
-
ActiveRecord::Base.establish_connection(
|
104
|
-
:database => "xe",
|
105
|
-
:username => "hr",
|
106
|
-
:password => "hr")
|
114
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
107
115
|
@conn = ActiveRecord::Base.connection
|
108
116
|
@conn.execute <<-SQL
|
109
117
|
CREATE TABLE sessions (
|
@@ -119,6 +127,11 @@ describe "OracleEnhancedAdapter database session store" do
|
|
119
127
|
CREATE SEQUENCE sessions_seq MINVALUE 1 MAXVALUE 999999999999999999999999999
|
120
128
|
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
121
129
|
SQL
|
130
|
+
if ENV['RAILS_GEM_VERSION'] >= '2.3'
|
131
|
+
@session_class = ActiveRecord::SessionStore::Session
|
132
|
+
else
|
133
|
+
@session_class = CGI::Session::ActiveRecordStore::Session
|
134
|
+
end
|
122
135
|
end
|
123
136
|
|
124
137
|
after(:all) do
|
@@ -131,29 +144,29 @@ describe "OracleEnhancedAdapter database session store" do
|
|
131
144
|
end
|
132
145
|
|
133
146
|
it "should save session data" do
|
134
|
-
@session =
|
147
|
+
@session = @session_class.new :session_id => "111111", :data => "something" #, :updated_at => Time.now
|
135
148
|
@session.save!
|
136
|
-
@session =
|
149
|
+
@session = @session_class.find_by_session_id("111111")
|
137
150
|
@session.data.should == "something"
|
138
151
|
end
|
139
152
|
|
140
153
|
it "should change session data when partial updates enabled" do
|
141
|
-
return pending("Not in this ActiveRecord version") unless
|
142
|
-
|
143
|
-
@session =
|
154
|
+
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:partial_updates=)
|
155
|
+
@session_class.partial_updates = true
|
156
|
+
@session = @session_class.new :session_id => "222222", :data => "something" #, :updated_at => Time.now
|
144
157
|
@session.save!
|
145
|
-
@session =
|
158
|
+
@session = @session_class.find_by_session_id("222222")
|
146
159
|
@session.data = "other thing"
|
147
160
|
@session.save!
|
148
161
|
# second save should call again blob writing callback
|
149
162
|
@session.save!
|
150
|
-
@session =
|
163
|
+
@session = @session_class.find_by_session_id("222222")
|
151
164
|
@session.data.should == "other thing"
|
152
165
|
end
|
153
166
|
|
154
167
|
it "should have one enhanced_write_lobs callback" do
|
155
|
-
return pending("Not in this ActiveRecord version") unless
|
156
|
-
|
168
|
+
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:after_save_callback_chain)
|
169
|
+
@session_class.after_save_callback_chain.select{|cb| cb.method == :enhanced_write_lobs}.should have(1).record
|
157
170
|
end
|
158
171
|
|
159
172
|
it "should not set sessions table session_id column type as integer if emulate_integers_by_column_name is true" do
|
@@ -167,10 +180,7 @@ end
|
|
167
180
|
|
168
181
|
describe "OracleEnhancedAdapter ignore specified table columns" do
|
169
182
|
before(:all) do
|
170
|
-
ActiveRecord::Base.establish_connection(
|
171
|
-
:database => "xe",
|
172
|
-
:username => "hr",
|
173
|
-
:password => "hr")
|
183
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
174
184
|
@conn = ActiveRecord::Base.connection
|
175
185
|
@conn.execute <<-SQL
|
176
186
|
CREATE TABLE test_employees (
|
@@ -193,7 +203,7 @@ describe "OracleEnhancedAdapter ignore specified table columns" do
|
|
193
203
|
INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
|
194
204
|
SQL
|
195
205
|
end
|
196
|
-
|
206
|
+
|
197
207
|
after(:all) do
|
198
208
|
@conn.execute "DROP TABLE test_employees"
|
199
209
|
@conn.execute "DROP SEQUENCE test_employees_seq"
|
@@ -204,14 +214,14 @@ describe "OracleEnhancedAdapter ignore specified table columns" do
|
|
204
214
|
end
|
205
215
|
|
206
216
|
it "should ignore specified table columns" do
|
207
|
-
class TestEmployee < ActiveRecord::Base
|
217
|
+
class ::TestEmployee < ActiveRecord::Base
|
208
218
|
ignore_table_columns :phone_number, :hire_date
|
209
219
|
end
|
210
220
|
TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
|
211
221
|
end
|
212
222
|
|
213
223
|
it "should ignore specified table columns specified in several lines" do
|
214
|
-
class TestEmployee < ActiveRecord::Base
|
224
|
+
class ::TestEmployee < ActiveRecord::Base
|
215
225
|
ignore_table_columns :phone_number
|
216
226
|
ignore_table_columns :hire_date
|
217
227
|
end
|
@@ -219,7 +229,7 @@ describe "OracleEnhancedAdapter ignore specified table columns" do
|
|
219
229
|
end
|
220
230
|
|
221
231
|
it "should not ignore unspecified table columns" do
|
222
|
-
class TestEmployee < ActiveRecord::Base
|
232
|
+
class ::TestEmployee < ActiveRecord::Base
|
223
233
|
ignore_table_columns :phone_number, :hire_date
|
224
234
|
end
|
225
235
|
TestEmployee.connection.columns('test_employees').select{|c| c.name == 'email' }.should_not be_empty
|
@@ -231,10 +241,7 @@ end
|
|
231
241
|
describe "OracleEnhancedAdapter table and sequence creation with non-default primary key" do
|
232
242
|
|
233
243
|
before(:all) do
|
234
|
-
ActiveRecord::Base.establish_connection(
|
235
|
-
:database => "xe",
|
236
|
-
:username => "hr",
|
237
|
-
:password => "hr")
|
244
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
238
245
|
ActiveRecord::Schema.define do
|
239
246
|
suppress_messages do
|
240
247
|
create_table :keyboards, :force => true, :id => false do |t|
|
@@ -246,13 +253,13 @@ describe "OracleEnhancedAdapter table and sequence creation with non-default pri
|
|
246
253
|
end
|
247
254
|
end
|
248
255
|
end
|
249
|
-
class Keyboard < ActiveRecord::Base
|
256
|
+
class ::Keyboard < ActiveRecord::Base
|
250
257
|
set_primary_key :key_number
|
251
258
|
end
|
252
|
-
class IdKeyboard < ActiveRecord::Base
|
259
|
+
class ::IdKeyboard < ActiveRecord::Base
|
253
260
|
end
|
254
261
|
end
|
255
|
-
|
262
|
+
|
256
263
|
after(:all) do
|
257
264
|
ActiveRecord::Schema.define do
|
258
265
|
suppress_messages do
|
@@ -263,7 +270,7 @@ describe "OracleEnhancedAdapter table and sequence creation with non-default pri
|
|
263
270
|
Object.send(:remove_const, "Keyboard")
|
264
271
|
Object.send(:remove_const, "IdKeyboard")
|
265
272
|
end
|
266
|
-
|
273
|
+
|
267
274
|
it "should create sequence for non-default primary key" do
|
268
275
|
ActiveRecord::Base.connection.next_sequence_value(Keyboard.sequence_name).should_not be_nil
|
269
276
|
end
|
@@ -276,12 +283,9 @@ end
|
|
276
283
|
describe "OracleEnhancedAdapter without composite_primary_keys" do
|
277
284
|
|
278
285
|
before(:all) do
|
279
|
-
ActiveRecord::Base.establish_connection(
|
280
|
-
:database => "xe",
|
281
|
-
:username => "hr",
|
282
|
-
:password => "hr")
|
286
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
283
287
|
Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
|
284
|
-
class Employee < ActiveRecord::Base
|
288
|
+
class ::Employee < ActiveRecord::Base
|
285
289
|
set_primary_key :employee_id
|
286
290
|
end
|
287
291
|
end
|
@@ -299,10 +303,7 @@ end
|
|
299
303
|
describe "OracleEnhancedAdapter sequence creation parameters" do
|
300
304
|
|
301
305
|
before(:all) do
|
302
|
-
ActiveRecord::Base.establish_connection(
|
303
|
-
:database => "xe",
|
304
|
-
:username => "hr",
|
305
|
-
:password => "hr")
|
306
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
306
307
|
end
|
307
308
|
|
308
309
|
def create_test_employees_table(sequence_start_value = nil)
|
@@ -315,7 +316,7 @@ describe "OracleEnhancedAdapter sequence creation parameters" do
|
|
315
316
|
end
|
316
317
|
end
|
317
318
|
end
|
318
|
-
|
319
|
+
|
319
320
|
def save_default_sequence_start_value
|
320
321
|
@saved_sequence_start_value = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value
|
321
322
|
end
|
@@ -341,7 +342,7 @@ describe "OracleEnhancedAdapter sequence creation parameters" do
|
|
341
342
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value.should == 10000
|
342
343
|
|
343
344
|
create_test_employees_table
|
344
|
-
class TestEmployee < ActiveRecord::Base; end
|
345
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
345
346
|
|
346
347
|
employee = TestEmployee.create!
|
347
348
|
employee.id.should == 10000
|
@@ -351,7 +352,7 @@ describe "OracleEnhancedAdapter sequence creation parameters" do
|
|
351
352
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value = 1
|
352
353
|
|
353
354
|
create_test_employees_table
|
354
|
-
class TestEmployee < ActiveRecord::Base; end
|
355
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
355
356
|
|
356
357
|
employee = TestEmployee.create!
|
357
358
|
employee.id.should == 1
|
@@ -359,7 +360,7 @@ describe "OracleEnhancedAdapter sequence creation parameters" do
|
|
359
360
|
|
360
361
|
it "should use sequence start value from table definition" do
|
361
362
|
create_test_employees_table(10)
|
362
|
-
class TestEmployee < ActiveRecord::Base; end
|
363
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
363
364
|
|
364
365
|
employee = TestEmployee.create!
|
365
366
|
employee.id.should == 10
|
@@ -367,7 +368,7 @@ describe "OracleEnhancedAdapter sequence creation parameters" do
|
|
367
368
|
|
368
369
|
it "should use sequence start value and other options from table definition" do
|
369
370
|
create_test_employees_table("100 NOCACHE INCREMENT BY 10")
|
370
|
-
class TestEmployee < ActiveRecord::Base; end
|
371
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
371
372
|
|
372
373
|
employee = TestEmployee.create!
|
373
374
|
employee.id.should == 100
|
@@ -380,10 +381,7 @@ end
|
|
380
381
|
describe "OracleEnhancedAdapter table and column comments" do
|
381
382
|
|
382
383
|
before(:all) do
|
383
|
-
ActiveRecord::Base.establish_connection(
|
384
|
-
:database => "xe",
|
385
|
-
:username => "hr",
|
386
|
-
:password => "hr")
|
384
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
387
385
|
@conn = ActiveRecord::Base.connection
|
388
386
|
end
|
389
387
|
|
@@ -411,8 +409,8 @@ describe "OracleEnhancedAdapter table and column comments" do
|
|
411
409
|
it "should create table with table comment" do
|
412
410
|
table_comment = "Test Employees"
|
413
411
|
create_test_employees_table(table_comment)
|
414
|
-
class TestEmployee < ActiveRecord::Base; end
|
415
|
-
|
412
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
413
|
+
|
416
414
|
@conn.table_comment("test_employees").should == table_comment
|
417
415
|
TestEmployee.table_comment.should == table_comment
|
418
416
|
end
|
@@ -420,8 +418,8 @@ describe "OracleEnhancedAdapter table and column comments" do
|
|
420
418
|
it "should create table with columns comment" do
|
421
419
|
column_comments = {:first_name => "Given Name", :last_name => "Surname"}
|
422
420
|
create_test_employees_table(nil, column_comments)
|
423
|
-
class TestEmployee < ActiveRecord::Base; end
|
424
|
-
|
421
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
422
|
+
|
425
423
|
[:first_name, :last_name].each do |attr|
|
426
424
|
@conn.column_comment("test_employees", attr.to_s).should == column_comments[attr]
|
427
425
|
end
|
@@ -435,8 +433,8 @@ describe "OracleEnhancedAdapter table and column comments" do
|
|
435
433
|
table_comment = "Test Employees"
|
436
434
|
column_comments = {:first_name => "Given Name", :last_name => "Surname"}
|
437
435
|
create_test_employees_table(table_comment, column_comments)
|
438
|
-
class TestEmployee < ActiveRecord::Base; end
|
439
|
-
|
436
|
+
class ::TestEmployee < ActiveRecord::Base; end
|
437
|
+
|
440
438
|
@conn.table_comment(TestEmployee.table_name).should == table_comment
|
441
439
|
TestEmployee.table_comment.should == table_comment
|
442
440
|
[:first_name, :last_name].each do |attr|
|
@@ -447,4 +445,109 @@ describe "OracleEnhancedAdapter table and column comments" do
|
|
447
445
|
end
|
448
446
|
end
|
449
447
|
|
450
|
-
end
|
448
|
+
end
|
449
|
+
|
450
|
+
describe "OracleEnhancedAdapter column quoting" do
|
451
|
+
|
452
|
+
before(:all) do
|
453
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
454
|
+
@conn = ActiveRecord::Base.connection
|
455
|
+
end
|
456
|
+
|
457
|
+
def create_test_reserved_words_table
|
458
|
+
ActiveRecord::Schema.define do
|
459
|
+
suppress_messages do
|
460
|
+
create_table :test_reserved_words do |t|
|
461
|
+
t.string :varchar2
|
462
|
+
t.integer :integer
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
after(:each) do
|
469
|
+
ActiveRecord::Schema.define do
|
470
|
+
suppress_messages do
|
471
|
+
drop_table :test_reserved_words
|
472
|
+
end
|
473
|
+
end
|
474
|
+
Object.send(:remove_const, "TestReservedWord")
|
475
|
+
ActiveRecord::Base.table_name_prefix = nil
|
476
|
+
end
|
477
|
+
|
478
|
+
it "should allow creation of a table with oracle reserved words as column names" do
|
479
|
+
create_test_reserved_words_table
|
480
|
+
class ::TestReservedWord < ActiveRecord::Base; end
|
481
|
+
|
482
|
+
[:varchar2, :integer].each do |attr|
|
483
|
+
TestReservedWord.columns_hash[attr.to_s].name.should == attr.to_s
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
end
|
488
|
+
|
489
|
+
describe "OracleEnhancedAdapter valid table names" do
|
490
|
+
before(:all) do
|
491
|
+
@adapter = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
|
492
|
+
end
|
493
|
+
it "should be valid with letters and digits" do
|
494
|
+
@adapter.valid_table_name?("abc_123").should be_true
|
495
|
+
end
|
496
|
+
|
497
|
+
it "should be valid with schema name" do
|
498
|
+
@adapter.valid_table_name?("abc_123.def_456").should be_true
|
499
|
+
end
|
500
|
+
|
501
|
+
it "should be valid with $ in name" do
|
502
|
+
@adapter.valid_table_name?("sys.v$session").should be_true
|
503
|
+
end
|
504
|
+
|
505
|
+
it "should not be valid with two dots in name" do
|
506
|
+
@adapter.valid_table_name?("abc_123.def_456.ghi_789").should be_false
|
507
|
+
end
|
508
|
+
|
509
|
+
it "should not be valid with invalid characters" do
|
510
|
+
@adapter.valid_table_name?("warehouse-things").should be_false
|
511
|
+
end
|
512
|
+
|
513
|
+
end
|
514
|
+
|
515
|
+
describe "OracleEnhancedAdapter table quoting" do
|
516
|
+
|
517
|
+
before(:all) do
|
518
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
519
|
+
@conn = ActiveRecord::Base.connection
|
520
|
+
end
|
521
|
+
|
522
|
+
def create_warehouse_things_table
|
523
|
+
ActiveRecord::Schema.define do
|
524
|
+
suppress_messages do
|
525
|
+
create_table "warehouse-things" do |t|
|
526
|
+
t.string :name
|
527
|
+
t.integer :foo
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
after(:each) do
|
534
|
+
ActiveRecord::Schema.define do
|
535
|
+
suppress_messages do
|
536
|
+
drop_table "warehouse-things"
|
537
|
+
end
|
538
|
+
end
|
539
|
+
Object.send(:remove_const, "WarehouseThing")
|
540
|
+
ActiveRecord::Base.table_name_prefix = nil
|
541
|
+
end
|
542
|
+
|
543
|
+
it "should allow creation of a table with non alphanumeric characters" do
|
544
|
+
create_warehouse_things_table
|
545
|
+
class ::WarehouseThing < ActiveRecord::Base
|
546
|
+
set_table_name "warehouse-things"
|
547
|
+
end
|
548
|
+
|
549
|
+
wh = WarehouseThing.create!(:name => "Foo", :foo => 2)
|
550
|
+
wh.id.should_not be_nil
|
551
|
+
end
|
552
|
+
|
553
|
+
end
|