factory_bot 5.0.2 → 5.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8a85e57f19a64402fd04363e3860ece58e6d1b5196cde075cf47973a15cda8a
4
- data.tar.gz: 4fb7243c9259094b83de12be38b27bd58d5cdaaec3d13796d07593c0f3846084
3
+ metadata.gz: 33780ea65377b4977bbc2ee3e16e126da53fbca4b820bd621537fa5b14bb8d85
4
+ data.tar.gz: f42bcc279ad3d3109ac513bcf73f07da96901fe00def25b8fbe4788ac96d1751
5
5
  SHA512:
6
- metadata.gz: 2e2fe25c47b767790269c438cf426c55dfc648e4f120eab1bc006fd5c38106deae1db27ae8107ae1aff5c310edf6f8f27116a4c36dd0e296b92feaf30cc8f291
7
- data.tar.gz: f7e369608d2a547c2a1fcf57b2f69645b8ea94ff6fb06c5fa71002a0024c2e3ca3e28738379324796f04648e969576ca42b49e181f8c7495b39444079acbaaea
6
+ metadata.gz: f51989b517d39a8254751e63b49b4705b8f104cb7a0ff52f073fd65243e7199ea39e8bad88c37edb1b3397fb362027be843bd196586f01a29d98b4d2accad112
7
+ data.tar.gz: 2768474e23632487e2f8cec649a48d1721858c6cb7c4baf9ca79f3b5688d29e9fb448e42cca5cb6e20c046f90b458829055dae4e3d6ec5fc4a7983880ad5d8f5
@@ -30,7 +30,7 @@ Configure your test suite
30
30
 
31
31
  ### RSpec
32
32
 
33
- If you're using Rails:
33
+ If you're using Rails, add the following configuration to `spec/support/factory_bot.rb` and be sure to require that file in `rails_helper.rb`:
34
34
 
35
35
  ```ruby
36
36
  RSpec.configure do |config|
@@ -387,7 +387,7 @@ post.new_record? # => true
387
387
  post.author.new_record? # => false
388
388
  ```
389
389
 
390
- To not save the associated object, specify strategy: :build in the factory:
390
+ To not save the associated object, specify `strategy: :build` in the factory:
391
391
 
392
392
  ```ruby
393
393
  FactoryBot.use_parent_strategy = false
@@ -510,20 +510,20 @@ create(:profile_with_languages, languages_count: 15).languages.length # 15
510
510
 
511
511
  Polymorphic associations can be handled with traits:
512
512
 
513
- ```
513
+ ```ruby
514
514
  FactoryBot.define do
515
515
  factory :video
516
516
  factory :photo
517
517
 
518
518
  factory :comment do
519
- for_photo
519
+ for_photo # default to the :for_photo trait if none is specified
520
520
 
521
521
  trait :for_video do
522
- association(:commentable, factory: :video)
522
+ association :commentable, factory: :video
523
523
  end
524
524
 
525
525
  trait :for_photo do
526
- association(:commentable, factory: :photo)
526
+ association :commentable, factory: :photo
527
527
  end
528
528
  end
529
529
  end
@@ -531,7 +531,7 @@ end
531
531
 
532
532
  This allows us to do:
533
533
 
534
- ```
534
+ ```ruby
535
535
  create(:comment)
536
536
  create(:comment, :for_video)
537
537
  create(:comment, :for_photo)
@@ -961,7 +961,7 @@ If a gem were to give you a User factory:
961
961
  ```ruby
962
962
  FactoryBot.define do
963
963
  factory :user do
964
- full_name "John Doe"
964
+ full_name { "John Doe" }
965
965
  sequence(:username) { |n| "user#{n}" }
966
966
  password { "password" }
967
967
  end
@@ -1066,10 +1066,11 @@ Example Rake task:
1066
1066
  namespace :factory_bot do
1067
1067
  desc "Verify that all FactoryBot factories are valid"
1068
1068
  task lint: :environment do
1069
- if Rails.env.test?
1070
- DatabaseCleaner.clean_with(:deletion)
1071
- DatabaseCleaner.cleaning do
1069
+ if Rails.env.test?
1070
+ conn = ActiveRecord::Base.connection
1071
+ conn.transaction do
1072
1072
  FactoryBot.lint
1073
+ raise ActiveRecord::Rollback
1073
1074
  end
1074
1075
  else
1075
1076
  system("bundle exec rake factory_bot:lint RAILS_ENV='test'")
@@ -1081,8 +1082,7 @@ end
1081
1082
 
1082
1083
  After calling `FactoryBot.lint`, you'll likely want to clear out the
1083
1084
  database, as records will most likely be created. The provided example above
1084
- uses the database_cleaner gem to clear out the database; be sure to add the
1085
- gem to your Gemfile under the appropriate groups.
1085
+ uses an sql transaction and rollback to leave the database clean.
1086
1086
 
1087
1087
  You can lint factories selectively by passing only factories you want linted:
1088
1088
 
data/NEWS.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # News
2
2
 
3
+ ## 5.1.0 (September 21, 2019)
4
+ * Added: "Did you mean?" style error message to help with typos in association declarations
5
+ * Changed: `NoMethodError` for static attributes now offers a "Did you mean?" style message
6
+ * Fixed: avoid undefining inherited evaluator methods
7
+ * Fixed: avoid stubbing id for records without a primary key
8
+ * Fixed: raise a helpful error for self-referencing traits to avoid a `SystemStackError`
9
+ * Deprecated: top-level methods meant only for internal use: `allow_class_lookup`, `allow_class_lookup`=, `register_trait`, `trait_by_name`, `traits`, `sequence_by_name`, `sequences`, `factory_by_name`, `register_factory`, `callback_names`, `register_callback`, `register_default_callbacks`, `register_default_strategies`, `strategies`
10
+
3
11
  ## 5.0.2 (February 22, 2019)
4
12
  * Bugfix: raise "Trait not registered" error when passing invalid trait arguments
5
13
 
data/README.md CHANGED
@@ -5,7 +5,7 @@ factory_bot is a fixtures replacement with a straightforward definition syntax,
5
5
  If you want to use factory_bot with Rails, see
6
6
  [factory_bot_rails](https://github.com/thoughtbot/factory_bot_rails).
7
7
 
8
- _[Interested in the history of the project name?](NAME.md)_
8
+ _[Interested in the history of the project name?][NAME]_
9
9
 
10
10
 
11
11
  ### Transitioning from factory\_girl?
@@ -59,9 +59,13 @@ More Information
59
59
  * [Issues](https://github.com/thoughtbot/factory_bot/issues)
60
60
  * [GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS](https://robots.thoughtbot.com/)
61
61
 
62
- You may also find useful information under the [factory_girl tag on Stack Overflow](https://stackoverflow.com/questions/tagged/factory-girl).
62
+ [GETTING_STARTED]: https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md
63
+ [NAME]: https://github.com/thoughtbot/factory_bot/blob/master/NAME.md
63
64
 
64
- [GETTING_STARTED]: https://www.rubydoc.info/gems/factory_bot/file/GETTING_STARTED.md
65
+ Useful Tools
66
+ ------------
67
+
68
+ * [FactoryTrace](https://github.com/djezzzl/factory_trace) - helps to find unused factories and traits.
65
69
 
66
70
  Contributing
67
71
  ------------
@@ -77,7 +81,10 @@ License
77
81
 
78
82
  factory_bot is Copyright © 2008-2019 Joe Ferris and thoughtbot. It is free
79
83
  software, and may be redistributed under the terms specified in the
80
- [LICENSE](/LICENSE) file.
84
+ [LICENSE] file.
85
+
86
+ [LICENSE]: https://github.com/thoughtbot/factory_bot/blob/master/LICENSE
87
+
81
88
 
82
89
  About thoughtbot
83
90
  ----------------
@@ -48,7 +48,7 @@ require "factory_bot/version"
48
48
  require "factory_bot/internal"
49
49
 
50
50
  module FactoryBot
51
- DEPRECATOR = ActiveSupport::Deprecation.new("6.0", "factory_bot")
51
+ Deprecation = ActiveSupport::Deprecation.new("6.0", "factory_bot")
52
52
 
53
53
  def self.configuration
54
54
  Internal.configuration
@@ -75,89 +75,51 @@ module FactoryBot
75
75
  end
76
76
 
77
77
  class << self
78
- delegate :factories,
78
+ delegate :callbacks,
79
+ :callback_names,
80
+ :constructor,
81
+ :factories,
82
+ :initialize_with,
79
83
  :sequences,
80
- :traits,
81
- :callbacks,
84
+ :skip_create,
82
85
  :strategies,
83
- :callback_names,
84
86
  :to_create,
85
- :skip_create,
86
- :initialize_with,
87
- :constructor,
87
+ :traits,
88
88
  to: :configuration
89
89
 
90
- attr_accessor :allow_class_lookup
91
- deprecate :allow_class_lookup, :allow_class_lookup=, deprecator: DEPRECATOR
92
- end
93
-
94
- def self.register_factory(factory)
95
- factory.names.each do |name|
96
- factories.register(name, factory)
97
- end
98
- factory
99
- end
100
-
101
- def self.factory_by_name(name)
102
- factories.find(name)
103
- end
104
-
105
- def self.register_sequence(sequence)
106
- sequence.names.each do |name|
107
- sequences.register(name, sequence)
108
- end
109
- sequence
110
- end
111
-
112
- def self.sequence_by_name(name)
113
- sequences.find(name)
114
- end
115
-
116
- def self.rewind_sequences
117
- sequences.each(&:rewind)
118
- Internal.rewind_inline_sequences
119
- end
120
-
121
- def self.register_trait(trait)
122
- trait.names.each do |name|
123
- traits.register(name, trait)
124
- end
125
- trait
126
- end
127
-
128
- def self.trait_by_name(name)
129
- traits.find(name)
130
- end
90
+ delegate :factory_by_name,
91
+ :register_callback,
92
+ :register_default_callbacks,
93
+ :register_default_strategies,
94
+ :register_factory,
95
+ :register_sequence,
96
+ :register_strategy,
97
+ :register_trait,
98
+ :rewind_sequences,
99
+ :sequence_by_name,
100
+ :strategy_by_name,
101
+ :trait_by_name,
102
+ to: Internal
131
103
 
132
- def self.register_strategy(strategy_name, strategy_class)
133
- strategies.register(strategy_name, strategy_class)
134
- StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
135
- end
136
-
137
- def self.strategy_by_name(name)
138
- strategies.find(name)
139
- end
140
-
141
- def self.register_default_strategies
142
- register_strategy(:build, FactoryBot::Strategy::Build)
143
- register_strategy(:create, FactoryBot::Strategy::Create)
144
- register_strategy(:attributes_for, FactoryBot::Strategy::AttributesFor)
145
- register_strategy(:build_stubbed, FactoryBot::Strategy::Stub)
146
- register_strategy(:null, FactoryBot::Strategy::Null)
147
- end
148
-
149
- def self.register_default_callbacks
150
- register_callback(:after_build)
151
- register_callback(:after_create)
152
- register_callback(:after_stub)
153
- register_callback(:before_create)
154
- end
104
+ attr_accessor :allow_class_lookup
155
105
 
156
- def self.register_callback(name)
157
- name = name.to_sym
158
- callback_names << name
106
+ deprecate :allow_class_lookup,
107
+ :allow_class_lookup=,
108
+ :callback_names,
109
+ :factory_by_name,
110
+ :register_callback,
111
+ :register_default_callbacks,
112
+ :register_default_strategies,
113
+ :register_factory,
114
+ :register_trait,
115
+ :sequence_by_name,
116
+ :sequences,
117
+ :strategies,
118
+ :trait_by_name,
119
+ :traits,
120
+ deprecator: Deprecation
159
121
  end
160
122
  end
161
123
 
162
- FactoryBot.register_default_strategies
163
- FactoryBot.register_default_callbacks
124
+ FactoryBot::Internal.register_default_strategies
125
+ FactoryBot::Internal.register_default_callbacks
@@ -2,7 +2,7 @@ module FactoryBot
2
2
  # @api private
3
3
  class AttributeAssigner
4
4
  def initialize(evaluator, build_class, &instance_builder)
5
- @build_class = build_class
5
+ @build_class = build_class
6
6
  @instance_builder = instance_builder
7
7
  @evaluator = evaluator
8
8
  @attribute_list = evaluator.class.attribute_list
@@ -28,9 +28,9 @@ module FactoryBot
28
28
  private
29
29
 
30
30
  def ensure_valid_callback_name!
31
- unless FactoryBot.callback_names.include?(name)
31
+ unless FactoryBot::Internal.callback_names.include?(name)
32
32
  raise InvalidCallbackNameError, "#{name} is not a valid callback name. " +
33
- "Valid callback names are #{FactoryBot.callback_names.inspect}"
33
+ "Valid callback names are #{FactoryBot::Internal.callback_names.inspect}"
34
34
  end
35
35
  end
36
36
 
@@ -22,9 +22,20 @@ module FactoryBot
22
22
  private
23
23
 
24
24
  def build
25
+ ensure_factory_is_not_a_declaration!
26
+
25
27
  factory_name = @overrides[:factory] || name
26
28
  [Attribute::Association.new(name, factory_name, [@traits, @overrides.except(:factory)].flatten)]
27
29
  end
30
+
31
+ def ensure_factory_is_not_a_declaration!
32
+ if @overrides[:factory].is_a?(Declaration)
33
+ raise ArgumentError.new(<<~MSG)
34
+ Association '#{name}' received an invalid factory argument.
35
+ Did you mean? 'factory: :#{@overrides[:factory].name}'
36
+ MSG
37
+ end
38
+ end
28
39
  end
29
40
  end
30
41
  end
@@ -23,8 +23,11 @@ module FactoryBot
23
23
  def build
24
24
  if FactoryBot.factories.registered?(name)
25
25
  [Attribute::Association.new(name, name, {})]
26
- elsif FactoryBot.sequences.registered?(name)
26
+ elsif FactoryBot::Internal.sequences.registered?(name)
27
27
  [Attribute::Sequence.new(name, name, @ignored)]
28
+ elsif @factory.name.to_s == name.to_s
29
+ message = "Self-referencing trait '#{@name}'"
30
+ raise TraitDefinitionError, message
28
31
  else
29
32
  @factory.inherit_traits([name])
30
33
  []
@@ -95,7 +95,7 @@ module FactoryBot
95
95
 
96
96
  def callback(*names, &block)
97
97
  names.each do |name|
98
- FactoryBot.register_callback(name)
98
+ FactoryBot::Internal.register_callback(name)
99
99
  add_callback(Callback.new(name, block))
100
100
  end
101
101
  end
@@ -111,7 +111,7 @@ module FactoryBot
111
111
  end
112
112
 
113
113
  def trait_by_name(name)
114
- trait_for(name) || FactoryBot.trait_by_name(name)
114
+ trait_for(name) || Internal.trait_by_name(name)
115
115
  end
116
116
 
117
117
  def trait_for(name)
@@ -89,14 +89,17 @@ module FactoryBot
89
89
  #
90
90
  # are equivalent.
91
91
  def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissing
92
- if args.empty?
92
+ association_options = args.first
93
+
94
+ if association_options.nil?
93
95
  __declare_attribute__(name, block)
94
- elsif args.first.respond_to?(:has_key?) && args.first.has_key?(:factory)
95
- association(name, *args)
96
+ elsif __valid_association_options?(association_options)
97
+ association(name, association_options)
96
98
  else
97
- raise NoMethodError.new(
98
- "undefined method '#{name}' in '#{@definition.name}' factory",
99
- )
99
+ raise NoMethodError.new(<<~MSG)
100
+ undefined method '#{name}' in '#{@definition.name}' factory
101
+ Did you mean? '#{name} { #{association_options.inspect} }'
102
+ MSG
100
103
  end
101
104
  end
102
105
 
@@ -187,5 +190,9 @@ module FactoryBot
187
190
  add_attribute(name, &block)
188
191
  end
189
192
  end
193
+
194
+ def __valid_association_options?(options)
195
+ options.respond_to?(:has_key?) && options.has_key?(:factory)
196
+ end
190
197
  end
191
198
  end
@@ -2,6 +2,9 @@ module FactoryBot
2
2
  # Raised when a factory is defined that attempts to instantiate itself.
3
3
  class AssociationDefinitionError < RuntimeError; end
4
4
 
5
+ # Raised when a trait is defined that references itself.
6
+ class TraitDefinitionError < RuntimeError; end
7
+
5
8
  # Raised when a callback is defined that has an invalid name
6
9
  class InvalidCallbackNameError < RuntimeError; end
7
10
 
@@ -66,7 +66,7 @@ module FactoryBot
66
66
  end
67
67
 
68
68
  def self.define_attribute(name, &block)
69
- if method_defined?(name) || private_method_defined?(name)
69
+ if instance_methods(false).include?(name) || private_instance_methods(false).include?(name)
70
70
  undef_method(name)
71
71
  end
72
72
 
@@ -145,7 +145,7 @@ module FactoryBot
145
145
 
146
146
  def parent
147
147
  if @parent
148
- FactoryBot.factory_by_name(@parent)
148
+ FactoryBot::Internal.factory_by_name(@parent)
149
149
  else
150
150
  NullFactory.new
151
151
  end
@@ -9,7 +9,7 @@ module FactoryBot
9
9
  end
10
10
 
11
11
  def run(runner_strategy = @strategy, &block)
12
- factory = FactoryBot.factory_by_name(@name)
12
+ factory = FactoryBot::Internal.factory_by_name(@name)
13
13
 
14
14
  factory.compile
15
15
 
@@ -1,8 +1,26 @@
1
1
  module FactoryBot
2
2
  # @api private
3
3
  module Internal
4
+ DEFAULT_STRATEGIES = {
5
+ build: FactoryBot::Strategy::Build,
6
+ create: FactoryBot::Strategy::Create,
7
+ attributes_for: FactoryBot::Strategy::AttributesFor,
8
+ build_stubbed: FactoryBot::Strategy::Stub,
9
+ null: FactoryBot::Strategy::Null,
10
+ }.freeze
11
+
12
+ DEFAULT_CALLBACKS = [
13
+ :after_create, :after_build, :after_stub, :after_create
14
+ ].freeze
15
+
4
16
  class << self
5
- delegate :inline_sequences, to: :configuration
17
+ delegate :callback_names,
18
+ :factories,
19
+ :inline_sequences,
20
+ :sequences,
21
+ :strategies,
22
+ :traits,
23
+ to: :configuration
6
24
 
7
25
  def configuration
8
26
  @configuration ||= Configuration.new
@@ -19,6 +37,66 @@ module FactoryBot
19
37
  def rewind_inline_sequences
20
38
  inline_sequences.each(&:rewind)
21
39
  end
40
+
41
+ def register_trait(trait)
42
+ trait.names.each do |name|
43
+ traits.register(name, trait)
44
+ end
45
+ trait
46
+ end
47
+
48
+ def trait_by_name(name)
49
+ traits.find(name)
50
+ end
51
+
52
+ def register_sequence(sequence)
53
+ sequence.names.each do |name|
54
+ sequences.register(name, sequence)
55
+ end
56
+ sequence
57
+ end
58
+
59
+ def sequence_by_name(name)
60
+ sequences.find(name)
61
+ end
62
+
63
+ def rewind_sequences
64
+ sequences.each(&:rewind)
65
+ rewind_inline_sequences
66
+ end
67
+
68
+ def register_factory(factory)
69
+ factory.names.each do |name|
70
+ factories.register(name, factory)
71
+ end
72
+ factory
73
+ end
74
+
75
+ def factory_by_name(name)
76
+ factories.find(name)
77
+ end
78
+
79
+ def register_strategy(strategy_name, strategy_class)
80
+ strategies.register(strategy_name, strategy_class)
81
+ StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
82
+ end
83
+
84
+ def strategy_by_name(name)
85
+ strategies.find(name)
86
+ end
87
+
88
+ def register_default_strategies
89
+ DEFAULT_STRATEGIES.each(&method(:register_strategy))
90
+ end
91
+
92
+ def register_default_callbacks
93
+ DEFAULT_CALLBACKS.each(&method(:register_callback))
94
+ end
95
+
96
+ def register_callback(name)
97
+ name = name.to_sym
98
+ callback_names << name
99
+ end
22
100
  end
23
101
  end
24
102
  end
@@ -1,8 +1,8 @@
1
1
  module FactoryBot
2
2
  def self.reload
3
3
  Internal.reset_configuration
4
- register_default_strategies
5
- register_default_callbacks
4
+ Internal.register_default_strategies
5
+ Internal.register_default_callbacks
6
6
  find_definitions
7
7
  end
8
8
  end
@@ -44,15 +44,17 @@ module FactoryBot
44
44
  end
45
45
 
46
46
  def stub_database_interaction_on_result(result_instance)
47
- result_instance.id ||= next_id
47
+ if has_settable_id?(result_instance)
48
+ result_instance.id ||= next_id
49
+ end
48
50
 
49
51
  result_instance.instance_eval do
50
52
  def persisted?
51
- !new_record?
53
+ true
52
54
  end
53
55
 
54
56
  def new_record?
55
- id.nil?
57
+ false
56
58
  end
57
59
 
58
60
  def destroyed?
@@ -68,6 +70,11 @@ module FactoryBot
68
70
  end
69
71
  end
70
72
 
73
+ def has_settable_id?(result_instance)
74
+ !result_instance.class.respond_to?(:primary_key) ||
75
+ result_instance.class.primary_key
76
+ end
77
+
71
78
  def clear_changes_information(result_instance)
72
79
  if result_instance.respond_to?(:clear_changes_information)
73
80
  result_instance.clear_changes_information
@@ -20,7 +20,7 @@ module FactoryBot
20
20
  end
21
21
 
22
22
  def strategy_name_to_object
23
- FactoryBot.strategy_by_name(@name_or_object)
23
+ FactoryBot::Internal.strategy_by_name(@name_or_object)
24
24
  end
25
25
  end
26
26
  end
@@ -17,7 +17,7 @@ module FactoryBot
17
17
  proxy = FactoryBot::DefinitionProxy.new(factory.definition)
18
18
  proxy.instance_eval(&block) if block_given?
19
19
 
20
- FactoryBot.register_factory(factory)
20
+ Internal.register_factory(factory)
21
21
 
22
22
  proxy.child_factories.each do |(child_name, child_options, child_block)|
23
23
  parent_factory = child_options.delete(:parent) || name
@@ -26,11 +26,11 @@ module FactoryBot
26
26
  end
27
27
 
28
28
  def sequence(name, *args, &block)
29
- FactoryBot.register_sequence(Sequence.new(name, *args, &block))
29
+ Internal.register_sequence(Sequence.new(name, *args, &block))
30
30
  end
31
31
 
32
32
  def trait(name, &block)
33
- FactoryBot.register_trait(Trait.new(name, &block))
33
+ Internal.register_trait(Trait.new(name, &block))
34
34
  end
35
35
 
36
36
  def to_create(&block)
@@ -54,13 +54,13 @@ module FactoryBot
54
54
  private
55
55
 
56
56
  def configuration
57
- FactoryBot::Internal.configuration
57
+ Internal.configuration
58
58
  end
59
59
  end
60
60
 
61
61
  class ModifyDSL
62
62
  def factory(name, _options = {}, &block)
63
- factory = FactoryBot.factory_by_name(name)
63
+ factory = Internal.factory_by_name(name)
64
64
  proxy = FactoryBot::DefinitionProxy.new(factory.definition.overridable)
65
65
  proxy.instance_eval(&block)
66
66
  end
@@ -30,7 +30,7 @@ module FactoryBot
30
30
  ## # factory with traits and attribute override
31
31
  ## build_stubbed_list(:user, 15, :admin, :male, name: "John Doe")
32
32
  module Methods
33
- # @!parse FactoryBot.register_default_strategies
33
+ # @!parse FactoryBot::Internal.register_default_strategies
34
34
  # @!method build(name, *traits_and_overrides, &block)
35
35
  # (see #strategy_method)
36
36
  # Builds a registered factory by name.
@@ -111,7 +111,7 @@ module FactoryBot
111
111
  # Returns:
112
112
  # The next value in the sequence. (Object)
113
113
  def generate(name)
114
- FactoryBot.sequence_by_name(name).next
114
+ Internal.sequence_by_name(name).next
115
115
  end
116
116
 
117
117
  # Generates and returns the list of values in a sequence.
@@ -126,7 +126,7 @@ module FactoryBot
126
126
  # The next value in the sequence. (Object)
127
127
  def generate_list(name, count)
128
128
  (1..count).map do
129
- FactoryBot.sequence_by_name(name).next
129
+ Internal.sequence_by_name(name).next
130
130
  end
131
131
  end
132
132
  end
@@ -7,9 +7,11 @@ module FactoryBot
7
7
  @name = name.to_s
8
8
  @block = block
9
9
  @definition = Definition.new(@name)
10
-
11
10
  proxy = FactoryBot::DefinitionProxy.new(@definition)
12
- proxy.instance_eval(&@block) if block_given?
11
+
12
+ if block_given?
13
+ proxy.instance_eval(&@block)
14
+ end
13
15
  end
14
16
 
15
17
  delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
@@ -1,3 +1,3 @@
1
1
  module FactoryBot
2
- VERSION = "5.0.2".freeze
2
+ VERSION = "5.1.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.2
4
+ version: 5.1.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: 2019-02-22 00:00:00.000000000 Z
12
+ date: 2019-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -165,20 +165,6 @@ dependencies:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
- - !ruby/object:Gem::Dependency
169
- name: timecop
170
- requirement: !ruby/object:Gem::Requirement
171
- requirements:
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- version: '0'
175
- type: :development
176
- prerelease: false
177
- version_requirements: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- version: '0'
182
168
  - !ruby/object:Gem::Dependency
183
169
  name: yard
184
170
  requirement: !ruby/object:Gem::Requirement
@@ -279,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
265
  - !ruby/object:Gem::Version
280
266
  version: '0'
281
267
  requirements: []
282
- rubygems_version: 3.0.1
268
+ rubygems_version: 3.0.3
283
269
  signing_key:
284
270
  specification_version: 4
285
271
  summary: factory_bot provides a framework and DSL for defining and using model instance