factory_factory_girl 0.1.6 → 0.1.7
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/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/README.md +8 -6
- data/lib/factory_factory_girl/configuration.rb +4 -4
- data/lib/factory_factory_girl/generators/model_generator.rb +17 -11
- data/lib/factory_factory_girl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e00378a8673d2f63d8bef7bbcf2de904d264c41f
|
4
|
+
data.tar.gz: 080f37fff446f640f7aaaee917905c7ea6cb6a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 289e57f57699f7da373ff3336f95c43292bd4c1f39abcc62d7b82b203242d6500bfa725e2daad0d309ffbe87541a84bc558f4808ef9b905c89b67f3b63b17fbd
|
7
|
+
data.tar.gz: cf34bcdca96742d8f867416ee99e3729f77df05d959b3952889f37edf6196e8c3649be66d63b79fa9bd9195b1338fe7dfd7a0970bbad97564439cde02c26b84a
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
[](https://travis-ci.org/st0012/factory_factory_girl)
|
2
2
|
[](https://codeclimate.com/github/st0012/factory_factory_girl)
|
3
|
+
[](https://codeclimate.com/github/st0012/factory_factory_girl/coverage)
|
3
4
|
|
4
5
|
# FactoryFactoryGirl
|
5
6
|
|
6
7
|
## Mission
|
7
8
|
|
8
|
-
[FactoryGirl](https://github.com/thoughtbot/factory_girl/) is a
|
9
|
+
[FactoryGirl](https://github.com/thoughtbot/factory_girl/) is a really useful gem that lets us generate test data more efficiently. However, if you start with new projects very frequently, you will feel painful to write project's attributes, especially some commonly seen attributes.
|
9
10
|
|
10
|
-
For example, you use `FFaker::Job.title` to generate all your `name` or `title`'s value, and use `FFaker::Lorem.paragraph` to generate `description` or `content`'s value. Then you just need to
|
11
|
+
For example, you use `FFaker::Job.title` to generate all your `name` or `title`'s value, and use `FFaker::Lorem.paragraph` to generate `description` or `content`'s value. Then you just need to copy & paste those methods to serveral columns in serveral factories, or even in serveral project's factories.
|
11
12
|
|
12
13
|
So I created [FactoryFactoryGirl](https://github.com/st0012/factory_factory_girl). The mission of this gem is helping people generate their factory more quickly, with some pre-defined rules like:
|
13
14
|
|
@@ -15,9 +16,10 @@ So I created [FactoryFactoryGirl](https://github.com/st0012/factory_factory_girl
|
|
15
16
|
FactoryFactoryGirl.configure do |config|
|
16
17
|
config.match(/name|title/, function: "FFaker::Job.title")
|
17
18
|
config.match(/content|descripton/, function: "FFaker::Lorem.paragraph")
|
19
|
+
config.match(/country|region/, value: "Taiwan")
|
18
20
|
end
|
19
21
|
```
|
20
|
-
And
|
22
|
+
And run:
|
21
23
|
|
22
24
|
```
|
23
25
|
$ rails g factory_factory_girl:model post
|
@@ -34,13 +36,14 @@ FactoryGirl.define do
|
|
34
36
|
........
|
35
37
|
name { FFaker::Job.title }
|
36
38
|
content { FFaker::Lorem.paragraph }
|
39
|
+
country "Taiwan"
|
37
40
|
.......
|
38
41
|
end
|
39
42
|
```
|
40
43
|
|
41
|
-
And the rule you defined in this project, can be
|
44
|
+
And the rule you defined in this project, can be used in any other projects. You won't need to copy & paste the setting of those frequently seen column's.
|
42
45
|
|
43
|
-
I think this gem could be helpful, but also needs a lot work. So if you find any bug or want any feature, please open an issue or email me , thanks 😄.
|
46
|
+
I think this gem could be helpful, but also needs a lot of work. So if you find any bug or want any new feature, please open an issue or email me , thanks 😄.
|
44
47
|
|
45
48
|
|
46
49
|
## Installation
|
@@ -67,7 +70,6 @@ Set your generation rule in `initializers/factory_factory_girl` like
|
|
67
70
|
FactoryFactoryGirl.configure do |config|
|
68
71
|
config.match(/name|title/, function: "FFaker::Job.title")
|
69
72
|
config.match(/content|descripton/, function: "FFaker::Lorem.paragraph")
|
70
|
-
config.match(/id/, value: "10")
|
71
73
|
end
|
72
74
|
```
|
73
75
|
|
@@ -16,13 +16,13 @@ module FactoryFactoryGirl
|
|
16
16
|
@rails_options = {}
|
17
17
|
end
|
18
18
|
|
19
|
-
def match(
|
20
|
-
raise "Need to give attribute or process" if
|
19
|
+
def match(pattern, value: nil, function: nil)
|
20
|
+
raise "Need to give attribute or process" if value.nil? && function.nil?
|
21
21
|
|
22
22
|
if value
|
23
|
-
rules << {
|
23
|
+
rules << { pattern: pattern, value: value }
|
24
24
|
else
|
25
|
-
rules << {
|
25
|
+
rules << { pattern: pattern, function: function }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -19,14 +19,14 @@ module FactoryFactoryGirl
|
|
19
19
|
|
20
20
|
def set_column(attribute)
|
21
21
|
match_results = rules.map do |rule|
|
22
|
-
if attribute.name.match(rule[:
|
22
|
+
if attribute.name.match(rule[:pattern])
|
23
23
|
rule
|
24
24
|
end
|
25
25
|
end.compact
|
26
26
|
|
27
27
|
if applied_rule = match_results.first
|
28
28
|
if applied_rule[:value]
|
29
|
-
transfer_value_type(applied_rule[:value], attribute.type
|
29
|
+
transfer_value_type(applied_rule[:value], attribute.type)
|
30
30
|
else
|
31
31
|
"{ #{applied_rule[:function]} }"
|
32
32
|
end
|
@@ -37,10 +37,14 @@ module FactoryFactoryGirl
|
|
37
37
|
|
38
38
|
def transfer_value_type(value, type)
|
39
39
|
case type
|
40
|
-
when
|
40
|
+
when :string
|
41
41
|
"\"#{value}\""
|
42
|
-
when
|
42
|
+
when :text
|
43
|
+
"\"#{value}\""
|
44
|
+
when :integer
|
43
45
|
value.to_i
|
46
|
+
when :decimal
|
47
|
+
value.to_f
|
44
48
|
else
|
45
49
|
value
|
46
50
|
end
|
@@ -50,16 +54,18 @@ module FactoryFactoryGirl
|
|
50
54
|
if attribute.default
|
51
55
|
attribute.default
|
52
56
|
else
|
53
|
-
case attribute.type
|
54
|
-
when
|
57
|
+
case attribute.type
|
58
|
+
when :string
|
55
59
|
"\"MyString\""
|
56
|
-
when
|
57
|
-
1
|
58
|
-
when "text"
|
60
|
+
when :text
|
59
61
|
"\"MyText\""
|
60
|
-
when
|
62
|
+
when :integer
|
63
|
+
1
|
64
|
+
when :float
|
65
|
+
1.2
|
66
|
+
when :boolean
|
61
67
|
true
|
62
|
-
when
|
68
|
+
when :datetime
|
63
69
|
"\"#{Time.now}\""
|
64
70
|
else
|
65
71
|
nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_factory_girl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stan Low
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_girl_rails
|