factory_factory_girl 0.1.6 → 0.1.7

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: 9f26bd9110b27b0ee92b3a805dc45cd591f9f75e
4
- data.tar.gz: cec9e3f0416b9113ad849ec1503d77939e7561d1
3
+ metadata.gz: e00378a8673d2f63d8bef7bbcf2de904d264c41f
4
+ data.tar.gz: 080f37fff446f640f7aaaee917905c7ea6cb6a7d
5
5
  SHA512:
6
- metadata.gz: b7081e89e55836a554614af7b0d4b49c233ffa60b5091df57ad6ff234a5b945ae0e8afeaf2d8760253fd3e1958bbe25dc780024b2e5c1f79c9dbc3604cb4d743
7
- data.tar.gz: abdc25871cc8b91dec6447390bbf163ca9255ca0a1d8a259b3735f20f58f8375c12bb474ac106089c68af5722e5739ee8faa4f67216c9b22a77067ae2630258e
6
+ metadata.gz: 289e57f57699f7da373ff3336f95c43292bd4c1f39abcc62d7b82b203242d6500bfa725e2daad0d309ffbe87541a84bc558f4808ef9b905c89b67f3b63b17fbd
7
+ data.tar.gz: cf34bcdca96742d8f867416ee99e3729f77df05d959b3952889f37edf6196e8c3649be66d63b79fa9bd9195b1338fe7dfd7a0970bbad97564439cde02c26b84a
@@ -4,3 +4,6 @@ cache: bundler
4
4
  rvm:
5
5
  - 2.2.0
6
6
  before_install: gem install bundler -v 1.10.6
7
+
8
+ env:
9
+ - CODECLIMATE_REPO_TOKEN=a4bd4a771867fdd972aecf09a1888009a0733391c844cd94991aed1d1257bf56
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  [![Build Status](https://travis-ci.org/st0012/factory_factory_girl.svg?branch=master)](https://travis-ci.org/st0012/factory_factory_girl)
2
2
  [![Code Climate](https://codeclimate.com/github/st0012/factory_factory_girl/badges/gpa.svg)](https://codeclimate.com/github/st0012/factory_factory_girl)
3
+ [![Test Coverage](https://codeclimate.com/github/st0012/factory_factory_girl/badges/coverage.svg)](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 very useful gem, which lets us generate test data more efficiently. However, if you start new projects very frequently, you will feel painful writing every project's factory, especially when most of them have some common attributes.
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 cope & paste those methods to serveral columns in serveral factories, or even in serveral project's factories.
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 type:
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 use in any other projects. You won't need to copy & paste the setting of those frequently seen column's.
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(rule, value: nil, function: nil)
20
- raise "Need to give attribute or process" if value.nil? && function.nil?
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 << { rule: rule, value: value }
23
+ rules << { pattern: pattern, value: value }
24
24
  else
25
- rules << { rule: rule, function: function }
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[: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.to_s)
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 "string" || "text"
40
+ when :string
41
41
  "\"#{value}\""
42
- when "integer"
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.to_s
54
- when "string"
57
+ case attribute.type
58
+ when :string
55
59
  "\"MyString\""
56
- when "integer"
57
- 1
58
- when "text"
60
+ when :text
59
61
  "\"MyText\""
60
- when "boolean"
62
+ when :integer
63
+ 1
64
+ when :float
65
+ 1.2
66
+ when :boolean
61
67
  true
62
- when "datetime"
68
+ when :datetime
63
69
  "\"#{Time.now}\""
64
70
  else
65
71
  nil
@@ -1,3 +1,3 @@
1
1
  module FactoryFactoryGirl
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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.6
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-13 00:00:00.000000000 Z
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