factory_bot 4.8.2 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.yardopts +1 -0
- data/GETTING_STARTED.md +226 -129
- data/LICENSE +1 -1
- data/NAME.md +12 -5
- data/NEWS.md +351 -0
- data/README.md +35 -27
- 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 +65 -41
- 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 +9 -1
- data/lib/factory_bot/strategy/null.rb +2 -4
- data/lib/factory_bot/strategy/stub.rb +32 -36
- 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 -134
- metadata +79 -64
- data/.autotest +0 -9
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.simplecov +0 -4
- data/.travis.yml +0 -38
- data/Appraisals +0 -19
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -103
- data/NEWS +0 -293
- data/Rakefile +0 -36
- data/cucumber.yml +0 -1
- data/factory_bot.gemspec +0 -36
- data/factory_girl.gemspec +0 -40
- data/gemfiles/3.2.gemfile +0 -10
- data/gemfiles/3.2.gemfile.lock +0 -105
- data/gemfiles/4.0.gemfile +0 -10
- data/gemfiles/4.0.gemfile.lock +0 -105
- data/gemfiles/4.1.gemfile +0 -10
- data/gemfiles/4.1.gemfile.lock +0 -104
- data/gemfiles/4.2.gemfile +0 -10
- data/gemfiles/4.2.gemfile.lock +0 -104
- data/gemfiles/5.0.gemfile +0 -10
- data/gemfiles/5.0.gemfile.lock +0 -103
- 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
- data/lib/factory_girl.rb +0 -5
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2008-
|
1
|
+
Copyright (c) 2008-2019 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/NAME.md
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# Project Naming History
|
2
2
|
|
3
|
-
|
4
|
-
library.
|
3
|
+
## Factory Girl
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
This library was [initially released](https://robots.thoughtbot.com/waiting-for-a-factory-girl)
|
6
|
+
in 2008 with the name "Factory Girl".
|
7
|
+
|
8
|
+
We chose the name as a nod in the direction of the [Factory method](https://en.wikipedia.org/wiki/Factory_method_pattern)
|
8
9
|
and [Object Mother](http://martinfowler.com/bliki/ObjectMother.html) software
|
9
10
|
patterns from the _Design Patterns_ book, and as a reference to the
|
10
11
|
[Rolling Stones song](https://www.youtube.com/watch?v=4jKix2DFlnA) of the same
|
11
12
|
name.
|
13
|
+
|
14
|
+
## Factory Bot
|
15
|
+
|
16
|
+
The name "Factory Girl" was confusing to some developers who encountered this
|
17
|
+
library, and offensive or problematic to others. In October 2017 we [renamed the library](https://robots.thoughtbot.com/factory_bot)
|
18
|
+
to "Factory Bot".
|
data/NEWS.md
ADDED
@@ -0,0 +1,351 @@
|
|
1
|
+
# News
|
2
|
+
|
3
|
+
## 5.2.0 (April 24, 2020)
|
4
|
+
* Added: Pass index to block for `*_list` methods
|
5
|
+
* Deprecated: top-level methods meant only for internal use: `callbacks`, `configuration`, `constructor`, `initialize_with`, `register_sequence`, `resent_configuration`, `skip_create`, `to_create`
|
6
|
+
|
7
|
+
## 5.1.2 (March 25, 2020)
|
8
|
+
* Fixed: Ruby 2.7 keyword deprecation warning in FactoryBot.lint
|
9
|
+
|
10
|
+
## 5.1.1 (October 2, 2019)
|
11
|
+
* Improved: performance of traits
|
12
|
+
* Fixed: registering strategies on JRuby
|
13
|
+
|
14
|
+
## 5.1.0 (September 21, 2019)
|
15
|
+
* Added: "Did you mean?" style error message to help with typos in association declarations
|
16
|
+
* Changed: `NoMethodError` for static attributes now offers a "Did you mean?" style message
|
17
|
+
* Fixed: avoid undefining inherited evaluator methods
|
18
|
+
* Fixed: avoid stubbing id for records without a primary key
|
19
|
+
* Fixed: raise a helpful error for self-referencing traits to avoid a `SystemStackError`
|
20
|
+
* 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`
|
21
|
+
|
22
|
+
## 5.0.2 (February 22, 2019)
|
23
|
+
* Bugfix: raise "Trait not registered" error when passing invalid trait arguments
|
24
|
+
|
25
|
+
## 5.0.1 (February 15, 2019)
|
26
|
+
* Bugfix: Do not raise error when two sequences have the same name
|
27
|
+
in two traits that have the same name
|
28
|
+
|
29
|
+
## 5.0.0 (February 1, 2019)
|
30
|
+
* Added: Verbose option to include full backtraces in the linting output
|
31
|
+
* Changed: use_parent_strategy now defaults to true, so by default the
|
32
|
+
build strategy will build, rather than create associations
|
33
|
+
* Changed: Passing a block when defining associations now raises an error
|
34
|
+
* Bugfix: use_parent_strategy is no longer reset by FactoryBot.reload
|
35
|
+
* Bugfix: rewind_sequences will now rewind local sequences along with the global ones
|
36
|
+
* Bugfix: the build_stubbed strategy now sets timestamps without changing the
|
37
|
+
the original behavior of the timestamp methods
|
38
|
+
* Bugfix: avoid a stack error when referring to an "attributes" attribute in initialize_with
|
39
|
+
* Removed: support for EOL versions of Ruby and Rails
|
40
|
+
* Removed: static attributes (use dynamic attributes with a block instead)
|
41
|
+
* Removed: looking up factories by class
|
42
|
+
* Removed: ignore method (use transient instead)
|
43
|
+
* Removed: duplicate_attribute_assignment_from_initialize_with configuration option
|
44
|
+
* Deprecated: allow_class_lookup configuration option
|
45
|
+
|
46
|
+
## 4.11.1 (September 7, 2018)
|
47
|
+
* Documentation: Include .yardopts in the gem to fix broken RubyDoc links
|
48
|
+
|
49
|
+
## 4.11.0 (August, 15, 2018)
|
50
|
+
* Bugfix: Do not raise error for valid build_stubbed methods: decrement, increment, and toggle
|
51
|
+
* Bugfix: Do not add timestamps with build_stubbed for objects that shouldn't have timestamps
|
52
|
+
* Deprecate static attributes
|
53
|
+
|
54
|
+
## 4.10.0 (May 25, 2018)
|
55
|
+
* Allow sequences to be rewound
|
56
|
+
|
57
|
+
## 4.9.0 (skipped - FactoryGirl only release)
|
58
|
+
|
59
|
+
## 4.8.2 (October 20, 2017)
|
60
|
+
* Rename factory_girl to factory_bot
|
61
|
+
|
62
|
+
## 4.8.1 (September 28, 2017)
|
63
|
+
* Explicitly define `#destroyed?` within the `Stub` strategy to return `nil` instead of raising
|
64
|
+
* Update various dependencies
|
65
|
+
* Update internal test suite to use RSpec's mocking/stubbing instead of mocha
|
66
|
+
|
67
|
+
## 4.8.0 (December 16, 2016)
|
68
|
+
* Improve documentation
|
69
|
+
* Add `FactoryGirl.generate_list` to be consistent with `build_list`/`create_list` and friends
|
70
|
+
* Add `FactoryGirl.use_parent_strategy` configuration to allow associations to leverage parent build strategy
|
71
|
+
|
72
|
+
## 4.7.0 (April 1, 2016)
|
73
|
+
* Improve documentation
|
74
|
+
* Improve instrumentation payload to include traits, overrides, and the factory itself
|
75
|
+
* Allow linting of traits
|
76
|
+
* Deprecate factory lookup by class name in preparation for 5.0
|
77
|
+
* Improve internal performance by using flat_map instead of map and compact
|
78
|
+
* Improve handling of dirty attributes after building a stubbed object
|
79
|
+
* Reduce warnings from redefining methods
|
80
|
+
|
81
|
+
## 4.6.0 (skipped)
|
82
|
+
|
83
|
+
## 4.5.0 (October 17, 2014)
|
84
|
+
* Improve FactoryGirl.lint by including exception and message in output
|
85
|
+
* Allow selective linting
|
86
|
+
* Use more explicit #public_send when doing attribute assignment
|
87
|
+
* Improve documentation around FactoryGirl.lint and initialize_with
|
88
|
+
* Deprecate #ignore in favor of #transient
|
89
|
+
|
90
|
+
## 4.4.0 (February 10, 2014)
|
91
|
+
* Add FactoryGirl.lint
|
92
|
+
* Fix memory leak in duplicate traits
|
93
|
+
* Update documentation
|
94
|
+
|
95
|
+
## 4.3.0 (November 3, 2013)
|
96
|
+
* Start testing against Rails 4.0 and Ruby 2.0.0
|
97
|
+
* Stop testing against Rails 3.0 and Ruby 1.9.2
|
98
|
+
* Add `*_pair` methods to only build two objects
|
99
|
+
* Raise if a method is defined with a FactoryGirl block (factory or trait)
|
100
|
+
* Allow use of Symbol#to_proc in callbacks
|
101
|
+
* Add global callbacks
|
102
|
+
* Improve GETTING_STARTED and README
|
103
|
+
|
104
|
+
## 4.2.0 (January 18, 2013)
|
105
|
+
* Improve documentation
|
106
|
+
* Allow `*_list` syntax methods to accept a block
|
107
|
+
* Update gem dependencies
|
108
|
+
* Allow setting id for objects created with `build_stubbed`
|
109
|
+
* Fix Stub strategy to mimic ActiveRecord regarding `created_at`
|
110
|
+
* Evaluate sequences within the context of an Evaluator
|
111
|
+
* Fix Mocha deprecation warning
|
112
|
+
* Fix some warnings when running RUBYOPT=-w rake
|
113
|
+
* Convert test suite to RSpec's "expect" syntax
|
114
|
+
|
115
|
+
## 4.1.0 (September 11, 2012)
|
116
|
+
* Allow multiple callbacks to bind to the same block
|
117
|
+
* Fix documentation surrounding the stub strategy
|
118
|
+
|
119
|
+
## 4.0.0 (August 3, 2012)
|
120
|
+
* Remove deprecated cucumber_steps
|
121
|
+
* Remove deprecated alternate syntaxes
|
122
|
+
* Deprecate duplicate_attribute_assignment_from_initialize_with, which is now unused
|
123
|
+
as attributes assigned within initialize_with are not subsequently assigned
|
124
|
+
|
125
|
+
## 3.6.1 (August 2, 2012)
|
126
|
+
Update README to include info about running with JRuby
|
127
|
+
* Update dependencies on RSpec and tiny versions of Rails in Appraisal
|
128
|
+
* Improve flexibility of using traits with associations and add documentation
|
129
|
+
* Stub update_column to raise to mirror ActiveRecord's change from update_attribute
|
130
|
+
|
131
|
+
## 3.6.0 (July 27, 2012)
|
132
|
+
* Code/spec cleanup
|
133
|
+
* Allow factories with traits to be used in associations
|
134
|
+
* Refactor Factory to use DefinitionHierarchy to handle managing callbacks,
|
135
|
+
custom constructor, and custom to_create
|
136
|
+
* Add memoization to speed up factories providing attribute overrides
|
137
|
+
* Add initial support of JRuby when running in 1.9 mode
|
138
|
+
* Improve docs on what happens when including FactoryGirl::Syntax::Methods
|
139
|
+
|
140
|
+
## 3.5.0 (June 22, 2012)
|
141
|
+
* Allow created_at to be set when using build_stubbed
|
142
|
+
* Deprecate FactoryGirl step definitions
|
143
|
+
|
144
|
+
## 3.4.2 (June 19, 2012)
|
145
|
+
* Fix bug in traits with callbacks called implicitly in factories whose
|
146
|
+
callbacks trigger multiple times
|
147
|
+
|
148
|
+
## 3.4.1 (June 18, 2012)
|
149
|
+
* Fix traits so they can be nested and referred to from other traits
|
150
|
+
|
151
|
+
## 3.4.0 (June 11, 2012)
|
152
|
+
* Sequences support Enumerators
|
153
|
+
* Optionally disable duplicate assignment of attributes in initialize_with
|
154
|
+
* Make hash of public attributes available in initialize_with
|
155
|
+
* Support referring to a factory based on class name
|
156
|
+
|
157
|
+
## 3.3.0 (May 13, 2012)
|
158
|
+
* Allow to_create, skip_create, and initialize_with to be defined globally
|
159
|
+
* Allow to_create, skip_create, and initialize_with to be defined within traits
|
160
|
+
* Fix deprecation messages for alternate syntaxes (make, generate, etc.)
|
161
|
+
* Improve library documentation
|
162
|
+
* Deprecate after_build, after_create, before_create, after_stub in favor of new callbacks
|
163
|
+
* Introduce new callback syntax: after(:build) {}, after(:custom) {}, or callback(:different) {}
|
164
|
+
This allows for declaring any callback, usable with custom strategies
|
165
|
+
* Add attributes_for_list and build_stubbed_list with the StrategySyntaxMethodRegistrar
|
166
|
+
* Allow use of syntax methods (build, create, generate, etc) implicitly in callbacks
|
167
|
+
* Internal refactoring of a handful of components
|
168
|
+
|
169
|
+
## 3.2.0 (April 24, 2012)
|
170
|
+
* Use AS::Notifications for pub/sub to track running factories
|
171
|
+
* Call new within initialize_with implicitly on the build class
|
172
|
+
* Skip to_create with skip_create
|
173
|
+
* Allow registration of custom strategies
|
174
|
+
* Deprecate alternate syntaxes
|
175
|
+
* Implicitly call factory_bot's syntax methods from dynamic attributes
|
176
|
+
|
177
|
+
## 3.1.0 (April 6, 2012)
|
178
|
+
* Sequences support aliases, which reference the same block
|
179
|
+
* Update documentation
|
180
|
+
* Add before_create callback
|
181
|
+
* Support use of #attribute_names method to determine available attributes for steps
|
182
|
+
* Use ActiveSupport::Deprecation for all deprecations
|
183
|
+
|
184
|
+
## 3.0.0 (March 23, 2012)
|
185
|
+
* Deprecate the vintage syntax
|
186
|
+
* Remove Rails 2.x support
|
187
|
+
* Remove Ruby 1.8 support
|
188
|
+
* Remove deprecated features, including default_strategy, factory_name,
|
189
|
+
:method for defining default strategy, ignore on individual attributes, and
|
190
|
+
interacting with Factory the way you would FactoryGirl
|
191
|
+
|
192
|
+
## 2.6.4 (March 16, 2012)
|
193
|
+
* Do not ignore names of transient attributes
|
194
|
+
* Ensure attributes set on instance are calculated uniquely
|
195
|
+
|
196
|
+
## 2.6.3 (March 9, 2012)
|
197
|
+
* Fix issue with traits not being present the first time a factory is accessed
|
198
|
+
* Update available Cucumber step definitions to not require a trailing colon
|
199
|
+
when building a table of attributes to instantiate records with
|
200
|
+
|
201
|
+
## 2.6.2 (March 9, 2012)
|
202
|
+
* Allow factories to use all their ancestors' traits
|
203
|
+
* Ignore bin dir generated by bundler
|
204
|
+
* Namespace ::Factory as top-level to fix vintage syntax issue with
|
205
|
+
Ruby 1.9.2-p3p18
|
206
|
+
|
207
|
+
## 2.6.1 (March 2, 2012)
|
208
|
+
* Use FactoryGirl.reload in specs
|
209
|
+
* Clean up running named factories with a particular strategy with
|
210
|
+
FactoryGirl::FactoryRunner
|
211
|
+
|
212
|
+
## 2.6.0 (February 17, 2012)
|
213
|
+
* Improve documentation of has_many associations in the GETTING_STARTED
|
214
|
+
document
|
215
|
+
* Deprecate :method in favor of :strategy when overriding an association's
|
216
|
+
build strategy
|
217
|
+
|
218
|
+
## 2.5.2 (February 10, 2012)
|
219
|
+
* Fix step definitions to use associations defined in parent factories
|
220
|
+
* Add inline trait support to (build|create)_list
|
221
|
+
* Update ActiveSupport dependency to >= 2.3.9, which introduced
|
222
|
+
class_attribute
|
223
|
+
|
224
|
+
## 2.5.1 (February 3, 2012)
|
225
|
+
* Fix attribute evaluation when the attribute isn't defined in the factory but
|
226
|
+
is a private method on Object
|
227
|
+
* Update rubygems on Travis before running tests
|
228
|
+
* Fix spec name
|
229
|
+
* Update GETTING_STARTED with correct usage of build_stubbed
|
230
|
+
* Update README with more info on initialize_with
|
231
|
+
* Honor :parent on factory over block nesting
|
232
|
+
|
233
|
+
## 2.5.0 (January 20, 2012)
|
234
|
+
* Revert 'Deprecate build_stubbed and attributes_for'
|
235
|
+
* Implement initialize_with to allow overriding object instantiation
|
236
|
+
* Ensure FG runs against Rails 3.2.0
|
237
|
+
|
238
|
+
## 2.4.2 (January 18, 2012)
|
239
|
+
* Fix inline traits' interaction with defaults on the factory
|
240
|
+
|
241
|
+
## 2.4.1 (January 17, 2012)
|
242
|
+
* Deprecate build_stubbed and attributes_for
|
243
|
+
* Fix inline traits
|
244
|
+
|
245
|
+
## 2.4.0 (January 13, 2012)
|
246
|
+
* Refactor internals of FactoryGirl to use anonymous class on which attributes
|
247
|
+
get defined
|
248
|
+
* Explicitly require Ruby 1.8.7 or higher in gemspec
|
249
|
+
* Fix documentation
|
250
|
+
* Add Gemnasium status to documentation
|
251
|
+
* Supplying a Class to a factory that overrides to_s no longer results in
|
252
|
+
getting the wrong Class constructed
|
253
|
+
* Be more agnostic about ORMs when using columns in FactoryGirl step
|
254
|
+
definitions
|
255
|
+
* Test against Active Record 3.2.0.rc2
|
256
|
+
* Update GETTING_STARTED to use Ruby syntax highlighting
|
257
|
+
|
258
|
+
## 2.3.2 (November 26, 2011)
|
259
|
+
* Move logic of where instance.save! is set to Definition
|
260
|
+
* Fix method name from aliases_for? to alias_for?
|
261
|
+
* Refactor internal attribute handling to use an anonymous class instead of
|
262
|
+
faking Ruby's variable resolution. This allows for more sane usage of
|
263
|
+
attributes without having to manage sorting priority because attributes
|
264
|
+
can turn themselves into procs, which are used with define_method on a
|
265
|
+
class so attributes work correctly all the time.
|
266
|
+
|
267
|
+
## 2.3.1 (November 23, 2011)
|
268
|
+
* Remove internally-used associate method from all the FactoryGirl::Proxy subclasses
|
269
|
+
* Move around requiring of files
|
270
|
+
* Consolidate errors into factory_bot.rb
|
271
|
+
* Refactor AttributeList to deal with priority only when iterating over
|
272
|
+
attributes
|
273
|
+
* Refactor internals of some of the Proxy subclasses
|
274
|
+
* Ensure callbacks on traits are executed in the correct order
|
275
|
+
|
276
|
+
## 2.3.0 (November 18, 2011)
|
277
|
+
* Registries are named, resulting in better messages when factories, traits,
|
278
|
+
or sequences cannot be found
|
279
|
+
* Fix incorrect tests
|
280
|
+
* Internals refactoring introducing FactoryGirl::NullFactory,
|
281
|
+
FactoryGirl::Definition, and FactoryGirl::DeclarationList
|
282
|
+
* Use ActiveSupport for Hash#except and its delegation capabilities
|
283
|
+
* Fix usage of callbacks when added via implicit traits
|
284
|
+
* Use Bundler tasks and clean up dependencies
|
285
|
+
* Fix failing spec for big letters in factory name passed as symbol
|
286
|
+
* Add ability for traits to be added dynamically when creating an instance via
|
287
|
+
build, create, build_stubbed, or attributes_for
|
288
|
+
|
289
|
+
## 2.2.0 (October 14, 2011)
|
290
|
+
* Clean up RSpec suite to not use 'should'
|
291
|
+
* Use create_list in step definitions
|
292
|
+
* Syntax methods that deal with ORM interaction (attributes_for, build, build_stubbed,
|
293
|
+
and create) now accept a block that yields the result. This results in a
|
294
|
+
more convenient way to interact with the result than using Object.tap.
|
295
|
+
* Standardize deprecation warnings
|
296
|
+
* Update transient attribute syntax to use blocks instead of calling ignore on
|
297
|
+
each attribute declaration
|
298
|
+
* Parents can be defined after children because factories are evaluated when
|
299
|
+
they're used; this means breaking up factories across multiple files will
|
300
|
+
behave as expected
|
301
|
+
* Large internal refactoring, including changing access modifiers for a
|
302
|
+
handful of methods for a more clearly defined API
|
303
|
+
|
304
|
+
## 2.1.2 (September 23, 2011)
|
305
|
+
* Bugfix: Vintage syntax fixed after bug introduced in 2.1.1
|
306
|
+
* Introduce dependency on activesupport to remove code from Factory class
|
307
|
+
|
308
|
+
## 2.1.1 (September 23, 2011) (yanked)
|
309
|
+
* Bugfix: Parent object callbacks are run before child object callbacks
|
310
|
+
* Declarations: allow overriding/modification of individual traits in child factories
|
311
|
+
* Callbacks refactored to not be attributes
|
312
|
+
* Updating documentation for formatting and clarity (incl. new specificity for cucumber)
|
313
|
+
|
314
|
+
## 2.1.0 (September 02, 2011)
|
315
|
+
* Bugfix: created_at now defined for stubbed models
|
316
|
+
* Gemspec updated for use with Rails 3.1
|
317
|
+
* Factories can now be modified post-definition (useful for overriding defaults from gems/plugins)
|
318
|
+
* All factories can now be reloaded with Factory.reload
|
319
|
+
* Add :method => build to factory associations to prevent saving of associated objects
|
320
|
+
* Factories defined in {Rails.root}/factories are now loaded by default
|
321
|
+
* Various documentation updates
|
322
|
+
|
323
|
+
## 1.1.4 (November 28, 2008)
|
324
|
+
* Factory.build now uses Factory.create for associations of the built object
|
325
|
+
* Factory definitions are now detected in subdirectories, such as
|
326
|
+
factories/person_factory.rb (thanks to Josh Nichols)
|
327
|
+
* Factory definitions are now loaded after the environment in a Rails project
|
328
|
+
(fixes some issues with dependencies being loaded too early) (thanks to
|
329
|
+
Josh Nichols)
|
330
|
+
* Factory names ending in 's' no longer cause problems (thanks to Alex Sharp
|
331
|
+
and Josh Owens)
|
332
|
+
|
333
|
+
## 1.1.3 (September 12, 2008)
|
334
|
+
* Automatically pull in definitions from factories.rb, test/factories.rb, or
|
335
|
+
spec/factories.rb
|
336
|
+
## 1.1.2 (July 30, 2008)
|
337
|
+
* Improved error handling for invalid and undefined factories/attributes
|
338
|
+
* Improved handling of strings vs symbols vs classes
|
339
|
+
* Added a prettier syntax for handling associations
|
340
|
+
* Updated documentation and fixed compatibility with Rails 2.1
|
341
|
+
|
342
|
+
## 1.1.1 (June 23, 2008)
|
343
|
+
* The attribute "name" no longer requires using #add_attribute
|
344
|
+
|
345
|
+
## 1.1.0 (June 03, 2008)
|
346
|
+
* Added support for dependent attributes
|
347
|
+
* Fixed the attributes_for build strategy to not build associations
|
348
|
+
* Added support for sequences
|
349
|
+
|
350
|
+
## 1.0.0 (May 31, 2008)
|
351
|
+
* First version
|
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
# factory_bot [![Build Status]
|
1
|
+
# factory_bot [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version] [![Reviewed by Hound][hound-badge-image]][hound]
|
2
2
|
|
3
3
|
factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
|
4
4
|
|
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
|
-
|
8
|
+
_[Interested in the history of the project name?][NAME]_
|
9
|
+
|
10
|
+
|
11
|
+
### Transitioning from factory\_girl?
|
12
|
+
|
13
|
+
Check out the [guide](https://github.com/thoughtbot/factory_bot/blob/4-9-0-stable/UPGRADE_FROM_FACTORY_GIRL.md).
|
9
14
|
|
10
|
-
_[Interested in the project name?](NAME.md)._
|
11
15
|
|
12
16
|
Documentation
|
13
17
|
-------------
|
@@ -17,7 +21,7 @@ You should find the documentation for your version of factory_bot on [Rubygems](
|
|
17
21
|
See [GETTING_STARTED] for information on defining and using factories. We also
|
18
22
|
have [a detailed introductory video][], available for free on Upcase.
|
19
23
|
|
20
|
-
[a detailed introductory video]: https://upcase.com/videos/factory-
|
24
|
+
[a detailed introductory video]: https://upcase.com/videos/factory-bot?utm_source=github&utm_medium=open-source&utm_campaign=factory-girl
|
21
25
|
|
22
26
|
Install
|
23
27
|
--------
|
@@ -36,22 +40,11 @@ To install the gem manually from your shell, run:
|
|
36
40
|
gem install factory_bot
|
37
41
|
```
|
38
42
|
|
39
|
-
**Caveat:** As of ActiveSupport 5.0 and above, Ruby 2.2.2+ is required. Because
|
40
|
-
of Rubygems' dependency resolution when installing gems, you may see an error
|
41
|
-
similar to:
|
42
|
-
|
43
|
-
```
|
44
|
-
$ gem install factory_bot
|
45
|
-
ERROR: Error installing factory_bot:
|
46
|
-
activesupport requires Ruby version >= 2.2.2.
|
47
|
-
```
|
48
|
-
|
49
|
-
To bypass this, install a pre-5.0 version of ActiveSupport before installing
|
50
|
-
manually.
|
51
|
-
|
52
43
|
Supported Ruby versions
|
53
44
|
-----------------------
|
54
45
|
|
46
|
+
The factory_bot 5.x series supports MRI Ruby 2.3+.
|
47
|
+
|
55
48
|
The factory_bot 3.x+ series supports MRI Ruby 1.9. Additionally, factory_bot
|
56
49
|
3.6+ supports JRuby 1.6.7.2+ while running in 1.9 mode. See [GETTING_STARTED]
|
57
50
|
for more information on configuring the JRuby environment.
|
@@ -62,34 +55,41 @@ More Information
|
|
62
55
|
----------------
|
63
56
|
|
64
57
|
* [Rubygems](https://rubygems.org/gems/factory_bot)
|
65
|
-
* [Stack Overflow](
|
58
|
+
* [Stack Overflow](https://stackoverflow.com/questions/tagged/factory-bot)
|
66
59
|
* [Issues](https://github.com/thoughtbot/factory_bot/issues)
|
67
|
-
* [GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS](
|
60
|
+
* [GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS](https://robots.thoughtbot.com/)
|
61
|
+
|
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
|
68
64
|
|
69
|
-
|
65
|
+
Useful Tools
|
66
|
+
------------
|
70
67
|
|
71
|
-
[
|
68
|
+
* [FactoryTrace](https://github.com/djezzzl/factory_trace) - helps to find unused factories and traits.
|
72
69
|
|
73
70
|
Contributing
|
74
71
|
------------
|
75
72
|
|
76
73
|
Please see [CONTRIBUTING.md](https://github.com/thoughtbot/factory_bot/blob/master/CONTRIBUTING.md).
|
77
74
|
|
78
|
-
factory_bot was originally written by Joe Ferris and is
|
79
|
-
|
75
|
+
factory_bot was originally written by Joe Ferris and is maintained by thoughtbot.
|
76
|
+
Many improvements and bugfixes were contributed by the [open source
|
80
77
|
community](https://github.com/thoughtbot/factory_bot/graphs/contributors).
|
81
78
|
|
82
79
|
License
|
83
80
|
-------
|
84
81
|
|
85
|
-
factory_bot is Copyright © 2008-
|
82
|
+
factory_bot is Copyright © 2008-2020 Joe Ferris and thoughtbot. It is free
|
86
83
|
software, and may be redistributed under the terms specified in the
|
87
|
-
[LICENSE]
|
84
|
+
[LICENSE] file.
|
85
|
+
|
86
|
+
[LICENSE]: https://github.com/thoughtbot/factory_bot/blob/master/LICENSE
|
87
|
+
|
88
88
|
|
89
89
|
About thoughtbot
|
90
90
|
----------------
|
91
91
|
|
92
|
-
![thoughtbot](
|
92
|
+
![thoughtbot](https://thoughtbot.com/brand_assets/93:44.svg)
|
93
93
|
|
94
94
|
factory_bot is maintained and funded by thoughtbot, inc.
|
95
95
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
@@ -99,4 +99,12 @@ See [our other projects][community] or
|
|
99
99
|
[hire us][hire] to design, develop, and grow your product.
|
100
100
|
|
101
101
|
[community]: https://thoughtbot.com/community?utm_source=github
|
102
|
-
[hire]: https://thoughtbot.com?utm_source=github
|
102
|
+
[hire]: https://thoughtbot.com/hire-us?utm_source=github
|
103
|
+
[ci-image]: https://travis-ci.org/thoughtbot/factory_bot.svg
|
104
|
+
[ci]: https://travis-ci.org/thoughtbot/factory_bot?branch=master
|
105
|
+
[grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot/badges/gpa.svg
|
106
|
+
[grade]: https://codeclimate.com/github/thoughtbot/factory_bot
|
107
|
+
[version-image]: https://badge.fury.io/rb/factory_bot.svg
|
108
|
+
[version]: https://badge.fury.io/rb/factory_bot
|
109
|
+
[hound-badge-image]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
|
110
|
+
[hound]: https://houndci.com
|
data/lib/factory_bot/aliases.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require 'factory_bot/attribute/sequence'
|
1
|
+
require "factory_bot/attribute/dynamic"
|
2
|
+
require "factory_bot/attribute/association"
|
3
|
+
require "factory_bot/attribute/sequence"
|
5
4
|
|
6
5
|
module FactoryBot
|
7
6
|
# @api private
|
@@ -11,11 +10,10 @@ module FactoryBot
|
|
11
10
|
def initialize(name, ignored)
|
12
11
|
@name = name.to_sym
|
13
12
|
@ignored = ignored
|
14
|
-
ensure_non_attribute_writer!
|
15
13
|
end
|
16
14
|
|
17
15
|
def to_proc
|
18
|
-
-> {
|
16
|
+
-> {}
|
19
17
|
end
|
20
18
|
|
21
19
|
def association?
|
@@ -25,38 +23,5 @@ module FactoryBot
|
|
25
23
|
def alias_for?(attr)
|
26
24
|
FactoryBot.aliases_for(attr).include?(name)
|
27
25
|
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def ensure_non_attribute_writer!
|
32
|
-
NonAttributeWriterValidator.new(@name).validate!
|
33
|
-
end
|
34
|
-
|
35
|
-
class NonAttributeWriterValidator
|
36
|
-
def initialize(method_name)
|
37
|
-
@method_name = method_name.to_s
|
38
|
-
@method_name_setter_match = @method_name.match(/(.*)=$/)
|
39
|
-
end
|
40
|
-
|
41
|
-
def validate!
|
42
|
-
if method_is_writer?
|
43
|
-
raise AttributeDefinitionError, error_message
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def method_is_writer?
|
50
|
-
!!@method_name_setter_match
|
51
|
-
end
|
52
|
-
|
53
|
-
def attribute_name
|
54
|
-
@method_name_setter_match[1]
|
55
|
-
end
|
56
|
-
|
57
|
-
def error_message
|
58
|
-
"factory_bot uses '#{attribute_name} value' syntax rather than '#{attribute_name} = value'"
|
59
|
-
end
|
60
|
-
end
|
61
26
|
end
|
62
27
|
end
|
@@ -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
|
5
|
+
@build_class = build_class
|
6
6
|
@instance_builder = instance_builder
|
7
7
|
@evaluator = evaluator
|
8
8
|
@attribute_list = evaluator.class.attribute_list
|
@@ -22,7 +22,7 @@ module FactoryBot
|
|
22
22
|
def hash
|
23
23
|
@evaluator.instance = build_hash
|
24
24
|
|
25
|
-
attributes_to_set_on_hash.
|
25
|
+
attributes_to_set_on_hash.reduce({}) do |result, attribute|
|
26
26
|
result[attribute] = get(attribute)
|
27
27
|
result
|
28
28
|
end
|
@@ -31,12 +31,15 @@ module FactoryBot
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def method_tracking_evaluator
|
34
|
-
@method_tracking_evaluator ||= Decorator::AttributeHash.new(
|
34
|
+
@method_tracking_evaluator ||= Decorator::AttributeHash.new(
|
35
|
+
decorated_evaluator,
|
36
|
+
attribute_names_to_assign,
|
37
|
+
)
|
35
38
|
end
|
36
39
|
|
37
40
|
def decorated_evaluator
|
38
41
|
Decorator::InvocationTracker.new(
|
39
|
-
Decorator::NewConstructor.new(@evaluator, @build_class)
|
42
|
+
Decorator::NewConstructor.new(@evaluator, @build_class),
|
40
43
|
)
|
41
44
|
end
|
42
45
|
|
@@ -65,7 +68,11 @@ module FactoryBot
|
|
65
68
|
end
|
66
69
|
|
67
70
|
def attribute_names_to_assign
|
68
|
-
@attribute_names_to_assign ||=
|
71
|
+
@attribute_names_to_assign ||=
|
72
|
+
non_ignored_attribute_names +
|
73
|
+
override_names -
|
74
|
+
ignored_attribute_names -
|
75
|
+
alias_names_to_ignore
|
69
76
|
end
|
70
77
|
|
71
78
|
def non_ignored_attribute_names
|
@@ -90,8 +97,16 @@ module FactoryBot
|
|
90
97
|
|
91
98
|
def alias_names_to_ignore
|
92
99
|
@attribute_list.non_ignored.flat_map do |attribute|
|
93
|
-
override_names.map
|
100
|
+
override_names.map do |override|
|
101
|
+
attribute.name if ignorable_alias?(attribute, override)
|
102
|
+
end
|
94
103
|
end.compact
|
95
104
|
end
|
105
|
+
|
106
|
+
def ignorable_alias?(attribute, override)
|
107
|
+
attribute.alias_for?(override) &&
|
108
|
+
attribute.name != override &&
|
109
|
+
!ignored_attribute_names.include?(override)
|
110
|
+
end
|
96
111
|
end
|
97
112
|
end
|
@@ -54,7 +54,8 @@ module FactoryBot
|
|
54
54
|
|
55
55
|
def ensure_attribute_not_self_referencing!(attribute)
|
56
56
|
if attribute.respond_to?(:factory) && attribute.factory == @name
|
57
|
-
|
57
|
+
message = "Self-referencing association '#{attribute.name}' in '#{attribute.factory}'"
|
58
|
+
raise AssociationDefinitionError, message
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
data/lib/factory_bot/callback.rb
CHANGED
@@ -22,14 +22,15 @@ module FactoryBot
|
|
22
22
|
end
|
23
23
|
|
24
24
|
protected
|
25
|
+
|
25
26
|
attr_reader :block
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def ensure_valid_callback_name!
|
30
|
-
unless FactoryBot.callback_names.include?(name)
|
31
|
+
unless FactoryBot::Internal.callback_names.include?(name)
|
31
32
|
raise InvalidCallbackNameError, "#{name} is not a valid callback name. " +
|
32
|
-
"Valid callback names are #{FactoryBot.callback_names.inspect}"
|
33
|
+
"Valid callback names are #{FactoryBot::Internal.callback_names.inspect}"
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|