factory-helper 1.7.1 → 1.7.2
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.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/factory-helper.rb +1 -0
- data/lib/factory-helper/my_sql.rb +89 -0
- data/lib/factory-helper/version.rb +1 -1
- data/lib/locales/en-US.yml +1 -1
- data/lib/locales/en.yml +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49290064ffe7f5787ab0ef9b4e1917d9e628c7ed
|
4
|
+
data.tar.gz: bd0fe13ab86afbe4e142c8f883be914dcbd6b364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11921bb744d08e0c15f763fd36c3b85b902f0f511a2886e2c7187ea88364d6f01123abba6e49b46e64a1759c830bd47a7db10baa9402e421e9a45ff4aea0412e
|
7
|
+
data.tar.gz: 316220e2ebff579ef5015aaab6b4c1cf37be03cdf60b7b883d5e9cb4764251717da567ec004b389f218b22ddd2aa9d0d1b6323c567d8bdb6a423829af2ae0d4c
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ FactoryHelper::Company.bs #=> "revolutionize plug-and-play architectures"
|
|
54
54
|
|
55
55
|
###FactoryHelper::String
|
56
56
|
-----------------
|
57
|
-
Random UTF-8 string with an optional length argument
|
57
|
+
Random UTF-8 string with an optional length argument.
|
58
58
|
|
59
59
|
```ruby
|
60
60
|
FactoryHelper::String.random #=> "3 뇦\u0017&y\u{3A109}$8^4* 녹豿4좘툢ꔾ쉙6ɉ\uA6F8TN畀챵|\"3쇤Ŵ"
|
@@ -64,6 +64,20 @@ FactoryHelper::String.random([0, 6]) #=> "I轤𣴒P溟L"
|
|
64
64
|
```
|
65
65
|
|
66
66
|
|
67
|
+
###FactoryHelper::MySQL
|
68
|
+
-----------------
|
69
|
+
Generates values for a factory per the MySQL datatypes. Accepts options unsigned, min, max.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
FactoryHelper::MySQL.integer #=> 1729 (int & integer are equivalent)
|
73
|
+
FactoryHelper::MySQL.tinyint #=> 42
|
74
|
+
FactoryHelper::MySQL.bigint #=> 9223372036854775807
|
75
|
+
FactoryHelper::MySQL.smallint(unsigned: true) #=> 55777
|
76
|
+
FactoryHelper::MySQL.int(min: 0, max: 1319) #=> 998
|
77
|
+
FactoryHelper::MySQL.mediumint #=> 7456451
|
78
|
+
```
|
79
|
+
|
80
|
+
|
67
81
|
###FactoryHelper::Address
|
68
82
|
-----------------
|
69
83
|
|
data/lib/factory-helper.rb
CHANGED
@@ -0,0 +1,89 @@
|
|
1
|
+
module FactoryHelper
|
2
|
+
# created for MySQL 5.0 https://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
|
3
|
+
class MySQL < Base
|
4
|
+
INTEGERS= {
|
5
|
+
:tinyint => {
|
6
|
+
false => {:min => -128, :max => 127},
|
7
|
+
true => {:min => 0, :max => 255},
|
8
|
+
},
|
9
|
+
:smallint => {
|
10
|
+
false => {:min => -32768, :max => 32767},
|
11
|
+
true => {:min => 0, :max => 65535},
|
12
|
+
},
|
13
|
+
:mediumint => {
|
14
|
+
false => {:min => -8388608, :max => 8388607},
|
15
|
+
true => {:min => 0, :max => 16777215},
|
16
|
+
},
|
17
|
+
:integer => {
|
18
|
+
false => {:min => -2147483648, :max => 2147483647},
|
19
|
+
true => {:min => 0, :max => 4294967295},
|
20
|
+
},
|
21
|
+
:bigint => {
|
22
|
+
false => {:min => -9223372036854775808, :max => 9223372036854775807},
|
23
|
+
true => {:min => 0, :max => 18446744073709551615},
|
24
|
+
},
|
25
|
+
}
|
26
|
+
ArgumentError= Class.new(StandardError)
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def tinyint opt= {}
|
30
|
+
int_sanitize opt
|
31
|
+
int_with_edge_cases(int_limits_for :tinyint, opt)
|
32
|
+
end
|
33
|
+
|
34
|
+
def smallint opt= {}
|
35
|
+
[ tinyint(opt),
|
36
|
+
int_with_edge_cases(int_limits_for :smallint, opt),
|
37
|
+
].sample(:random => FactoryHelper::Config.random)
|
38
|
+
end
|
39
|
+
|
40
|
+
def mediumint opt= {}
|
41
|
+
[ smallint(opt),
|
42
|
+
int_with_edge_cases(int_limits_for :mediumint, opt),
|
43
|
+
].sample(:random => FactoryHelper::Config.random)
|
44
|
+
end
|
45
|
+
|
46
|
+
def integer opt= {}
|
47
|
+
[ mediumint(opt),
|
48
|
+
int_with_edge_cases(int_limits_for :integer, opt),
|
49
|
+
].sample(:random => FactoryHelper::Config.random)
|
50
|
+
end
|
51
|
+
|
52
|
+
def bigint opt= {}
|
53
|
+
[ integer(opt),
|
54
|
+
int_with_edge_cases(int_limits_for :bigint, opt),
|
55
|
+
].sample(:random => FactoryHelper::Config.random)
|
56
|
+
end
|
57
|
+
|
58
|
+
alias_method :int, :integer
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def int_with_edge_cases opt= {:min => -128, :max => 127}
|
63
|
+
[ int_edge_case_for(opt),
|
64
|
+
FactoryHelper::Config.random.rand(opt[:min].. opt[:max]),
|
65
|
+
FactoryHelper::Config.random.rand(opt[:min].. opt[:max]),
|
66
|
+
].sample(:random => FactoryHelper::Config.random)
|
67
|
+
end
|
68
|
+
|
69
|
+
def int_limits_for datatype= :integer, opt= {}
|
70
|
+
INTEGERS[datatype][!!opt[:unsigned]].merge(opt)
|
71
|
+
end
|
72
|
+
|
73
|
+
def int_edge_case_for opt= {:min => -128, :max => 127}
|
74
|
+
[-1, 1, 0, opt[:min], opt[:max]].keep_if do |element|
|
75
|
+
(opt[:min].. opt[:max]).include?(element)
|
76
|
+
end.sample(:random => FactoryHelper::Config.random)
|
77
|
+
end
|
78
|
+
|
79
|
+
def int_sanitize opt
|
80
|
+
raise ArgumentError, 'Argument list must be a hash.' unless opt.kind_of? Hash
|
81
|
+
raise ArgumentError, 'Must specify a min and a max, or neither.' if !!opt[:min]^ !!opt[:max]
|
82
|
+
raise ArgumentError, '`:min` must reference an Integer' if opt[:min]&& !opt[:min].kind_of?(Integer)
|
83
|
+
raise ArgumentError, '`:max` must reference an Integer' if opt[:max]&& !opt[:max].kind_of?(Integer)
|
84
|
+
raise ArgumentError, "Minimum(#{opt[:min]}) must not be less than zero when unsigned" if (opt[:unsigned]&& opt[:min]&& opt[:min]< 0)
|
85
|
+
raise ArgumentError, "Minimum(#{opt[:min]}) must be less than Maximum(#{opt[:max]})" if opt[:min]&& opt[:max]&& (opt[:max]< opt[:min])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/locales/en-US.yml
CHANGED
data/lib/locales/en.yml
CHANGED
@@ -95,7 +95,7 @@ en:
|
|
95
95
|
|
96
96
|
internet:
|
97
97
|
free_email: [gmail.com, yahoo.com, hotmail.com]
|
98
|
-
domain_suffix: [com, biz, info, name, net, org]
|
98
|
+
domain_suffix: [com, biz, info, name, net, org, io, co]
|
99
99
|
|
100
100
|
lorem:
|
101
101
|
words: [alias, consequatur, aut, perferendis, sit, voluptatem, accusantium, doloremque, aperiam, eaque, ipsa, quae, ab, illo, inventore, veritatis, et, quasi, architecto, beatae, vitae, dicta, sunt, explicabo, aspernatur, aut, odit, aut, fugit, sed, quia, consequuntur, magni, dolores, eos, qui, ratione, voluptatem, sequi, nesciunt, neque, dolorem, ipsum, quia, dolor, sit, amet, consectetur, adipisci, velit, sed, quia, non, numquam, eius, modi, tempora, incidunt, ut, labore, et, dolore, magnam, aliquam, quaerat, voluptatem, ut, enim, ad, minima, veniam, quis, nostrum, exercitationem, ullam, corporis, nemo, enim, ipsam, voluptatem, quia, voluptas, sit, suscipit, laboriosam, nisi, ut, aliquid, ex, ea, commodi, consequatur, quis, autem, vel, eum, iure, reprehenderit, qui, in, ea, voluptate, velit, esse, quam, nihil, molestiae, et, iusto, odio, dignissimos, ducimus, qui, blanditiis, praesentium, laudantium, totam, rem, voluptatum, deleniti, atque, corrupti, quos, dolores, et, quas, molestias, excepturi, sint, occaecati, cupiditate, non, provident, sed, ut, perspiciatis, unde, omnis, iste, natus, error, similique, sunt, in, culpa, qui, officia, deserunt, mollitia, animi, id, est, laborum, et, dolorum, fuga, et, harum, quidem, rerum, facilis, est, et, expedita, distinctio, nam, libero, tempore, cum, soluta, nobis, est, eligendi, optio, cumque, nihil, impedit, quo, porro, quisquam, est, qui, minus, id, quod, maxime, placeat, facere, possimus, omnis, voluptas, assumenda, est, omnis, dolor, repellendus, temporibus, autem, quibusdam, et, aut, consequatur, vel, illum, qui, dolorem, eum, fugiat, quo, voluptas, nulla, pariatur, at, vero, eos, et, accusamus, officiis, debitis, aut, rerum, necessitatibus, saepe, eveniet, ut, et, voluptates, repudiandae, sint, et, molestiae, non, recusandae, itaque, earum, rerum, hic, tenetur, a, sapiente, delectus, ut, aut, reiciendis, voluptatibus, maiores, doloribus, asperiores, repellat]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Avvakumov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/factory-helper/hacker.rb
|
120
120
|
- lib/factory-helper/internet.rb
|
121
121
|
- lib/factory-helper/lorem.rb
|
122
|
+
- lib/factory-helper/my_sql.rb
|
122
123
|
- lib/factory-helper/name.rb
|
123
124
|
- lib/factory-helper/number.rb
|
124
125
|
- lib/factory-helper/phone_number.rb
|