factory_bot 4.11.1 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/GETTING_STARTED.md +121 -37
- data/LICENSE +1 -1
- data/NEWS.md +351 -0
- data/README.md +18 -22
- data/lib/factory_bot/aliases.rb +1 -1
- data/lib/factory_bot/attribute/dynamic.rb +1 -0
- data/lib/factory_bot/attribute.rb +4 -39
- data/lib/factory_bot/attribute_assigner.rb +21 -6
- data/lib/factory_bot/attribute_list.rb +2 -1
- data/lib/factory_bot/callback.rb +3 -2
- data/lib/factory_bot/configuration.rb +16 -20
- data/lib/factory_bot/declaration/association.rb +14 -1
- data/lib/factory_bot/declaration/dynamic.rb +3 -1
- data/lib/factory_bot/declaration/implicit.rb +7 -2
- data/lib/factory_bot/declaration.rb +4 -4
- data/lib/factory_bot/declaration_list.rb +1 -1
- data/lib/factory_bot/decorator/attribute_hash.rb +1 -1
- data/lib/factory_bot/decorator/invocation_tracker.rb +1 -1
- data/lib/factory_bot/decorator.rb +5 -1
- data/lib/factory_bot/definition.rb +10 -7
- data/lib/factory_bot/definition_hierarchy.rb +1 -11
- data/lib/factory_bot/definition_proxy.rb +59 -62
- data/lib/factory_bot/errors.rb +7 -4
- data/lib/factory_bot/evaluation.rb +1 -1
- data/lib/factory_bot/evaluator.rb +5 -5
- data/lib/factory_bot/factory.rb +8 -8
- data/lib/factory_bot/factory_runner.rb +3 -3
- data/lib/factory_bot/find_definitions.rb +1 -1
- data/lib/factory_bot/internal.rb +104 -0
- data/lib/factory_bot/linter.rb +36 -19
- data/lib/factory_bot/null_factory.rb +4 -1
- data/lib/factory_bot/null_object.rb +2 -2
- data/lib/factory_bot/registry.rb +15 -6
- data/lib/factory_bot/reload.rb +3 -3
- data/lib/factory_bot/sequence.rb +0 -1
- data/lib/factory_bot/strategy/null.rb +2 -4
- data/lib/factory_bot/strategy/stub.rb +32 -31
- data/lib/factory_bot/strategy_calculator.rb +1 -1
- data/lib/factory_bot/strategy_syntax_method_registrar.rb +13 -2
- data/lib/factory_bot/syntax/default.rb +12 -24
- data/lib/factory_bot/syntax/methods.rb +32 -9
- data/lib/factory_bot/syntax.rb +2 -2
- data/lib/factory_bot/trait.rb +6 -3
- data/lib/factory_bot/version.rb +1 -1
- data/lib/factory_bot.rb +103 -138
- metadata +72 -32
- data/NEWS +0 -306
- data/lib/factory_bot/attribute/static.rb +0 -16
- data/lib/factory_bot/declaration/static.rb +0 -26
- data/lib/factory_bot/decorator/class_key_hash.rb +0 -28
@@ -31,7 +31,8 @@ module FactoryBot
|
|
31
31
|
def result(evaluation)
|
32
32
|
evaluation.object.tap do |instance|
|
33
33
|
stub_database_interaction_on_result(instance)
|
34
|
-
|
34
|
+
set_timestamps(instance)
|
35
|
+
clear_changes_information(instance)
|
35
36
|
evaluation.notify(:after_stub, instance)
|
36
37
|
end
|
37
38
|
end
|
@@ -43,15 +44,17 @@ module FactoryBot
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def stub_database_interaction_on_result(result_instance)
|
46
|
-
result_instance
|
47
|
+
if has_settable_id?(result_instance)
|
48
|
+
result_instance.id ||= next_id
|
49
|
+
end
|
47
50
|
|
48
51
|
result_instance.instance_eval do
|
49
52
|
def persisted?
|
50
|
-
|
53
|
+
true
|
51
54
|
end
|
52
55
|
|
53
56
|
def new_record?
|
54
|
-
|
57
|
+
false
|
55
58
|
end
|
56
59
|
|
57
60
|
def destroyed?
|
@@ -60,46 +63,44 @@ module FactoryBot
|
|
60
63
|
|
61
64
|
DISABLED_PERSISTENCE_METHODS.each do |write_method|
|
62
65
|
define_singleton_method(write_method) do |*args|
|
63
|
-
raise "stubbed models are not allowed to access the database -
|
66
|
+
raise "stubbed models are not allowed to access the database - "\
|
67
|
+
"#{self.class}##{write_method}(#{args.join(',')})"
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
71
|
+
end
|
67
72
|
|
68
|
-
|
73
|
+
def has_settable_id?(result_instance)
|
74
|
+
!result_instance.class.respond_to?(:primary_key) ||
|
75
|
+
result_instance.class.primary_key
|
76
|
+
end
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@created_at ||= Time.now.in_time_zone
|
74
|
-
end
|
75
|
-
end
|
78
|
+
def clear_changes_information(result_instance)
|
79
|
+
if result_instance.respond_to?(:clear_changes_information)
|
80
|
+
result_instance.clear_changes_information
|
76
81
|
end
|
82
|
+
end
|
77
83
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if updated_at_no_default
|
82
|
-
result_instance.instance_eval do
|
83
|
-
def updated_at
|
84
|
-
@updated_at ||= Time.current
|
85
|
-
end
|
86
|
-
end
|
84
|
+
def set_timestamps(result_instance)
|
85
|
+
if missing_created_at?(result_instance)
|
86
|
+
result_instance.created_at = Time.current
|
87
87
|
end
|
88
|
-
end
|
89
88
|
|
90
|
-
|
91
|
-
|
92
|
-
result_instance.extend ActiveModelDirtyBackport
|
89
|
+
if missing_updated_at?(result_instance)
|
90
|
+
result_instance.updated_at = Time.current
|
93
91
|
end
|
92
|
+
end
|
94
93
|
|
95
|
-
|
94
|
+
def missing_created_at?(result_instance)
|
95
|
+
result_instance.respond_to?(:created_at) &&
|
96
|
+
result_instance.respond_to?(:created_at=) &&
|
97
|
+
result_instance.created_at.blank?
|
96
98
|
end
|
97
|
-
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
def missing_updated_at?(result_instance)
|
101
|
+
result_instance.respond_to?(:updated_at) &&
|
102
|
+
result_instance.respond_to?(:updated_at=) &&
|
103
|
+
result_instance.updated_at.blank?
|
103
104
|
end
|
104
105
|
end
|
105
106
|
end
|
@@ -11,6 +11,14 @@ module FactoryBot
|
|
11
11
|
define_pair_strategy_method
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.with_index(block, index)
|
15
|
+
if block&.arity == 2
|
16
|
+
->(instance) { block.call(instance, index) }
|
17
|
+
else
|
18
|
+
block
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
private
|
15
23
|
|
16
24
|
def define_singular_strategy_method
|
@@ -29,7 +37,10 @@ module FactoryBot
|
|
29
37
|
raise ArgumentError, "count missing for #{strategy_name}_list"
|
30
38
|
end
|
31
39
|
|
32
|
-
|
40
|
+
Array.new(amount) do |i|
|
41
|
+
block_with_index = StrategySyntaxMethodRegistrar.with_index(block, i)
|
42
|
+
send(strategy_name, name, *traits_and_overrides, &block_with_index)
|
43
|
+
end
|
33
44
|
end
|
34
45
|
end
|
35
46
|
|
@@ -37,7 +48,7 @@ module FactoryBot
|
|
37
48
|
strategy_name = @strategy_name
|
38
49
|
|
39
50
|
define_syntax_method("#{strategy_name}_pair") do |name, *traits_and_overrides, &block|
|
40
|
-
2
|
51
|
+
Array.new(2) { send(strategy_name, name, *traits_and_overrides, &block) }
|
41
52
|
end
|
42
53
|
end
|
43
54
|
|
@@ -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
|
-
|
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,41 +26,29 @@ module FactoryBot
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def sequence(name, *args, &block)
|
29
|
-
|
29
|
+
Internal.register_sequence(Sequence.new(name, *args, &block))
|
30
30
|
end
|
31
31
|
|
32
32
|
def trait(name, &block)
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def to_create(&block)
|
37
|
-
FactoryBot.to_create(&block)
|
38
|
-
end
|
39
|
-
|
40
|
-
def skip_create
|
41
|
-
FactoryBot.skip_create
|
42
|
-
end
|
43
|
-
|
44
|
-
def initialize_with(&block)
|
45
|
-
FactoryBot.initialize_with(&block)
|
33
|
+
Internal.register_trait(Trait.new(name, &block))
|
46
34
|
end
|
47
35
|
|
48
36
|
def self.run(block)
|
49
37
|
new.instance_eval(&block)
|
50
38
|
end
|
51
39
|
|
52
|
-
delegate :
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
40
|
+
delegate :after,
|
41
|
+
:before,
|
42
|
+
:callback,
|
43
|
+
:initialize_with,
|
44
|
+
:skip_create,
|
45
|
+
:to_create,
|
46
|
+
to: FactoryBot::Internal
|
59
47
|
end
|
60
48
|
|
61
49
|
class ModifyDSL
|
62
|
-
def factory(name,
|
63
|
-
factory =
|
50
|
+
def factory(name, _options = {}, &block)
|
51
|
+
factory = Internal.factory_by_name(name)
|
64
52
|
proxy = FactoryBot::DefinitionProxy.new(factory.definition.overridable)
|
65
53
|
proxy.instance_eval(&block)
|
66
54
|
end
|
@@ -2,8 +2,8 @@ module FactoryBot
|
|
2
2
|
module Syntax
|
3
3
|
## This module is a container for all strategy methods provided by
|
4
4
|
## FactoryBot. This includes all the default strategies provided ({Methods#build},
|
5
|
-
## {Methods#create}, {Methods#build_stubbed}, and {Methods#attributes_for}), as
|
6
|
-
## the complementary *_list methods.
|
5
|
+
## {Methods#create}, {Methods#build_stubbed}, and {Methods#attributes_for}), as
|
6
|
+
## well as the complementary *_list and *_pair methods.
|
7
7
|
## @example singular factory execution
|
8
8
|
## # basic use case
|
9
9
|
## build(:completed_order)
|
@@ -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.
|
@@ -51,22 +51,38 @@ module FactoryBot
|
|
51
51
|
# Generates a hash of attributes for a registered factory by name.
|
52
52
|
# @return [Hash] hash of attributes for the factory
|
53
53
|
|
54
|
-
# @!method build_list(name, amount, *traits_and_overrides)
|
54
|
+
# @!method build_list(name, amount, *traits_and_overrides, &block)
|
55
55
|
# (see #strategy_method_list)
|
56
56
|
# @return [Array] array of built objects defined by the factory
|
57
57
|
|
58
|
-
# @!method create_list(name, amount, *traits_and_overrides)
|
58
|
+
# @!method create_list(name, amount, *traits_and_overrides, &block)
|
59
59
|
# (see #strategy_method_list)
|
60
60
|
# @return [Array] array of created objects defined by the factory
|
61
61
|
|
62
|
-
# @!method build_stubbed_list(name, amount, *traits_and_overrides)
|
62
|
+
# @!method build_stubbed_list(name, amount, *traits_and_overrides, &block)
|
63
63
|
# (see #strategy_method_list)
|
64
64
|
# @return [Array] array of stubbed objects defined by the factory
|
65
65
|
|
66
|
-
# @!method attributes_for_list(name, amount, *traits_and_overrides)
|
66
|
+
# @!method attributes_for_list(name, amount, *traits_and_overrides, &block)
|
67
67
|
# (see #strategy_method_list)
|
68
68
|
# @return [Array<Hash>] array of attribute hashes for the factory
|
69
69
|
|
70
|
+
# @!method build_pair(name, *traits_and_overrides, &block)
|
71
|
+
# (see #strategy_method_pair)
|
72
|
+
# @return [Array] pair of built objects defined by the factory
|
73
|
+
|
74
|
+
# @!method create_pair(name, *traits_and_overrides, &block)
|
75
|
+
# (see #strategy_method_pair)
|
76
|
+
# @return [Array] pair of created objects defined by the factory
|
77
|
+
|
78
|
+
# @!method build_stubbed_pair(name, *traits_and_overrides, &block)
|
79
|
+
# (see #strategy_method_pair)
|
80
|
+
# @return [Array] pair of stubbed objects defined by the factory
|
81
|
+
|
82
|
+
# @!method attributes_for_pair(name, *traits_and_overrides, &block)
|
83
|
+
# (see #strategy_method_pair)
|
84
|
+
# @return [Array<Hash>] pair of attribute hashes for the factory
|
85
|
+
|
70
86
|
# @!method strategy_method
|
71
87
|
# @!visibility private
|
72
88
|
# @param [Symbol] name the name of the factory to build
|
@@ -78,6 +94,13 @@ module FactoryBot
|
|
78
94
|
# @param [Symbol] name the name of the factory to execute
|
79
95
|
# @param [Integer] amount the number of instances to execute
|
80
96
|
# @param [Array<Symbol, Symbol, Hash>] traits_and_overrides splat args traits and a hash of overrides
|
97
|
+
# @param [Proc] block block to be executed
|
98
|
+
|
99
|
+
# @!method strategy_method_pair
|
100
|
+
# @!visibility private
|
101
|
+
# @param [Symbol] name the name of the factory to execute
|
102
|
+
# @param [Array<Symbol, Symbol, Hash>] traits_and_overrides splat args traits and a hash of overrides
|
103
|
+
# @param [Proc] block block to be executed
|
81
104
|
|
82
105
|
# Generates and returns the next value in a sequence.
|
83
106
|
#
|
@@ -88,7 +111,7 @@ module FactoryBot
|
|
88
111
|
# Returns:
|
89
112
|
# The next value in the sequence. (Object)
|
90
113
|
def generate(name)
|
91
|
-
|
114
|
+
Internal.sequence_by_name(name).next
|
92
115
|
end
|
93
116
|
|
94
117
|
# Generates and returns the list of values in a sequence.
|
@@ -103,7 +126,7 @@ module FactoryBot
|
|
103
126
|
# The next value in the sequence. (Object)
|
104
127
|
def generate_list(name, count)
|
105
128
|
(1..count).map do
|
106
|
-
|
129
|
+
Internal.sequence_by_name(name).next
|
107
130
|
end
|
108
131
|
end
|
109
132
|
end
|
data/lib/factory_bot/syntax.rb
CHANGED
data/lib/factory_bot/trait.rb
CHANGED
@@ -4,12 +4,14 @@ module FactoryBot
|
|
4
4
|
attr_reader :name, :definition
|
5
5
|
|
6
6
|
def initialize(name, &block)
|
7
|
-
@name = name
|
7
|
+
@name = name.to_s
|
8
8
|
@block = block
|
9
9
|
@definition = Definition.new(@name)
|
10
|
-
|
11
10
|
proxy = FactoryBot::DefinitionProxy.new(@definition)
|
12
|
-
|
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,
|
@@ -25,6 +27,7 @@ module FactoryBot
|
|
25
27
|
end
|
26
28
|
|
27
29
|
protected
|
30
|
+
|
28
31
|
attr_reader :block
|
29
32
|
end
|
30
33
|
end
|
data/lib/factory_bot/version.rb
CHANGED
data/lib/factory_bot.rb
CHANGED
@@ -1,59 +1,57 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
1
|
+
require "set"
|
2
|
+
require "active_support/core_ext/module/delegation"
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "active_support/deprecation"
|
5
|
+
require "active_support/notifications"
|
6
|
+
|
7
|
+
require "factory_bot/internal"
|
8
|
+
require "factory_bot/definition_hierarchy"
|
9
|
+
require "factory_bot/configuration"
|
10
|
+
require "factory_bot/errors"
|
11
|
+
require "factory_bot/factory_runner"
|
12
|
+
require "factory_bot/strategy_syntax_method_registrar"
|
13
|
+
require "factory_bot/strategy_calculator"
|
14
|
+
require "factory_bot/strategy/build"
|
15
|
+
require "factory_bot/strategy/create"
|
16
|
+
require "factory_bot/strategy/attributes_for"
|
17
|
+
require "factory_bot/strategy/stub"
|
18
|
+
require "factory_bot/strategy/null"
|
19
|
+
require "factory_bot/registry"
|
20
|
+
require "factory_bot/null_factory"
|
21
|
+
require "factory_bot/null_object"
|
22
|
+
require "factory_bot/evaluation"
|
23
|
+
require "factory_bot/factory"
|
24
|
+
require "factory_bot/attribute_assigner"
|
25
|
+
require "factory_bot/evaluator"
|
26
|
+
require "factory_bot/evaluator_class_definer"
|
27
|
+
require "factory_bot/attribute"
|
28
|
+
require "factory_bot/callback"
|
29
|
+
require "factory_bot/callbacks_observer"
|
30
|
+
require "factory_bot/declaration_list"
|
31
|
+
require "factory_bot/declaration"
|
32
|
+
require "factory_bot/sequence"
|
33
|
+
require "factory_bot/attribute_list"
|
34
|
+
require "factory_bot/trait"
|
35
|
+
require "factory_bot/aliases"
|
36
|
+
require "factory_bot/definition"
|
37
|
+
require "factory_bot/definition_proxy"
|
38
|
+
require "factory_bot/syntax"
|
39
|
+
require "factory_bot/syntax_runner"
|
40
|
+
require "factory_bot/find_definitions"
|
41
|
+
require "factory_bot/reload"
|
42
|
+
require "factory_bot/decorator"
|
43
|
+
require "factory_bot/decorator/attribute_hash"
|
44
|
+
require "factory_bot/decorator/disallows_duplicates_registry"
|
45
|
+
require "factory_bot/decorator/invocation_tracker"
|
46
|
+
require "factory_bot/decorator/new_constructor"
|
47
|
+
require "factory_bot/linter"
|
48
|
+
require "factory_bot/version"
|
48
49
|
|
49
50
|
module FactoryBot
|
50
|
-
|
51
|
-
@configuration ||= Configuration.new
|
52
|
-
end
|
51
|
+
Deprecation = ActiveSupport::Deprecation.new("6.0", "factory_bot")
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
53
|
+
mattr_accessor :use_parent_strategy, instance_accessor: false
|
54
|
+
self.use_parent_strategy = true
|
57
55
|
|
58
56
|
# Look for errors in factories and (optionally) their traits.
|
59
57
|
# Parameters:
|
@@ -61,100 +59,67 @@ module FactoryBot
|
|
61
59
|
# options:
|
62
60
|
# traits: true - to lint traits as well as factories
|
63
61
|
# strategy: :create - to specify the strategy for linting
|
62
|
+
# verbose: true - to include full backtraces for each linting error
|
64
63
|
def self.lint(*args)
|
65
64
|
options = args.extract_options!
|
66
65
|
factories_to_lint = args[0] || FactoryBot.factories
|
67
|
-
|
68
|
-
factory_strategy = options[:strategy] || :create
|
69
|
-
Linter.new(factories_to_lint, linting_strategy, factory_strategy).lint!
|
66
|
+
Linter.new(factories_to_lint, **options).lint!
|
70
67
|
end
|
71
68
|
|
72
69
|
class << self
|
73
|
-
delegate :
|
74
|
-
:sequences,
|
75
|
-
:traits,
|
70
|
+
delegate :callback_names,
|
76
71
|
:callbacks,
|
72
|
+
:configuration,
|
73
|
+
:constructor,
|
74
|
+
:factories,
|
75
|
+
:factory_by_name,
|
76
|
+
:initialize_with,
|
77
|
+
:register_callback,
|
78
|
+
:register_default_callbacks,
|
79
|
+
:register_default_strategies,
|
80
|
+
:register_factory,
|
81
|
+
:register_sequence,
|
82
|
+
:register_strategy,
|
83
|
+
:register_trait,
|
84
|
+
:reset_configuration,
|
85
|
+
:rewind_sequences,
|
86
|
+
:sequence_by_name,
|
87
|
+
:sequences,
|
88
|
+
:skip_create,
|
77
89
|
:strategies,
|
78
|
-
:
|
90
|
+
:strategy_by_name,
|
79
91
|
:to_create,
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
def self.sequence_by_name(name)
|
111
|
-
sequences.find(name)
|
112
|
-
end
|
113
|
-
|
114
|
-
def self.rewind_sequences
|
115
|
-
sequences.each(&:rewind)
|
116
|
-
end
|
117
|
-
|
118
|
-
def self.register_trait(trait)
|
119
|
-
trait.names.each do |name|
|
120
|
-
traits.register(name, trait)
|
121
|
-
end
|
122
|
-
trait
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.trait_by_name(name)
|
126
|
-
traits.find(name)
|
127
|
-
end
|
128
|
-
|
129
|
-
def self.register_strategy(strategy_name, strategy_class)
|
130
|
-
strategies.register(strategy_name, strategy_class)
|
131
|
-
StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.strategy_by_name(name)
|
135
|
-
strategies.find(name)
|
136
|
-
end
|
137
|
-
|
138
|
-
def self.register_default_strategies
|
139
|
-
register_strategy(:build, FactoryBot::Strategy::Build)
|
140
|
-
register_strategy(:create, FactoryBot::Strategy::Create)
|
141
|
-
register_strategy(:attributes_for, FactoryBot::Strategy::AttributesFor)
|
142
|
-
register_strategy(:build_stubbed, FactoryBot::Strategy::Stub)
|
143
|
-
register_strategy(:null, FactoryBot::Strategy::Null)
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.register_default_callbacks
|
147
|
-
register_callback(:after_build)
|
148
|
-
register_callback(:after_create)
|
149
|
-
register_callback(:after_stub)
|
150
|
-
register_callback(:before_create)
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.register_callback(name)
|
154
|
-
name = name.to_sym
|
155
|
-
callback_names << name
|
92
|
+
:trait_by_name,
|
93
|
+
:traits,
|
94
|
+
to: Internal
|
95
|
+
|
96
|
+
attr_accessor :allow_class_lookup
|
97
|
+
|
98
|
+
deprecate :allow_class_lookup,
|
99
|
+
:allow_class_lookup=,
|
100
|
+
:callback_names,
|
101
|
+
:callbacks,
|
102
|
+
:configuration,
|
103
|
+
:constructor,
|
104
|
+
:factory_by_name,
|
105
|
+
:initialize_with,
|
106
|
+
:register_callback,
|
107
|
+
:register_default_callbacks,
|
108
|
+
:register_default_strategies,
|
109
|
+
:register_factory,
|
110
|
+
:register_sequence,
|
111
|
+
:register_trait,
|
112
|
+
:reset_configuration,
|
113
|
+
:sequence_by_name,
|
114
|
+
:sequences,
|
115
|
+
:skip_create,
|
116
|
+
:strategies,
|
117
|
+
:to_create,
|
118
|
+
:trait_by_name,
|
119
|
+
:traits,
|
120
|
+
deprecator: Deprecation
|
156
121
|
end
|
157
122
|
end
|
158
123
|
|
159
|
-
FactoryBot.register_default_strategies
|
160
|
-
FactoryBot.register_default_callbacks
|
124
|
+
FactoryBot::Internal.register_default_strategies
|
125
|
+
FactoryBot::Internal.register_default_callbacks
|