factory_girl 4.8.1 → 4.9.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: ceeca3f3f93cc3394beba00cb146418a0da7161b
4
- data.tar.gz: 475b27d583aaac3a83d769bb3be01d07a0a41b29
3
+ metadata.gz: e16a4a30eb303ecf77779a64966bb5542f4f1a19
4
+ data.tar.gz: a4a44676d4602a413fe5447d6a78ac62f8fd9a77
5
5
  SHA512:
6
- metadata.gz: 41d5105c3878506f0c0e27257d8ab250863db5abe33834e2c3fe1bcfdf962d61a000a3d06e382c506427b7b0d76ea6fc193a026321431694ee72db484047deff
7
- data.tar.gz: e7d20de687a85d18d924caf583006cd4abe39efc93eb15bb96edb8f331bd0f66d0d23d0289e99cf257fac8db518e8ab853d83bd822c8cb57f8455f09fcc9eb55
6
+ metadata.gz: 95d58dc9a5f1aa320431927c7a84af285c96d0cb7cd8a3ae0ee124658d7bff391f304e5977ac12c2f87f93b3bf0f0c816912c4b714c2dbc305657e5ecab64b90
7
+ data.tar.gz: 33928a2fc80baa62226a3a83fa19f144debe62b56cb047c88d511b2267ecd74f844f08d2083b9e2160f4d90fc7163be67fd167c98ffadc80101f0b1b63174bc6
@@ -986,14 +986,12 @@ namespace :factory_girl do
986
986
  desc "Verify that all FactoryGirl factories are valid"
987
987
  task lint: :environment do
988
988
  if Rails.env.test?
989
- begin
990
- DatabaseCleaner.start
989
+ DatabaseCleaner.cleaning do
991
990
  FactoryGirl.lint
992
- ensure
993
- DatabaseCleaner.clean
994
991
  end
995
992
  else
996
993
  system("bundle exec rake factory_girl:lint RAILS_ENV='test'")
994
+ exit $?.exitstatus
997
995
  end
998
996
  end
999
997
  end
@@ -1030,6 +1028,12 @@ This can also be combined with other arguments:
1030
1028
  FactoryGirl.lint factories_to_lint, traits: true
1031
1029
  ```
1032
1030
 
1031
+ You can also specify the strategy used for linting:
1032
+
1033
+ ```ruby
1034
+ FactoryGirl.lint strategy: :build
1035
+ ```
1036
+
1033
1037
  Custom Construction
1034
1038
  -------------------
1035
1039
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (4.8.1)
4
+ factory_girl (4.9.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2016 Joe Ferris and thoughtbot, inc.
1
+ Copyright (c) 2008-2017 Joe Ferris and thoughtbot, inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/NEWS CHANGED
@@ -1,3 +1,6 @@
1
+ 4.9.0 (October 23, 2017)
2
+ Deprecate factory_girl in favor of factory_bot
3
+
1
4
  4.8.1 (September 28, 2017)
2
5
  Explicitly define `#destroyed?` within the `Stub` strategy to return `nil` instead of raising
3
6
  Update various dependencies
data/README.md CHANGED
@@ -78,7 +78,7 @@ community](https://github.com/thoughtbot/factory_girl/graphs/contributors).
78
78
  License
79
79
  -------
80
80
 
81
- factory_girl is Copyright © 2008-2016 Joe Ferris and thoughtbot. It is free
81
+ factory_girl is Copyright © 2008-2017 Joe Ferris and thoughtbot. It is free
82
82
  software, and may be redistributed under the terms specified in the
83
83
  [LICENSE](/LICENSE) file.
84
84
 
@@ -0,0 +1,48 @@
1
+ # Upgrade from factory\_girl
2
+
3
+ Upgrading your codebase should involve only a few steps, and in most cases, it
4
+ involves updating the Gemfile, factories file(s), and support file configuring
5
+ the testing framework.
6
+
7
+ ## Modify your Gemfile
8
+
9
+ Replace references to factory\_girl\_rails or factory\_girl with
10
+ factory\_bot\_rails or factory\_bot. Both new gems are available starting at
11
+ version 4.8.2.
12
+
13
+ ```ruby
14
+ # Gemfile
15
+
16
+ # old
17
+ group :development, :test do
18
+ gem "factory_girl_rails"
19
+ # or
20
+ gem "factory_girl"
21
+ end
22
+
23
+ # new
24
+ group :development, :test do
25
+ gem "factory_bot_rails"
26
+ # or
27
+ gem "factory_bot"
28
+ end
29
+ ```
30
+
31
+ ## Replace All Constant References
32
+
33
+ A global find-and-replace of `FactoryGirl` to `FactoryBot` across the codebase
34
+ to replace all references with the new constant should do the trick. For
35
+ example, on OS X:
36
+
37
+ ```sh
38
+ grep -e FactoryGirl **/*.rake **/*.rb -l | xargs sed -i "" "s|FactoryGirl|FactoryBot|"
39
+ ```
40
+
41
+ ## Replace All Path References
42
+
43
+ If you're requiring files from factory\_girl or factory\_girl\_rails directly,
44
+ you'll have to update the paths.
45
+
46
+ ```sh
47
+ grep -e factory_girl **/*.rake **/*.rb -l | xargs sed -i "" "s|factory_girl|factory_bot|"
48
+ ```
@@ -18,7 +18,7 @@ GIT
18
18
  PATH
19
19
  remote: ../
20
20
  specs:
21
- factory_girl (4.8.1)
21
+ factory_girl (4.9.0)
22
22
  activesupport (>= 3.0.0)
23
23
 
24
24
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- factory_girl (4.8.1)
4
+ factory_girl (4.9.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- factory_girl (4.8.1)
4
+ factory_girl (4.9.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- factory_girl (4.8.1)
4
+ factory_girl (4.9.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- factory_girl (4.8.1)
4
+ factory_girl (4.9.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -59,12 +59,14 @@ module FactoryGirl
59
59
  # Parameters:
60
60
  # factories - which factories to lint; omit for all factories
61
61
  # options:
62
- # traits : true - to lint traits as well as factories
62
+ # traits: true - to lint traits as well as factories
63
+ # strategy: :create - to specify the strategy for linting
63
64
  def self.lint(*args)
64
65
  options = args.extract_options!
65
66
  factories_to_lint = args[0] || FactoryGirl.factories
66
- strategy = options[:traits] ? :factory_and_traits : :factory
67
- Linter.new(factories_to_lint, strategy).lint!
67
+ linting_strategy = options[:traits] ? :factory_and_traits : :factory
68
+ factory_strategy = options[:strategy] || :create
69
+ Linter.new(factories_to_lint, linting_strategy, factory_strategy).lint!
68
70
  end
69
71
 
70
72
  class << self
@@ -152,3 +154,5 @@ end
152
154
 
153
155
  FactoryGirl.register_default_strategies
154
156
  FactoryGirl.register_default_callbacks
157
+
158
+ ActiveSupport::Deprecation.warn "The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions."
@@ -4,7 +4,8 @@ module FactoryGirl
4
4
  class Evaluation
5
5
  include Observable
6
6
 
7
- def initialize(attribute_assigner, to_create)
7
+ def initialize(evaluator, attribute_assigner, to_create)
8
+ @evaluator = evaluator
8
9
  @attribute_assigner = attribute_assigner
9
10
  @to_create = to_create
10
11
  end
@@ -12,7 +13,10 @@ module FactoryGirl
12
13
  delegate :object, :hash, to: :@attribute_assigner
13
14
 
14
15
  def create(result_instance)
15
- @to_create[result_instance]
16
+ case @to_create.arity
17
+ when 2 then @to_create[result_instance, @evaluator]
18
+ else @to_create[result_instance]
19
+ end
16
20
  end
17
21
 
18
22
  def notify(name, result_instance)
@@ -36,7 +36,8 @@ module FactoryGirl
36
36
  evaluator = evaluator_class.new(strategy, overrides.symbolize_keys)
37
37
  attribute_assigner = AttributeAssigner.new(evaluator, build_class, &compiled_constructor)
38
38
 
39
- evaluation = Evaluation.new(attribute_assigner, compiled_to_create)
39
+ evaluation =
40
+ Evaluation.new(evaluator, attribute_assigner, compiled_to_create)
40
41
  evaluation.add_observer(CallbacksObserver.new(callbacks, evaluator))
41
42
 
42
43
  strategy.result(evaluation).tap(&block)
@@ -1,9 +1,10 @@
1
1
  module FactoryGirl
2
2
  class Linter
3
3
 
4
- def initialize(factories_to_lint, linting_strategy)
5
- @factories_to_lint = factories_to_lint
4
+ def initialize(factories, linting_strategy, factory_strategy = :create)
5
+ @factories_to_lint = factories
6
6
  @linting_method = "lint_#{linting_strategy}"
7
+ @factory_strategy = factory_strategy
7
8
  @invalid_factories = calculate_invalid_factories
8
9
  end
9
10
 
@@ -13,11 +14,10 @@ module FactoryGirl
13
14
  end
14
15
  end
15
16
 
16
- attr_reader :factories_to_lint, :invalid_factories
17
- private :factories_to_lint, :invalid_factories
18
-
19
17
  private
20
18
 
19
+ attr_reader :factories_to_lint, :invalid_factories, :factory_strategy
20
+
21
21
  def calculate_invalid_factories
22
22
  factories_to_lint.reduce(Hash.new([])) do |result, factory|
23
23
  errors = send(@linting_method, factory)
@@ -56,7 +56,7 @@ module FactoryGirl
56
56
  def lint_factory(factory)
57
57
  result = []
58
58
  begin
59
- FactoryGirl.create(factory.name)
59
+ FactoryGirl.public_send(factory_strategy, factory.name)
60
60
  rescue => error
61
61
  result |= [FactoryError.new(error, factory)]
62
62
  end
@@ -67,7 +67,7 @@ module FactoryGirl
67
67
  result = []
68
68
  factory.definition.defined_traits.map(&:name).each do |trait_name|
69
69
  begin
70
- FactoryGirl.create(factory.name, trait_name)
70
+ FactoryGirl.public_send(factory_strategy, factory.name, trait_name)
71
71
  rescue => error
72
72
  result |=
73
73
  [FactoryTraitError.new(error, factory, trait_name)]
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '4.8.1'.freeze
2
+ VERSION = '4.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.1
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Clayton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-09-28 00:00:00.000000000 Z
12
+ date: 2017-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -178,6 +178,7 @@ files:
178
178
  - NEWS
179
179
  - README.md
180
180
  - Rakefile
181
+ - UPGRADE_FROM_FACTORY_GIRL.md
181
182
  - cucumber.yml
182
183
  - factory_girl.gemspec
183
184
  - gemfiles/3.2.gemfile