pmacs-activerecord-oracle_enhanced-adapter 1.4.2.rc1 → 1.5.5.1

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 (44) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -40
  3. data/History.md +170 -0
  4. data/README.md +61 -5
  5. data/Rakefile +1 -0
  6. data/VERSION +1 -1
  7. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +330 -161
  8. data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +48 -8
  9. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +77 -0
  10. data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +8 -24
  11. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +4 -13
  12. data/lib/active_record/connection_adapters/oracle_enhanced_database_tasks.rb +61 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +13 -12
  14. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +42 -19
  15. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +28 -74
  16. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +165 -231
  17. data/lib/active_record/connection_adapters/oracle_enhanced_schema_creation.rb +89 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +16 -24
  19. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +29 -38
  20. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +93 -42
  21. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +5 -3
  22. data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +7 -7
  23. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -1
  24. data/lib/pmacs-activerecord-oracle_enhanced-adapter.rb +2 -2
  25. data/pmacs-activerecord-oracle_enhanced-adapter.gemspec +19 -17
  26. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +35 -99
  27. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +17 -3
  28. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +105 -98
  29. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +74 -44
  30. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +89 -0
  31. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -3
  32. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +13 -2
  33. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +11 -12
  34. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +252 -60
  35. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +170 -40
  36. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +14 -8
  37. data/spec/spec_helper.rb +25 -54
  38. metadata +41 -72
  39. data/lib/active_record/connection_adapters/oracle_enhanced.rake +0 -105
  40. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
  41. data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -118
  42. data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +0 -25
  43. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
  44. data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +0 -19
@@ -6,7 +6,8 @@ describe "OracleEnhancedAdapter schema dump" do
6
6
  before(:all) do
7
7
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
8
8
  @conn = ActiveRecord::Base.connection
9
- @oracle11g = !! @conn.select_value("SELECT * FROM v$version WHERE banner LIKE 'Oracle%11g%'")
9
+ @oracle11g_or_higher = !! @conn.select_value(
10
+ "select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
10
11
  end
11
12
 
12
13
  def standard_dump(options = {})
@@ -17,7 +18,7 @@ describe "OracleEnhancedAdapter schema dump" do
17
18
  end
18
19
 
19
20
  def create_test_posts_table(options = {})
20
- options.merge! :force => true
21
+ options.merge! force: true
21
22
  schema_define do
22
23
  create_table :test_posts, options do |t|
23
24
  t.string :title
@@ -42,12 +43,12 @@ describe "OracleEnhancedAdapter schema dump" do
42
43
 
43
44
  it "should not include ignored table names in schema dump" do
44
45
  create_test_posts_table
45
- standard_dump(:ignore_tables => %w(test_posts)).should_not =~ /create_table "test_posts"/
46
+ standard_dump(ignore_tables: %w(test_posts)).should_not =~ /create_table "test_posts"/
46
47
  end
47
48
 
48
49
  it "should not include ignored table regexes in schema dump" do
49
50
  create_test_posts_table
50
- standard_dump(:ignore_tables => [ /test_posts/i ]).should_not =~ /create_table "test_posts"/
51
+ standard_dump(ignore_tables: [ /test_posts/i ]).should_not =~ /create_table "test_posts"/
51
52
  end
52
53
 
53
54
  end
@@ -55,9 +56,9 @@ describe "OracleEnhancedAdapter schema dump" do
55
56
  describe "dumping default values" do
56
57
  before :each do
57
58
  schema_define do
58
- create_table "test_defaults", :force => true do |t|
59
- t.string "regular", :default => "c"
60
- t.string "special_c", :default => "\n"
59
+ create_table "test_defaults", force: true do |t|
60
+ t.string "regular", default: "c"
61
+ t.string "special_c", default: "\n"
61
62
  end
62
63
  end
63
64
  end
@@ -69,7 +70,7 @@ describe "OracleEnhancedAdapter schema dump" do
69
70
  end
70
71
 
71
72
  it "should be able to dump default values using special characters" do
72
- standard_dump.should =~ /t.string \"special_c\", :default => "\\n"/
73
+ standard_dump.should =~ /t.string \"special_c\", default: "\\n"/
73
74
  end
74
75
  end
75
76
  describe "table prefixes and suffixes" do
@@ -124,8 +125,8 @@ describe "OracleEnhancedAdapter schema dump" do
124
125
  end
125
126
 
126
127
  it "should include non-default primary key in schema dump" do
127
- create_test_posts_table(:primary_key => 'post_id')
128
- standard_dump.should =~ /create_table "test_posts", :primary_key => "post_id"/
128
+ create_test_posts_table(primary_key: 'post_id')
129
+ standard_dump.should =~ /create_table "test_posts", primary_key: "post_id"/
129
130
  end
130
131
 
131
132
  end
@@ -138,13 +139,13 @@ describe "OracleEnhancedAdapter schema dump" do
138
139
  end
139
140
 
140
141
  it "should include primary key trigger in schema dump" do
141
- create_test_posts_table(:primary_key_trigger => true)
142
+ create_test_posts_table(primary_key_trigger: true)
142
143
  standard_dump.should =~ /create_table "test_posts".*add_primary_key_trigger "test_posts"/m
143
144
  end
144
145
 
145
146
  it "should include primary key trigger with non-default primary key in schema dump" do
146
- create_test_posts_table(:primary_key_trigger => true, :primary_key => 'post_id')
147
- standard_dump.should =~ /create_table "test_posts", :primary_key => "post_id".*add_primary_key_trigger "test_posts", :primary_key => "post_id"/m
147
+ create_test_posts_table(primary_key_trigger: true, primary_key: 'post_id')
148
+ standard_dump.should =~ /create_table "test_posts", primary_key: "post_id".*add_primary_key_trigger "test_posts", primary_key: "post_id"/m
148
149
  end
149
150
 
150
151
  end
@@ -152,11 +153,11 @@ describe "OracleEnhancedAdapter schema dump" do
152
153
  describe "foreign key constraints" do
153
154
  before(:all) do
154
155
  schema_define do
155
- create_table :test_posts, :force => true do |t|
156
+ create_table :test_posts, force: true do |t|
156
157
  t.string :title
157
158
  end
158
- create_table :test_comments, :force => true do |t|
159
- t.string :body, :limit => 4000
159
+ create_table :test_comments, force: true do |t|
160
+ t.string :body, limit: 4000
160
161
  t.references :test_post
161
162
  end
162
163
  end
@@ -165,7 +166,7 @@ describe "OracleEnhancedAdapter schema dump" do
165
166
  after(:each) do
166
167
  schema_define do
167
168
  remove_foreign_key :test_comments, :test_posts rescue nil
168
- remove_foreign_key :test_comments, :name => 'comments_posts_baz_fooz_fk' rescue nil
169
+ remove_foreign_key :test_comments, name: 'comments_posts_baz_fooz_fk' rescue nil
169
170
  end
170
171
  end
171
172
  after(:all) do
@@ -179,49 +180,49 @@ describe "OracleEnhancedAdapter schema dump" do
179
180
  schema_define do
180
181
  add_foreign_key :test_comments, :test_posts
181
182
  end
182
- standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", :name => "test_comments_test_post_id_fk"/
183
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", name: "test_comments_test_post_id_fk"/
183
184
  end
184
185
 
185
186
  it "should include foreign key with delete dependency in schema dump" do
186
187
  schema_define do
187
- add_foreign_key :test_comments, :test_posts, :dependent => :delete
188
+ add_foreign_key :test_comments, :test_posts, dependent: :delete
188
189
  end
189
- standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", :name => "test_comments_test_post_id_fk", :dependent => :delete/
190
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", name: "test_comments_test_post_id_fk", dependent: :delete/
190
191
  end
191
192
 
192
193
  it "should include foreign key with nullify dependency in schema dump" do
193
194
  schema_define do
194
- add_foreign_key :test_comments, :test_posts, :dependent => :nullify
195
+ add_foreign_key :test_comments, :test_posts, dependent: :nullify
195
196
  end
196
- standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", :name => "test_comments_test_post_id_fk", :dependent => :nullify/
197
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", name: "test_comments_test_post_id_fk", dependent: :nullify/
197
198
  end
198
199
 
199
200
  it "should not include foreign keys on ignored table names in schema dump" do
200
201
  schema_define do
201
202
  add_foreign_key :test_comments, :test_posts
202
203
  end
203
- standard_dump(:ignore_tables => %w(test_comments)).should_not =~ /add_foreign_key "test_comments"/
204
+ standard_dump(ignore_tables: %w(test_comments)).should_not =~ /add_foreign_key "test_comments"/
204
205
  end
205
206
 
206
207
  it "should not include foreign keys on ignored table regexes in schema dump" do
207
208
  schema_define do
208
209
  add_foreign_key :test_comments, :test_posts
209
210
  end
210
- standard_dump(:ignore_tables => [ /test_comments/i ]).should_not =~ /add_foreign_key "test_comments"/
211
+ standard_dump(ignore_tables: [ /test_comments/i ]).should_not =~ /add_foreign_key "test_comments"/
211
212
  end
212
213
 
213
214
  it "should include foreign keys referencing ignored table names in schema dump" do
214
215
  schema_define do
215
216
  add_foreign_key :test_comments, :test_posts
216
217
  end
217
- standard_dump(:ignore_tables => %w(test_posts)).should =~ /add_foreign_key "test_comments"/
218
+ standard_dump(ignore_tables: %w(test_posts)).should =~ /add_foreign_key "test_comments"/
218
219
  end
219
220
 
220
221
  it "should include foreign keys referencing ignored table regexes in schema dump" do
221
222
  schema_define do
222
223
  add_foreign_key :test_comments, :test_posts
223
224
  end
224
- standard_dump(:ignore_tables => [ /test_posts/i ]).should =~ /add_foreign_key "test_comments"/
225
+ standard_dump(ignore_tables: [ /test_posts/i ]).should =~ /add_foreign_key "test_comments"/
225
226
  end
226
227
 
227
228
  it "should include composite foreign keys" do
@@ -237,9 +238,9 @@ describe "OracleEnhancedAdapter schema dump" do
237
238
  add_column :test_comments, :baz_id, :integer
238
239
  add_column :test_comments, :fooz_id, :integer
239
240
 
240
- add_foreign_key :test_comments, :test_posts, :columns => ["baz_id", "fooz_id"], :name => 'comments_posts_baz_fooz_fk'
241
+ add_foreign_key :test_comments, :test_posts, columns: ["baz_id", "fooz_id"], name: 'comments_posts_baz_fooz_fk'
241
242
  end
242
- standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", :columns => \["baz_id", "fooz_id"\], :name => "comments_posts_baz_fooz_fk"/
243
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", columns: \["baz_id", "fooz_id"\], name: "comments_posts_baz_fooz_fk"/
243
244
  end
244
245
  it "should include foreign keys following all tables" do
245
246
  # if foreign keys preceed declaration of all tables
@@ -250,6 +251,26 @@ describe "OracleEnhancedAdapter schema dump" do
250
251
  dump = standard_dump
251
252
  dump.rindex("create_table").should < dump.index("add_foreign_key")
252
253
  end
254
+
255
+ it "should include primary_key when reference column name is not 'id'" do
256
+ schema_define do
257
+ create_table :test_posts, force: true, :primary_key => 'baz_id' do |t|
258
+ t.string :title
259
+ end
260
+ create_table :test_comments, force: true do |t|
261
+ t.string :body, limit: 4000
262
+ t.integer :baz_id
263
+ end
264
+ end
265
+
266
+ @conn.execute <<-SQL
267
+ ALTER TABLE TEST_COMMENTS
268
+ ADD CONSTRAINT TEST_COMMENTS_BAZ_ID_FK FOREIGN KEY (baz_id) REFERENCES test_posts(baz_id)
269
+ SQL
270
+
271
+ standard_dump.should =~ /add_foreign_key "test_comments", "test_posts", column: "baz_id", primary_key: "baz_id", name: "test_comments_baz_id_fk"/
272
+ end
273
+
253
274
  end
254
275
 
255
276
  describe "synonyms" do
@@ -261,37 +282,37 @@ describe "OracleEnhancedAdapter schema dump" do
261
282
 
262
283
  it "should include synonym to other schema table in schema dump" do
263
284
  schema_define do
264
- add_synonym :test_synonym, "schema_name.table_name", :force => true
285
+ add_synonym :test_synonym, "schema_name.table_name", force: true
265
286
  end
266
- standard_dump.should =~ /add_synonym "test_synonym", "schema_name.table_name", :force => true/
287
+ standard_dump.should =~ /add_synonym "test_synonym", "schema_name.table_name", force: true/
267
288
  end
268
289
 
269
290
  it "should include synonym to other database table in schema dump" do
270
291
  schema_define do
271
- add_synonym :test_synonym, "table_name@link_name", :force => true
292
+ add_synonym :test_synonym, "table_name@link_name", force: true
272
293
  end
273
- standard_dump.should =~ /add_synonym "test_synonym", "table_name@link_name(\.[-A-Za-z0-9_]+)*", :force => true/
294
+ standard_dump.should =~ /add_synonym "test_synonym", "table_name@link_name(\.[-A-Za-z0-9_]+)*", force: true/
274
295
  end
275
296
 
276
297
  it "should not include ignored table names in schema dump" do
277
298
  schema_define do
278
- add_synonym :test_synonym, "schema_name.table_name", :force => true
299
+ add_synonym :test_synonym, "schema_name.table_name", force: true
279
300
  end
280
- standard_dump(:ignore_tables => %w(test_synonym)).should_not =~ /add_synonym "test_synonym"/
301
+ standard_dump(ignore_tables: %w(test_synonym)).should_not =~ /add_synonym "test_synonym"/
281
302
  end
282
303
 
283
304
  it "should not include ignored table regexes in schema dump" do
284
305
  schema_define do
285
- add_synonym :test_synonym, "schema_name.table_name", :force => true
306
+ add_synonym :test_synonym, "schema_name.table_name", force: true
286
307
  end
287
- standard_dump(:ignore_tables => [ /test_synonym/i ]).should_not =~ /add_synonym "test_synonym"/
308
+ standard_dump(ignore_tables: [ /test_synonym/i ]).should_not =~ /add_synonym "test_synonym"/
288
309
  end
289
310
 
290
311
  it "should include synonyms to ignored table regexes in schema dump" do
291
312
  schema_define do
292
- add_synonym :test_synonym, "schema_name.table_name", :force => true
313
+ add_synonym :test_synonym, "schema_name.table_name", force: true
293
314
  end
294
- standard_dump(:ignore_tables => [ /table_name/i ]).should =~ /add_synonym "test_synonym"/
315
+ standard_dump(ignore_tables: [ /table_name/i ]).should =~ /add_synonym "test_synonym"/
295
316
  end
296
317
 
297
318
  end
@@ -302,8 +323,8 @@ describe "OracleEnhancedAdapter schema dump" do
302
323
  end
303
324
 
304
325
  it "should include temporary options" do
305
- create_test_posts_table(:temporary => true)
306
- standard_dump.should =~ /create_table "test_posts", :temporary => true/
326
+ create_test_posts_table(temporary: true)
327
+ standard_dump.should =~ /create_table "test_posts", temporary: true/
307
328
  end
308
329
  end
309
330
 
@@ -314,20 +335,20 @@ describe "OracleEnhancedAdapter schema dump" do
314
335
 
315
336
  it "should not specify default tablespace in add index" do
316
337
  create_test_posts_table
317
- standard_dump.should =~ /add_index "test_posts", \["title"\], :name => "index_test_posts_on_title"$/
338
+ standard_dump.should =~ /add_index "test_posts", \["title"\], name: "index_test_posts_on_title"$/
318
339
  end
319
340
 
320
341
  it "should specify non-default tablespace in add index" do
321
342
  tablespace_name = @conn.default_tablespace
322
343
  @conn.stub!(:default_tablespace).and_return('dummy')
323
344
  create_test_posts_table
324
- standard_dump.should =~ /add_index "test_posts", \["title"\], :name => "index_test_posts_on_title", :tablespace => "#{tablespace_name}"$/
345
+ standard_dump.should =~ /add_index "test_posts", \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/
325
346
  end
326
347
 
327
348
  it "should create and dump function-based indexes" do
328
349
  create_test_posts_table
329
- @conn.add_index :test_posts, "NVL(created_at, updated_at)", :name => "index_test_posts_cr_upd_at"
330
- standard_dump.should =~ /add_index "test_posts", \["NVL\(\\"CREATED_AT\\",\\"UPDATED_AT\\"\)"\], :name => "index_test_posts_cr_upd_at"$/
350
+ @conn.add_index :test_posts, "NVL(created_at, updated_at)", name: "index_test_posts_cr_upd_at"
351
+ standard_dump.should =~ /add_index "test_posts", \["NVL\(\\"CREATED_AT\\",\\"UPDATED_AT\\"\)"\], name: "index_test_posts_cr_upd_at"$/
331
352
  end
332
353
 
333
354
  end
@@ -347,7 +368,7 @@ describe "OracleEnhancedAdapter schema dump" do
347
368
 
348
369
  describe 'virtual columns' do
349
370
  before(:all) do
350
- if @oracle11g
371
+ if @oracle11g_or_higher
351
372
  schema_define do
352
373
  create_table :test_names, :force => true do |t|
353
374
  t.string :first_name
@@ -355,6 +376,7 @@ describe "OracleEnhancedAdapter schema dump" do
355
376
  t.virtual :full_name, :as => "first_name || ', ' || last_name"
356
377
  t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
357
378
  t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
379
+ t.virtual :name_ratio, :as=>'(LENGTH(first_name)/LENGTH(last_name))'
358
380
  t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
359
381
  t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
360
382
  end
@@ -365,31 +387,45 @@ describe "OracleEnhancedAdapter schema dump" do
365
387
  end
366
388
 
367
389
  before(:each) do
368
- if @oracle11g
390
+ if @oracle11g_or_higher
369
391
  class ::TestName < ActiveRecord::Base
370
- if self.respond_to?(:table_name=)
371
- self.table_name = "test_names"
372
- else
373
- set_table_name "test_names"
374
- end
392
+ self.table_name = "test_names"
375
393
  end
376
394
  end
377
395
  end
378
396
 
379
397
  after(:all) do
380
- if @oracle11g
398
+ if @oracle11g_or_higher
381
399
  schema_define do
382
400
  drop_table :test_names
383
401
  end
384
402
  end
385
403
  end
386
404
 
387
- it 'should dump correctly' do
388
- standard_dump.should =~ /t\.virtual "full_name",(\s*):limit => 512,(\s*):as => "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*):type => :string/
389
- standard_dump.should =~ /t\.virtual "short_name",(\s*):limit => 300,(\s*):as =>(.*),(\s*):type => :string/
390
- standard_dump.should =~ /t\.virtual "full_name_length",(\s*):precision => 38,(\s*):scale => 0,(\s*):as =>(.*),(\s*):type => :integer/
391
- standard_dump.should =~ /t\.virtual "abbrev_name",(\s*):limit => 100,(\s*):as =>(.*),(\s*):type => :string/
392
- standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*):limit => 300,(\s*):as => "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*):type => :string/
405
+ context "when number_datatype_coercion is :float" do
406
+ before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
407
+
408
+ it 'should dump correctly' do
409
+ standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
410
+ standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
411
+ standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)scale: 0,(\s*)as:(.*),(\s*)type: :integer/
412
+ standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*),(\s*)type: :float$/
413
+ standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
414
+ standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
415
+ end
416
+ end
417
+
418
+ context "when number_datatype_coercion is :decimal" do
419
+ before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
420
+
421
+ it 'should dump correctly' do
422
+ standard_dump.should =~ /t\.virtual "full_name",(\s*)limit: 512,(\s*)as: "\\"FIRST_NAME\\"\|\|', '\|\|\\"LAST_NAME\\"",(\s*)type: :string/
423
+ standard_dump.should =~ /t\.virtual "short_name",(\s*)limit: 300,(\s*)as:(.*),(\s*)type: :string/
424
+ standard_dump.should =~ /t\.virtual "full_name_length",(\s*)precision: 38,(\s*)scale: 0,(\s*)as:(.*),(\s*)type: :integer/
425
+ standard_dump.should =~ /t\.virtual "name_ratio",(\s*)as:(.*)\"$/
426
+ standard_dump.should =~ /t\.virtual "abbrev_name",(\s*)limit: 100,(\s*)as:(.*),(\s*)type: :string/
427
+ standard_dump.should =~ /t\.virtual "field_with_leading_space",(\s*)limit: 300,(\s*)as: "' '\|\|\\"FIRST_NAME\\"\|\|' '",(\s*)type: :string/
428
+ end
393
429
  end
394
430
 
395
431
  context 'with column cache' do
@@ -415,14 +451,14 @@ describe "OracleEnhancedAdapter schema dump" do
415
451
 
416
452
  context "with index on virtual column" do
417
453
  before(:all) do
418
- if @oracle11g
454
+ if @oracle11g_or_higher
419
455
  schema_define do
420
456
  add_index 'test_names', 'field_with_leading_space', :name => "index_on_virtual_col"
421
457
  end
422
458
  end
423
459
  end
424
460
  after(:all) do
425
- if @oracle11g
461
+ if @oracle11g_or_higher
426
462
  schema_define do
427
463
  remove_index 'test_names', :name => 'index_on_virtual_col'
428
464
  end
@@ -435,4 +471,160 @@ describe "OracleEnhancedAdapter schema dump" do
435
471
  end
436
472
  end
437
473
 
474
+ describe "NUMBER columns" do
475
+ after(:each) do
476
+ schema_define do
477
+ drop_table "test_numbers"
478
+ end
479
+ end
480
+
481
+ let(:value_within_max_precision) { (10 ** @conn.class::NUMBER_MAX_PRECISION) - 1 }
482
+ let(:value_exceeding_max_precision) { (10 ** @conn.class::NUMBER_MAX_PRECISION) + 1 }
483
+
484
+ context "when using ActiveRecord::Schema.define and ActiveRecord::ConnectionAdapters::TableDefinition#float" do
485
+ before :each do
486
+ schema_define do
487
+ create_table :test_numbers, :force => true do |t|
488
+ t.float :value
489
+ end
490
+ end
491
+ end
492
+
493
+ context "when number_datatype_coercion is :float" do
494
+ before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
495
+
496
+ it "should dump correctly" do
497
+ standard_dump.should =~ /t\.float "value"$/
498
+ end
499
+ end
500
+
501
+ context "when number_datatype_coercion is :decimal" do
502
+ before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
503
+
504
+ it "should dump correctly" do
505
+ standard_dump.should =~ /t\.decimal "value"$/
506
+ end
507
+ end
508
+ end
509
+
510
+ context "when using handwritten 'CREATE_TABLE' SQL" do
511
+ before :each do
512
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
513
+ @conn = ActiveRecord::Base.connection
514
+ @conn.execute <<-SQL
515
+ CREATE TABLE test_numbers (
516
+ id NUMBER(#{@conn.class::NUMBER_MAX_PRECISION},0) PRIMARY KEY,
517
+ value NUMBER
518
+ )
519
+ SQL
520
+ @conn.execute <<-SQL
521
+ CREATE SEQUENCE test_numbers_seq MINVALUE 1
522
+ INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
523
+ SQL
524
+ end
525
+
526
+ context "when number_datatype_coercion is :float" do
527
+ before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:float) }
528
+
529
+ it "should dump correctly" do
530
+ standard_dump.should =~ /t\.float "value"$/
531
+ end
532
+
533
+ describe "ActiveRecord saving" do
534
+ before :each do
535
+ class ::TestNumber < ActiveRecord::Base
536
+ self.table_name = "test_numbers"
537
+ end
538
+ end
539
+
540
+ it "should allow saving of values within NUMBER_MAX_PRECISION" do
541
+ number = TestNumber.new(value: value_within_max_precision)
542
+ number.save!
543
+ number.reload
544
+ number.value.should eq(value_within_max_precision)
545
+ end
546
+
547
+ it "should allow saving of values larger than NUMBER_MAX_PRECISION" do
548
+ number = TestNumber.new(value: value_exceeding_max_precision)
549
+ number.save!
550
+ number.reload
551
+ number.value.should eq(value_exceeding_max_precision)
552
+ end
553
+
554
+ it "should be recreatable from dump and have same properties" do
555
+ # Simulating db:schema:dump & db:test:load
556
+ 2.times do
557
+ create_table_dump = standard_dump[/(create_table.+?end)/m]
558
+
559
+ schema_define do
560
+ drop_table "test_numbers"
561
+ end
562
+
563
+ schema_define(&eval("-> * { #{create_table_dump} }"))
564
+ end
565
+
566
+ number = TestNumber.new(value: value_within_max_precision)
567
+ number.save!
568
+
569
+ number2 = TestNumber.new(value: value_exceeding_max_precision)
570
+ number2.save!
571
+ end
572
+ end
573
+ end
574
+
575
+ context "when number_datatype_coercion is :decimal" do
576
+ before { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.stub(:number_datatype_coercion).and_return(:decimal) }
577
+
578
+ it "should dump correctly" do
579
+ standard_dump.should =~ /t\.decimal "value"$/
580
+ end
581
+
582
+ describe "ActiveRecord saving" do
583
+ before :each do
584
+ class ::TestNumber < ActiveRecord::Base
585
+ self.table_name = "test_numbers"
586
+ end
587
+ end
588
+
589
+ it "should allow saving of values within NUMBER_MAX_PRECISION" do
590
+ number = TestNumber.new(value: value_within_max_precision)
591
+ number.save!
592
+ number.reload
593
+ number.value.should eq(value_within_max_precision)
594
+ end
595
+
596
+ it "should allow saving of values larger than NUMBER_MAX_PRECISION" do
597
+ number = TestNumber.new(value: value_exceeding_max_precision)
598
+ number.save!
599
+ number.reload
600
+ number.value.should eq(value_exceeding_max_precision)
601
+ end
602
+
603
+ it "should be recreatable from dump and have same properties" do
604
+ # Simulating db:schema:dump & db:test:load
605
+ 2.times do |i|
606
+ create_table_dump = standard_dump[/(create_table.+?end)/m]
607
+
608
+ schema_define do
609
+ drop_table "test_numbers"
610
+ end
611
+
612
+ schema_define(&eval("-> * { #{create_table_dump} }"))
613
+ end
614
+
615
+ number = TestNumber.new(value: value_within_max_precision)
616
+ number.save!
617
+
618
+ # Raises 'ORA-01438' as :value column type isn't FLOAT'ish
619
+ number2 = TestNumber.new(value: value_exceeding_max_precision)
620
+ lambda do
621
+ number2.save!
622
+ end.should raise_error() { |e| e.message.should =~ /ORA-01438/ }
623
+ end
624
+ end
625
+ end # context (:decimal)
626
+
627
+ end # context (handwritten)
628
+ end # describe (NUMBER columns)
629
+
438
630
  end