Skip to content

Commit

Permalink
Merge pull request #46 from tagliala/chore/provide-examples-for-assoc…
Browse files Browse the repository at this point in the history
…iation-style-with-traits

Add an example for an association with factory
  • Loading branch information
pirj authored May 17, 2023
2 parents 7dab265 + e194fe2 commit 81d95db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/modules/ROOT/pages/cops_factorybot.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ end
factory :post do
user
end
# bad
factory :post do
association :user, :author
end
# good
factory :post do
user factory: %i[user author]
end
----

==== EnforcedStyle: explicit
Expand All @@ -51,6 +61,16 @@ factory :post do
association :user
end
# bad
factory :post do
user factory: %i[user author]
end
# good
factory :post do
association :user, :author
end
# good (NonImplicitAssociationMethodNames: ['email'])
sequence :email do |n|
"person#{n}@example.com"
Expand Down
20 changes: 20 additions & 0 deletions lib/rubocop/cop/factory_bot/association_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ module FactoryBot
# user
# end
#
# # bad
# factory :post do
# association :user, :author
# end
#
# # good
# factory :post do
# user factory: %i[user author]
# end
#
# @example EnforcedStyle: explicit
# # bad
# factory :post do
Expand All @@ -32,6 +42,16 @@ module FactoryBot
# association :user
# end
#
# # bad
# factory :post do
# user factory: %i[user author]
# end
#
# # good
# factory :post do
# association :user, :author
# end
#
# # good (NonImplicitAssociationMethodNames: ['email'])
# sequence :email do |n|
# "person#{n}@example.com"
Expand Down

0 comments on commit 81d95db

Please sign in to comment.