oracle-model-generator 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b08bfd1eb4571ecdbbf5cc02f216581514367d88
4
- data.tar.gz: cfeb424ff1b19a26f265b3e8a04969931973ef8b
3
+ metadata.gz: 88af1ec7da51ae892d01e8115190a2ea950304bd
4
+ data.tar.gz: 3e2baf456b61aa2f2ac34ca76cb20f7da51b690c
5
5
  SHA512:
6
- metadata.gz: a284019c0512deb281022efda26bfa11b04264e1eb7f4767862cd88fb661567ef1464ba0cc4bf4416312907c739a8e0248d7c649dd7f2253b9cb33e3be00dfee
7
- data.tar.gz: f9fd0d86eddafb2417c4d6ca4a1b077e57742cd5a9fe9e29eacfad6e6d420aa94fc006a07ec3ac1f650dc6927899a36d07bf052620884f8dac859c841915923e
6
+ metadata.gz: 32f50b665bc2e1756858fee86362a4cccf4d307fc30cd11cc78f7809418da77cfb8e6e8eb1eac7da81d72d2b21cd3a9b88f9ff9e7ee12e4ba224451bfd520482
7
+ data.tar.gz: 3dff9390c919127c9aa95300b883d3bf69f8b3caa599f5f47912d62ae9ef0795a98084dea7674103ce53d09ef91e5173b1233220998a6a3f22b2c612785353bd
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ = 0.4.0 - 7-Nov-2014
2
+ * Added support for minitest test file output.
3
+
1
4
  = 0.3.2 - 6-Nov-2014
2
5
  * Removed explicit references to Rails 3 in documentation. It's now simply
3
6
  Rails 2, or Rails 3 or higher.
data/bin/omg CHANGED
@@ -36,7 +36,7 @@ def help
36
36
  -u, --user => The user used to establish a connection to the database.
37
37
  -p, --password => The password used to establish a connection to the database.
38
38
  -r, --rails => The version of rails you're using (2 or higher).
39
- -x, --tests => Generate tests (the default).
39
+ -x, --tests => Generate tests using testunit, minitest or rspec.
40
40
  -c, --class => Class name for the generated table (optional)
41
41
 
42
42
  If no user or password are supplied, then OMG will attempt to glean that
@@ -51,7 +51,8 @@ def help
51
51
 
52
52
  If no tests option is specified then a test file, using test-unit 2, will
53
53
  be generated that includes some basic tests to backup the builtin
54
- validations. Legal options are 'testunit', 'rspec', or 'none'.
54
+ validations. Legal options are 'testunit', 'minitest', 'rspec', or 'none'.
55
+ If you specify 'none', then no test file is generated.
55
56
 
56
57
  Examples:
57
58
 
@@ -269,30 +270,57 @@ File.open(ofile, 'w') do |fh|
269
270
  fh.puts "end"
270
271
  end
271
272
 
272
- if opts['x'].nil? || opts['x'] == 'testunit'
273
+ opts['x'] ||= 'testunit' # Default
274
+
275
+ testunit = opts['x'] == 'testunit'
276
+ minitest = opts['x'] == 'minitest'
277
+
278
+ if testunit || minitest
273
279
  test_file = "test_#{ofile}"
280
+
274
281
  File.open(test_file, "w") do |fh|
275
282
  setup_var = omg.table.downcase
276
283
  setup_var.chop! if setup_var[-1].chr.downcase == 's'
277
284
  instance_var = "@#{setup_var}"
278
285
 
279
- fh.puts "require 'test-unit'\n\n"
286
+ if testunit
287
+ fh.puts "require 'test-unit'\n\n"
288
+ else
289
+ fh.puts "require 'minitest/autorun'\n\n"
290
+ end
291
+
292
+ if testunit
293
+ fh.puts "class TC_#{omg.model} < Test::Unit::TestCase\n"
294
+ else
295
+ fh.puts "class TC_#{omg.model} < Minitest::Unit::TestCase\n"
296
+ end
280
297
 
281
- fh.puts "class TC_#{omg.model} < Test::Unit::TestCase\n"
282
298
  fh.puts " def setup"
283
299
  fh.puts " #{instance_var} = #{omg.model}.new"
284
300
  fh.puts " end\n\n"
285
301
 
286
- fh.puts " test 'table name is #{omg.table.downcase}' do"
302
+ if testunit
303
+ fh.puts " test 'table name is #{omg.table.downcase}' do"
304
+ else
305
+ fh.puts " def table_name_is_#{omg.table.downcase}"
306
+ end
287
307
  fh.puts " assert_equal('#{omg.table.downcase}', #{omg.model}.table_name)"
288
308
  fh.puts " end\n\n"
289
309
 
290
310
  if omg.primary_keys.size > 1
291
- test_string = " test 'primary keys are #{omg.primary_keys.join(', ')}' do"
311
+ if testunit
312
+ test_string = " test 'primary keys are #{omg.primary_keys.join(', ')}' do"
313
+ else
314
+ test_string = " def test_primary_keys_are_#{omg.primary_keys.join('_')}"
315
+ end
292
316
  fh.puts test_string
293
317
  fh.puts " assert_equal('#{omg.primary_keys.join(', ')}', #{omg.model}.primary_keys)"
294
318
  else
295
- test_string = " test 'primary key is #{omg.primary_keys.first}' do"
319
+ if testunit
320
+ test_string = " test 'primary key is #{omg.primary_keys.first}' do"
321
+ else
322
+ test_string = " def test_primary_key_is_#{omg.primary_keys.first}"
323
+ end
296
324
  fh.puts test_string
297
325
  fh.puts " assert_equal('#{omg.primary_keys.first}', #{omg.model}.primary_key)"
298
326
  end
@@ -303,28 +331,48 @@ if opts['x'].nil? || opts['x'] == 'testunit'
303
331
  data_type = col.data_type.to_s
304
332
  column = col.name.downcase
305
333
 
306
- fh.puts "\n test '#{column} basic functionality' do"
334
+ if testunit
335
+ fh.puts "\n test '#{column} basic functionality' do"
336
+ else
337
+ fh.puts "\n def test_#{column}_basic_functionality"
338
+ end
307
339
  fh.puts " assert_respond_to(#{instance_var}, :#{column})"
308
- fh.puts " assert_nothing_raised{ #{instance_var}.#{column} }"
340
+ fh.puts " assert_nothing_raised{ #{instance_var}.#{column} }" if testunit
309
341
 
310
342
  case data_type
311
343
  when 'char', 'varchar', 'varchar2'
312
344
  if col.nullable?
313
- fh.puts " assert_kind_of([NilClass, String], #{instance_var}.#{column})"
345
+ if testunit
346
+ fh.puts " assert_kind_of([NilClass, String], #{instance_var}.#{column})"
347
+ else
348
+ fh.puts " assert([NilClass, String].include?(#{instance_var}.#{column}.class))"
349
+ end
314
350
  else
315
351
  fh.puts " assert_kind_of(String, #{instance_var}.#{column})"
316
352
  end
317
353
  when 'number'
318
354
  if col.nullable?
319
- fh.puts " assert_kind_of([NilClass, Numeric], #{instance_var}.#{column})"
355
+ if testunit
356
+ fh.puts " assert_kind_of([NilClass, Numeric], #{instance_var}.#{column})"
357
+ else
358
+ fh.puts " assert([NilClass, Numeric].include?(#{instance_var}.#{column}.class))"
359
+ end
320
360
  else
321
361
  fh.puts " assert_kind_of(Numeric, #{instance_var}.#{column})"
322
362
  end
323
363
  when 'date'
324
- if col.nullable?
325
- fh.puts " assert_kind_of([NilClass, DateTime, Time], #{instance_var}.#{column})"
364
+ if testunit
365
+ if col.nullable?
366
+ fh.puts " assert_kind_of([NilClass, DateTime, Time], #{instance_var}.#{column})"
367
+ else
368
+ fh.puts " assert_kind_of([DateTime, Time], #{instance_var}.#{column})"
369
+ end
326
370
  else
327
- fh.puts " assert_kind_of([DateTime, Time], #{instance_var}.#{column})"
371
+ if col.nullable?
372
+ fh.puts " assert([NilClass, DateTime, Time].include?(#{instance_var}.#{column}.class))"
373
+ else
374
+ fh.puts " assert([DateTime, Time].include?(#{instance_var}.#{column}.class))"
375
+ end
328
376
  end
329
377
  end
330
378
 
@@ -332,40 +380,77 @@ if opts['x'].nil? || opts['x'] == 'testunit'
332
380
 
333
381
  case data_type
334
382
  when 'char', 'varchar', 'varchar2'
335
- test_title = "\n test '#{column} must be a string"
336
- test_title += " if present" if col.nullable?
337
- test_title += "' do"
383
+ if testunit
384
+ test_title = "\n test '#{column} must be a string"
385
+ test_title += " if present" if col.nullable?
386
+ test_title += "' do"
387
+ else
388
+ test_title = "\n def test_#{column}_must_be_a_string"
389
+ test_title += "_if_present" if col.nullable?
390
+ end
338
391
 
339
392
  fh.puts test_title
340
393
  fh.puts " #{instance_var}.#{column} = #{rand(100)}"
341
- fh.puts " assert_false(#{instance_var}.valid?)"
342
- fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('is not a string'))"
394
+ if testunit
395
+ fh.puts " assert_false(#{instance_var}.valid?)"
396
+ fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('is not a string'))"
397
+ else
398
+ fh.puts " assert(!#{instance_var}.valid?)"
399
+ fh.puts " assert(#{instance_var}.errors[:#{column}].include?('is not a string'))"
400
+ end
343
401
  fh.puts " end\n"
344
402
 
345
403
  max_len = col.data_size
346
404
  err_msg = "is too long (maximum is #{max_len} characters)"
347
405
 
348
- fh.puts "\n test '#{column} cannot exceed #{max_len} characters' do"
406
+ if testunit
407
+ fh.puts "\n test '#{column} cannot exceed #{max_len} characters' do"
408
+ else
409
+ fh.puts "\n def test_#{column}_cannot_exceed_#{max_len}_characters"
410
+ end
411
+
349
412
  fh.puts " #{instance_var}.#{column} = 'a' * #{max_len + 1}"
350
- fh.puts " assert_false(#{instance_var}.valid?)"
351
- fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
413
+
414
+ if testunit
415
+ fh.puts " assert_false(#{instance_var}.valid?)"
416
+ fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
417
+ else
418
+ fh.puts " assert(!#{instance_var}.valid?)"
419
+ fh.puts " assert(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
420
+ end
352
421
  fh.puts " end\n"
353
422
  when 'number'
354
- test_title = "\n test '#{column} must be a number"
355
- test_title += " if present" if col.nullable?
356
- test_title += "' do"
423
+ if testunit
424
+ test_title = "\n test '#{column} must be a number"
425
+ test_title += " if present" if col.nullable?
426
+ test_title += "' do"
427
+ else
428
+ test_title = "\n def test_#{column}_must_be_a_number"
429
+ test_title += "_if_present" if col.nullable?
430
+ end
357
431
 
358
432
  fh.puts test_title
359
433
  fh.puts " #{instance_var}.#{column} = 'test_string'"
360
- fh.puts " assert_false(#{instance_var}.valid?)"
361
- fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('is not a number'))"
434
+
435
+ if testunit
436
+ fh.puts " assert_false(#{instance_var}.valid?)"
437
+ fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('is not a number'))"
438
+ else
439
+ fh.puts " assert(!#{instance_var}.valid?)"
440
+ fh.puts " assert(#{instance_var}.errors[:#{column}].include?('is not a number'))"
441
+ end
442
+
362
443
  fh.puts " end\n"
363
444
 
364
445
  max = "9" * col.precision
365
446
  max.insert(col.precision - col.scale, ".") if col.scale > 0
366
447
  err_msg = "must be less than or equal to #{max}"
367
448
 
368
- fh.puts "\n test '#{column} cannot exceed the value #{max}' do"
449
+ if testunit
450
+ fh.puts "\n test '#{column} cannot exceed the value #{max}' do"
451
+ else
452
+ fh.puts "\n def test_#{column}_cannot_exceed_the_value_#{max.sub('.', '_')}"
453
+ end
369
454
 
370
455
  if col.scale > 0
371
456
  fh.puts " #{instance_var}.#{column} = #{max.to_f.round}"
@@ -373,13 +458,23 @@ if opts['x'].nil? || opts['x'] == 'testunit'
373
458
  fh.puts " #{instance_var}.#{column} = #{max.to_i + 1}"
374
459
  end
375
460
 
376
- fh.puts " assert_false(#{instance_var}.valid?)"
377
- fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
461
+ if testunit
462
+ fh.puts " assert_false(#{instance_var}.valid?)"
463
+ fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
464
+ else
465
+ fh.puts " assert(!#{instance_var}.valid?)"
466
+ fh.puts " assert(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
467
+ end
468
+
378
469
  fh.puts " end\n"
379
470
 
380
471
  err_msg = "must be greater than or equal to -#{max}"
381
472
 
382
- fh.puts "\n test '#{column} cannot be less than the value -#{max}' do"
473
+ if testunit
474
+ fh.puts "\n test '#{column} cannot be less than the value -#{max}' do"
475
+ else
476
+ fh.puts "\n def test_#{column}_cannot_be_less_than_the_value_#{max.sub('.', '_')}"
477
+ end
383
478
 
384
479
  if col.scale > 0
385
480
  fh.puts " #{instance_var}.#{column} = -#{max.to_f.round}"
@@ -387,17 +482,31 @@ if opts['x'].nil? || opts['x'] == 'testunit'
387
482
  fh.puts " #{instance_var}.#{column} = -#{max.to_i + 1}"
388
483
  end
389
484
 
390
- fh.puts " assert_false(#{instance_var}.valid?)"
391
- fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
485
+ if testunit
486
+ fh.puts " assert_false(#{instance_var}.valid?)"
487
+ fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
488
+ else
489
+ fh.puts " assert(!#{instance_var}.valid?)"
490
+ fh.puts " assert(#{instance_var}.errors[:#{column}].include?('#{err_msg}'))"
491
+ end
392
492
  fh.puts " end\n"
393
493
  end
394
494
 
395
495
  unless col.nullable?
396
496
  err_msg = "can't be blank"
397
- fh.puts "\n test '#{column} cannot be nil' do"
497
+ if testunit
498
+ fh.puts "\n test '#{column} cannot be nil' do"
499
+ else
500
+ fh.puts "\n def test_#{column}_cannot_be_nil"
501
+ end
398
502
  fh.puts " #{instance_var}.#{column} = nil"
399
- fh.puts " assert_false(#{instance_var}.valid?)"
400
- fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?(\"#{err_msg}\"))"
503
+ if testunit
504
+ fh.puts " assert_false(#{instance_var}.valid?)"
505
+ fh.puts " assert_true(#{instance_var}.errors[:#{column}].include?(\"#{err_msg}\"))"
506
+ else
507
+ fh.puts " assert(!#{instance_var}.valid?)"
508
+ fh.puts " assert(#{instance_var}.errors[:#{column}].include?(\"#{err_msg}\"))"
509
+ end
401
510
  fh.puts " end\n"
402
511
  end
403
512
  }
@@ -4,7 +4,7 @@ module Oracle
4
4
  module Model
5
5
  class Generator
6
6
  # The version of the oracle-model-generator library
7
- VERSION = '0.3.2'
7
+ VERSION = '0.4.0'
8
8
 
9
9
  # The raw OCI8 connection.
10
10
  attr_reader :connection
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'oracle-model-generator'
5
- gem.version = '0.3.2'
5
+ gem.version = '0.4.0'
6
6
  gem.author = 'Daniel J. Berger'
7
7
  gem.license = 'Artistic 2.0'
8
8
  gem.email = 'djberg96@gmail.com'
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  gem.description = <<-EOF
22
22
  The oracle-model-generator library allows you to generate an ActiveRecord
23
- model from an existing Oracle table or view.
23
+ model from an existing Oracle table or view, as well as automatically
24
+ generate a baseline test file for test-unit or minitest.
24
25
  EOF
25
26
  end
@@ -20,7 +20,7 @@ class TC_Oracle_Model_Generator < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  test "version number is correct" do
23
- assert_equal('0.3.2', Oracle::Model::Generator::VERSION)
23
+ assert_equal('0.4.0', Oracle::Model::Generator::VERSION)
24
24
  end
25
25
 
26
26
  test "constructor accepts an oci8 connection object" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oracle-model-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-oci8
@@ -54,7 +54,8 @@ dependencies:
54
54
  version: '0'
55
55
  description: |2
56
56
  The oracle-model-generator library allows you to generate an ActiveRecord
57
- model from an existing Oracle table or view.
57
+ model from an existing Oracle table or view, as well as automatically
58
+ generate a baseline test file for test-unit or minitest.
58
59
  email: djberg96@gmail.com
59
60
  executables:
60
61
  - omg