factory_bot 4.11.1 → 6.2.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +58 -13
  3. data/GETTING_STARTED.md +785 -153
  4. data/LICENSE +1 -1
  5. data/NEWS.md +379 -0
  6. data/README.md +20 -30
  7. data/lib/factory_bot/aliases.rb +2 -2
  8. data/lib/factory_bot/attribute/association.rb +2 -2
  9. data/lib/factory_bot/attribute/dynamic.rb +3 -2
  10. data/lib/factory_bot/attribute.rb +4 -39
  11. data/lib/factory_bot/attribute_assigner.rb +24 -10
  12. data/lib/factory_bot/attribute_list.rb +3 -2
  13. data/lib/factory_bot/callback.rb +4 -11
  14. data/lib/factory_bot/configuration.rb +15 -19
  15. data/lib/factory_bot/declaration/association.rb +33 -3
  16. data/lib/factory_bot/declaration/dynamic.rb +3 -1
  17. data/lib/factory_bot/declaration/implicit.rb +7 -2
  18. data/lib/factory_bot/declaration.rb +5 -5
  19. data/lib/factory_bot/declaration_list.rb +3 -3
  20. data/lib/factory_bot/decorator/attribute_hash.rb +1 -1
  21. data/lib/factory_bot/decorator/invocation_tracker.rb +2 -1
  22. data/lib/factory_bot/decorator.rb +20 -4
  23. data/lib/factory_bot/definition.rb +69 -21
  24. data/lib/factory_bot/definition_hierarchy.rb +1 -11
  25. data/lib/factory_bot/definition_proxy.rb +119 -64
  26. data/lib/factory_bot/enum.rb +27 -0
  27. data/lib/factory_bot/errors.rb +7 -4
  28. data/lib/factory_bot/evaluation.rb +1 -1
  29. data/lib/factory_bot/evaluator.rb +10 -11
  30. data/lib/factory_bot/evaluator_class_definer.rb +1 -1
  31. data/lib/factory_bot/factory.rb +12 -12
  32. data/lib/factory_bot/factory_runner.rb +4 -4
  33. data/lib/factory_bot/find_definitions.rb +2 -2
  34. data/lib/factory_bot/internal.rb +91 -0
  35. data/lib/factory_bot/linter.rb +41 -28
  36. data/lib/factory_bot/null_factory.rb +13 -4
  37. data/lib/factory_bot/null_object.rb +2 -6
  38. data/lib/factory_bot/registry.rb +17 -8
  39. data/lib/factory_bot/reload.rb +2 -3
  40. data/lib/factory_bot/sequence.rb +5 -6
  41. data/lib/factory_bot/strategy/stub.rb +37 -32
  42. data/lib/factory_bot/strategy_calculator.rb +1 -1
  43. data/lib/factory_bot/strategy_syntax_method_registrar.rb +13 -2
  44. data/lib/factory_bot/syntax/default.rb +13 -25
  45. data/lib/factory_bot/syntax/methods.rb +32 -9
  46. data/lib/factory_bot/syntax.rb +2 -2
  47. data/lib/factory_bot/trait.rb +7 -4
  48. data/lib/factory_bot/version.rb +1 -1
  49. data/lib/factory_bot.rb +71 -140
  50. metadata +46 -34
  51. data/NEWS +0 -306
  52. data/lib/factory_bot/attribute/static.rb +0 -16
  53. data/lib/factory_bot/declaration/static.rb +0 -26
  54. data/lib/factory_bot/decorator/class_key_hash.rb +0 -28
data/NEWS DELETED
@@ -1,306 +0,0 @@
1
- 4.11.1 (September 7, 2018)
2
- Documentation: Include .yardopts in the gem to fix broken RubyDoc links
3
-
4
- 4.11.0 (August, 15, 2018)
5
- Bugfix: Do not raise error for valid build_stubbed methods: decrement, increment, and toggle
6
- Bugfix: Do not add timestamps with build_stubbed for objects that shouldn't have timestamps
7
- Deprecate static attributes
8
-
9
- 4.10.0 (May 25, 2018)
10
- Allow sequences to be rewound
11
-
12
- 4.9.0 (skipped - FactoryGirl only release)
13
-
14
- 4.8.2 (October 20, 2017)
15
- Rename factory_girl to factory_bot
16
-
17
- 4.8.1 (September 28, 2017)
18
- Explicitly define `#destroyed?` within the `Stub` strategy to return `nil` instead of raising
19
- Update various dependencies
20
- Update internal test suite to use RSpec's mocking/stubbing instead of mocha
21
-
22
- 4.8.0 (December 16, 2016)
23
- Improve documentation
24
- Add `FactoryGirl.generate_list` to be consistent with `build_list`/`create_list` and friends
25
- Add `FactoryGirl.use_parent_strategy` configuration to allow associations to leverage parent build strategy
26
-
27
- 4.7.0 (April 1, 2016)
28
- Improve documentation
29
- Improve instrumentation payload to include traits, overrides, and the factory itself
30
- Allow linting of traits
31
- Deprecate factory lookup by class name in preparation for 5.0
32
- Improve internal performance by using flat_map instead of map and compact
33
- Improve handling of dirty attributes after building a stubbed object
34
- Reduce warnings from redefining methods
35
-
36
- 4.6.0 (skipped)
37
-
38
- 4.5.0 (October 17, 2014)
39
- Improve FactoryGirl.lint by including exception and message in output
40
- Allow selective linting
41
- Use more explicit #public_send when doing attribute assignment
42
- Improve documentation around FactoryGirl.lint and initialize_with
43
- Deprecate #ignore in favor of #transient
44
-
45
- 4.4.0 (February 10, 2014)
46
- Add FactoryGirl.lint
47
- Fix memory leak in duplicate traits
48
- Update documentation
49
-
50
- 4.3.0 (November 3, 2013)
51
- Start testing against Rails 4.0 and Ruby 2.0.0
52
- Stop testing against Rails 3.0 and Ruby 1.9.2
53
- Add *_pair methods to only build two objects
54
- Raise if a method is defined with a FactoryGirl block (factory or trait)
55
- Allow use of Symbol#to_proc in callbacks
56
- Add global callbacks
57
- Improve GETTING_STARTED and README
58
-
59
- 4.2.0 (January 18, 2013)
60
- Improve documentation
61
- Allow *_list syntax methods to accept a block
62
- Update gem dependencies
63
- Allow setting id for objects created with `build_stubbed`
64
- Fix Stub strategy to mimic ActiveRecord regarding `created_at`
65
- Evaluate sequences within the context of an Evaluator
66
- Fix Mocha deprecation warning
67
- Fix some warnings when running RUBYOPT=-w rake
68
- Convert test suite to RSpec's "expect" syntax
69
-
70
- 4.1.0 (September 11, 2012)
71
- Allow multiple callbacks to bind to the same block
72
- Fix documentation surrounding the stub strategy
73
-
74
- 4.0.0 (August 3, 2012)
75
- Remove deprecated cucumber_steps
76
- Remove deprecated alternate syntaxes
77
- Deprecate duplicate_attribute_assignment_from_initialize_with, which is now unused
78
- as attributes assigned within initialize_with are not subsequently assigned
79
-
80
- 3.6.1 (August 2, 2012)
81
- Update README to include info about running with JRuby
82
- Update dependencies on RSpec and tiny versions of Rails in Appraisal
83
- Improve flexibility of using traits with associations and add documentation
84
- Stub update_column to raise to mirror ActiveRecord's change from update_attribute
85
-
86
- 3.6.0 (July 27, 2012)
87
- Code/spec cleanup
88
- Allow factories with traits to be used in associations
89
- Refactor Factory to use DefinitionHierarchy to handle managing callbacks,
90
- custom constructor, and custom to_create
91
- Add memoization to speed up factories providing attribute overrides
92
- Add initial support of JRuby when running in 1.9 mode
93
- Improve docs on what happens when including FactoryGirl::Syntax::Methods
94
-
95
- 3.5.0 (June 22, 2012)
96
- Allow created_at to be set when using build_stubbed
97
- Deprecate FactoryGirl step definitions
98
-
99
- 3.4.2 (June 19, 2012)
100
- Fix bug in traits with callbacks called implicitly in factories whose
101
- callbacks trigger multiple times
102
-
103
- 3.4.1 (June 18, 2012)
104
- Fix traits so they can be nested and referred to from other traits
105
-
106
- 3.4.0 (June 11, 2012)
107
- Sequences support Enumerators
108
- Optionally disable duplicate assignment of attributes in initialize_with
109
- Make hash of public attributes available in initialize_with
110
- Support referring to a factory based on class name
111
-
112
- 3.3.0 (May 13, 2012)
113
- Allow to_create, skip_create, and initialize_with to be defined globally
114
- Allow to_create, skip_create, and initialize_with to be defined within traits
115
- Fix deprecation messages for alternate syntaxes (make, generate, etc.)
116
- Improve library documentation
117
- Deprecate after_build, after_create, before_create, after_stub in favor of new callbacks
118
- Introduce new callback syntax: after(:build) {}, after(:custom) {}, or callback(:different) {}
119
- This allows for declaring any callback, usable with custom strategies
120
- Add attributes_for_list and build_stubbed_list with the StrategySyntaxMethodRegistrar
121
- Allow use of syntax methods (build, create, generate, etc) implicitly in callbacks
122
- Internal refactoring of a handful of components
123
-
124
- 3.2.0 (April 24, 2012)
125
- Use AS::Notifications for pub/sub to track running factories
126
- Call new within initialize_with implicitly on the build class
127
- Skip to_create with skip_create
128
- Allow registration of custom strategies
129
- Deprecate alternate syntaxes
130
- Implicitly call factory_bot's syntax methods from dynamic attributes
131
-
132
- 3.1.0 (April 6, 2012)
133
- Sequences support aliases, which reference the same block
134
- Update documentation
135
- Add before_create callback
136
- Support use of #attribute_names method to determine available attributes for steps
137
- Use ActiveSupport::Deprecation for all deprecations
138
-
139
- 3.0.0 (March 23, 2012)
140
- Deprecate the vintage syntax
141
- Remove Rails 2.x support
142
- Remove Ruby 1.8 support
143
- Remove deprecated features, including default_strategy, factory_name,
144
- :method for defining default strategy, ignore on individual attributes, and
145
- interacting with Factory the way you would FactoryGirl
146
-
147
- 2.6.4 (March 16, 2012)
148
- Do not ignore names of transient attributes
149
- Ensure attributes set on instance are calculated uniquely
150
-
151
- 2.6.3 (March 9, 2012)
152
- Fix issue with traits not being present the first time a factory is accessed
153
- Update available Cucumber step definitions to not require a trailing colon
154
- when building a table of attributes to instantiate records with
155
-
156
- 2.6.2 (March 9, 2012)
157
- Allow factories to use all their ancestors' traits
158
- Ignore bin dir generated by bundler
159
- Namespace ::Factory as top-level to fix vintage syntax issue with
160
- Ruby 1.9.2-p3p18
161
-
162
- 2.6.1 (March 2, 2012)
163
- Use FactoryGirl.reload in specs
164
- Clean up running named factories with a particular strategy with
165
- FactoryGirl::FactoryRunner
166
-
167
- 2.6.0 (February 17, 2012)
168
- Improve documentation of has_many associations in the GETTING_STARTED
169
- document
170
- Deprecate :method in favor of :strategy when overriding an association's
171
- build strategy
172
-
173
- 2.5.2 (February 10, 2012)
174
- Fix step definitions to use associations defined in parent factories
175
- Add inline trait support to (build|create)_list
176
- Update ActiveSupport dependency to >= 2.3.9, which introduced
177
- class_attribute
178
-
179
- 2.5.1 (February 3, 2012)
180
- Fix attribute evaluation when the attribute isn't defined in the factory but
181
- is a private method on Object
182
- Update rubygems on Travis before running tests
183
- Fix spec name
184
- Update GETTING_STARTED with correct usage of build_stubbed
185
- Update README with more info on initialize_with
186
- Honor :parent on factory over block nesting
187
-
188
- 2.5.0 (January 20, 2012)
189
- Revert 'Deprecate build_stubbed and attributes_for'
190
- Implement initialize_with to allow overriding object instantiation
191
- Ensure FG runs against Rails 3.2.0
192
-
193
- 2.4.2 (January 18, 2012)
194
- Fix inline traits' interaction with defaults on the factory
195
-
196
- 2.4.1 (January 17, 2012)
197
- Deprecate build_stubbed and attributes_for
198
- Fix inline traits
199
-
200
- 2.4.0 (January 13, 2012)
201
- Refactor internals of FactoryGirl to use anonymous class on which attributes
202
- get defined
203
- Explicitly require Ruby 1.8.7 or higher in gemspec
204
- Fix documentation
205
- Add Gemnasium status to documentation
206
- Supplying a Class to a factory that overrides to_s no longer results in
207
- getting the wrong Class constructed
208
- Be more agnostic about ORMs when using columns in FactoryGirl step
209
- definitions
210
- Test against Active Record 3.2.0.rc2
211
- Update GETTING_STARTED to use Ruby syntax highlighting
212
-
213
- 2.3.2 (November 26, 2011)
214
- Move logic of where instance.save! is set to Definition
215
- Fix method name from aliases_for? to alias_for?
216
- Refactor internal attribute handling to use an anonymous class instead of
217
- faking Ruby's variable resolution. This allows for more sane usage of
218
- attributes without having to manage sorting priority because attributes
219
- can turn themselves into procs, which are used with define_method on a
220
- class so attributes work correctly all the time.
221
-
222
- 2.3.1 (November 23, 2011)
223
- Remove internally-used associate method from all the FactoryGirl::Proxy subclasses
224
- Move around requiring of files
225
- Consolidate errors into factory_bot.rb
226
- Refactor AttributeList to deal with priority only when iterating over
227
- attributes
228
- Refactor internals of some of the Proxy subclasses
229
- Ensure callbacks on traits are executed in the correct order
230
-
231
- 2.3.0 (November 18, 2011)
232
- Registries are named, resulting in better messages when factories, traits,
233
- or sequences cannot be found
234
- Fix incorrect tests
235
- Internals refactoring introducing FactoryGirl::NullFactory,
236
- FactoryGirl::Definition, and FactoryGirl::DeclarationList
237
- Use ActiveSupport for Hash#except and its delegation capabilities
238
- Fix usage of callbacks when added via implicit traits
239
- Use Bundler tasks and clean up dependencies
240
- Fix failing spec for big letters in factory name passed as symbol
241
- Add ability for traits to be added dynamically when creating an instance via
242
- build, create, build_stubbed, or attributes_for
243
-
244
- 2.2.0 (October 14, 2011)
245
- Clean up RSpec suite to not use 'should'
246
- Use create_list in step definitions
247
- Syntax methods that deal with ORM interaction (attributes_for, build, build_stubbed,
248
- and create) now accept a block that yields the result. This results in a
249
- more convenient way to interact with the result than using Object.tap.
250
- Standardize deprecation warnings
251
- Update transient attribute syntax to use blocks instead of calling ignore on
252
- each attribute declaration
253
- Parents can be defined after children because factories are evaluated when
254
- they're used; this means breaking up factories across multiple files will
255
- behave as expected
256
- Large internal refactoring, including changing access modifiers for a
257
- handful of methods for a more clearly defined API
258
-
259
- 2.1.2 (September 23, 2011)
260
- Bugfix: Vintage syntax fixed after bug introduced in 2.1.1
261
- Introduce dependency on activesupport to remove code from Factory class
262
-
263
- 2.1.1 (September 23, 2011) (yanked)
264
- Bugfix: Parent object callbacks are run before child object callbacks
265
- Declarations: allow overriding/modification of individual traits in child factories
266
- Callbacks refactored to not be attributes
267
- Updating documentation for formatting and clarity (incl. new specificity for cucumber)
268
-
269
- 2.1.0 (September 02, 2011)
270
- Bugfix: created_at now defined for stubbed models
271
- Gemspec updated for use with Rails 3.1
272
- Factories can now be modified post-definition (useful for overriding defaults from gems/plugins)
273
- All factories can now be reloaded with Factory.reload
274
- Add :method => build to factory associations to prevent saving of associated objects
275
- Factories defined in {Rails.root}/factories are now loaded by default
276
- Various documentation updates
277
-
278
- 1.1.4 (November 28, 2008)
279
- Factory.build now uses Factory.create for associations of the built object
280
- Factory definitions are now detected in subdirectories, such as
281
- factories/person_factory.rb (thanks to Josh Nichols)
282
- Factory definitions are now loaded after the environment in a Rails project
283
- (fixes some issues with dependencies being loaded too early) (thanks to
284
- Josh Nichols)
285
- Factory names ending in 's' no longer cause problems (thanks to Alex Sharp
286
- and Josh Owens)
287
-
288
- 1.1.3 (September 12, 2008)
289
- Automatically pull in definitions from factories.rb, test/factories.rb, or
290
- spec/factories.rb
291
- 1.1.2 (July 30, 2008)
292
- Improved error handling for invalid and undefined factories/attributes
293
- Improved handling of strings vs symbols vs classes
294
- Added a prettier syntax for handling associations
295
- Updated documentation and fixed compatibility with Rails 2.1
296
-
297
- 1.1.1 (June 23, 2008)
298
- The attribute "name" no longer requires using #add_attribute
299
-
300
- 1.1.0 (June 03, 2008)
301
- Added support for dependent attributes
302
- Fixed the attributes_for build strategy to not build associations
303
- Added support for sequences
304
-
305
- 1.0.0 (May 31, 2008)
306
- First version
@@ -1,16 +0,0 @@
1
- module FactoryBot
2
- class Attribute
3
- # @api private
4
- class Static < Attribute
5
- def initialize(name, value, ignored)
6
- super(name, ignored)
7
- @value = value
8
- end
9
-
10
- def to_proc
11
- value = @value
12
- -> { value }
13
- end
14
- end
15
- end
16
- end
@@ -1,26 +0,0 @@
1
- module FactoryBot
2
- class Declaration
3
- # @api private
4
- class Static < Declaration
5
- def initialize(name, value, ignored = false)
6
- super(name, ignored)
7
- @value = value
8
- end
9
-
10
- def ==(other)
11
- name == other.name &&
12
- value == other.value &&
13
- ignored == other.ignored
14
- end
15
-
16
- protected
17
- attr_reader :value
18
-
19
- private
20
-
21
- def build
22
- [Attribute::Static.new(name, @value, @ignored)]
23
- end
24
- end
25
- end
26
- end
@@ -1,28 +0,0 @@
1
- module FactoryBot
2
- class Decorator
3
- class ClassKeyHash < Decorator
4
- def [](key)
5
- @component[symbolized_key key]
6
- end
7
-
8
- def []=(key, value)
9
- @component[symbolized_key key] = value
10
- end
11
-
12
- def key?(key)
13
- @component.key? symbolized_key(key)
14
- end
15
-
16
- private
17
-
18
- def symbolized_key(key)
19
- if key.respond_to?(:to_sym)
20
- key.to_sym
21
- elsif FactoryBot.allow_class_lookup
22
- ActiveSupport::Deprecation.warn "Looking up factories by class is deprecated and will be removed in 5.0. Use symbols instead and set FactoryBot.allow_class_lookup = false", caller
23
- key.to_s.underscore.to_sym
24
- end
25
- end
26
- end
27
- end
28
- end