factory_bot 5.0.0 → 5.1.2

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