data_factory 0.1.3 → 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e822bc63cfb321de0f6c8c84644c1c34b1cf46e
4
+ data.tar.gz: 8669da85bf543f5f6cf3c96dbdf035211a973ea8
5
+ SHA512:
6
+ metadata.gz: be85d1e78d4a80058fdb8b4dc4b81bae88679eafd27a5231cf4f461af621bb8c47a58a334f3b0c18863df1f9fa6a85ef44df976251fe52db463ea8ff2a8881d2
7
+ data.tar.gz: b30aedf808030b04d31f080a91b33b30f9bbcc297474d82ff193a06aa3f85d5e3c874fa9379b70e2ac8cb8076cfbe2cc6dde170e3aeea0d5fee51ce028b2e725
@@ -148,7 +148,7 @@ module DataFactory
148
148
  # Oracle specific.
149
149
  def quote_value(col)
150
150
  case column_detail(col).data_type
151
- when 'CHAR', 'VARCHAR2', 'CLOB'
151
+ when 'CHAR', 'VARCHAR2', 'CLOB', 'RAW'
152
152
  "'#{@column_values[col]}'"
153
153
  when 'DATE', 'DATETIME'
154
154
  "to_date('#{@column_values[col].strftime('%Y%m%d %H:%M:%S')}', 'YYYYMMDD HH24:MI:SS')"
@@ -165,6 +165,8 @@ module DataFactory
165
165
  case col.data_type
166
166
  when 'CHAR', 'VARCHAR2', 'CLOB'
167
167
  random_string_upto_length(col.data_length)
168
+ when 'RAW'
169
+ random_hex_string_upto_length(col.data_length)
168
170
  when 'DATE', 'DATETIME', 'TIMESTAMP'
169
171
  Time.now
170
172
  when 'NUMBER', 'INTEGER'
@@ -206,7 +208,7 @@ module DataFactory
206
208
 
207
209
  def column_type_to_ruby_type(col)
208
210
  case col.data_type
209
- when 'CHAR', 'VARCHAR2', 'CLOB'
211
+ when 'CHAR', 'VARCHAR2', 'CLOB', 'RAW'
210
212
  String
211
213
  when 'DATE', 'DATETIME', 'TIMESTAMP'
212
214
  Time
@@ -143,7 +143,7 @@ module DataFactory
143
143
 
144
144
  table_details_sql = "select column_name,
145
145
  data_type,
146
- data_length,
146
+ nvl(char_length, data_length),
147
147
  data_precision,
148
148
  data_scale,
149
149
  column_id,
@@ -2,6 +2,7 @@ module DataFactory
2
2
  module Random
3
3
 
4
4
  CHARS = ['A'..'Z', 'a'..'z', '0'..'9'].map{|r|r.to_a}.flatten
5
+ HEX_CHARS = ['A'..'F', '0'..'9'].map{|r|r.to_a}.flatten
5
6
 
6
7
  # Generates a random string of letters and numbers of length
7
8
  def random_string_of_length(length)
@@ -12,6 +13,16 @@ module DataFactory
12
13
  str
13
14
  end
14
15
 
16
+ # Generates a random string of hex characters
17
+ def random_hex_string_of_length(length)
18
+ str = ''
19
+ # Binary length is double in ASCII
20
+ 1.upto(length*2) do
21
+ str << HEX_CHARS[rand(HEX_CHARS.size)]
22
+ end
23
+ str
24
+ end
25
+
15
26
  # Generates a random string of random length, which has a maximum
16
27
  # length of max_length
17
28
  def random_string_upto_length(max_length)
@@ -19,6 +30,13 @@ module DataFactory
19
30
  random_string_of_length(length)
20
31
  end
21
32
 
33
+ # Generates a hex string of random length, which has a maximum
34
+ # length of max_length
35
+ def random_hex_string_upto_length(max_length)
36
+ length = random_integer(max_length)
37
+ random_hex_string_of_length(length)
38
+ end
39
+
22
40
  # Generates a random integer that is at most max_size
23
41
  def random_integer(max_size)
24
42
  1 + rand(max_size)
@@ -116,7 +116,7 @@ class BaseAPITest < Test::Unit::TestCase
116
116
  def test_generate_data_generates_column_data_if_column_not_nullable
117
117
  instance = @klass.new
118
118
  instance.generate_column_data
119
- assert_not_nil(instance.column_value('COL3'))
119
+ assert_not_nil(instance.column_value('COL4'))
120
120
  end
121
121
 
122
122
  def test_generate_data_default_used_for_column_when_present
@@ -29,14 +29,23 @@ module TestHelper
29
29
  # Mock out returing a list of columns for a table.
30
30
  def each_array(&blk)
31
31
  data = [
32
- # cname, type len precision, scale, position, nullable
33
- ['col1', 'varchar2', 20, nil, nil, 1, 'Y'],
34
- ['col2', 'number', 20, 9, 2, 2, 'Y'],
35
- ['col3', 'DATE', 20, nil, nil, 3, 'N'],
36
- ['col4', 'varchar2', 20, nil, nil, 4, 'N'],
37
- ['col5', 'integer', 20, 38, 0, 5, 'N'],
38
- ['col6', 'number', 20, 20, 5, 6, 'N']
39
- ]
32
+ # cname, type len precision, scale, position, nullable
33
+ ['col1', 'varchar2', 20, nil, nil, 1, 'Y'],
34
+ ['col2', 'varchar2', 20, nil, nil, 2, 'N'],
35
+ ['col3', 'number', 20, 9, 2, 3, 'Y'],
36
+ ['col4', 'number', 20, 9, 2, 4, 'N'],
37
+ ['col5', 'integer', 20, 38, 0, 5, 'Y'],
38
+ ['col6', 'integer', 20, 38, 0, 6, 'N'],
39
+ ['col7', 'DATE', 20, nil, nil, 7, 'Y'],
40
+ ['col8', 'DATE', 20, nil, nil, 8, 'N'],
41
+ ['col9', 'TIMESTAMP',20, nil, nil, 9, 'Y'],
42
+ ['col10','TIMESTAMP',20, nil, nil, 10,'N'],
43
+ ['col11','raw', 20, nil, nil, 11,'Y'],
44
+ ['col12','raw', 20, nil, nil, 12,'N'],
45
+ ['col13','char', 20, nil, nil, 13,'Y'],
46
+ ['col14','char', 20, nil, nil, 14,'N']
47
+
48
+ ]
40
49
  data.each do |d|
41
50
  yield d
42
51
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stephen O'Donnell
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-17 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Generates data to insert into database tables, allowing columns to be
15
14
  defaulted or overriden. Intended to be used when testing wide tables where many
@@ -37,28 +36,26 @@ files:
37
36
  - README.md
38
37
  homepage: http://betteratoracle.com
39
38
  licenses: []
39
+ metadata: {}
40
40
  post_install_message:
41
41
  rdoc_options: []
42
42
  require_paths:
43
43
  - lib
44
44
  required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
45
  requirements:
47
- - - ! '>='
46
+ - - '>='
48
47
  - !ruby/object:Gem::Version
49
48
  version: '0'
50
49
  required_rubygems_version: !ruby/object:Gem::Requirement
51
- none: false
52
50
  requirements:
53
- - - ! '>='
51
+ - - '>='
54
52
  - !ruby/object:Gem::Version
55
53
  version: '0'
56
54
  requirements: []
57
55
  rubyforge_project:
58
- rubygems_version: 1.8.24
56
+ rubygems_version: 2.0.3
59
57
  signing_key:
60
- specification_version: 3
58
+ specification_version: 4
61
59
  summary: A gem to generate template insert statements for use when unit testing database
62
60
  code
63
61
  test_files: []
64
- has_rdoc: true