Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow #traits_for_enum to be used in a FactoryBot factory without a block #944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

* Extend the list of Rails spec types for `RSpec/DescribeClass`. ([@pirj][])
* Fix `FactoryBot/AttributeDefinedStatically` to allow `#traits_for_enum` without a block. ([@harrylewis][])

## 1.40.0 (2020-06-11)

Expand Down Expand Up @@ -520,3 +521,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@robotdana]: https://github.com/robotdana
[@rolfschmidt]: https://github.com/rolfschmidt
[@andrykonchin]: https://github.com/andrykonchin
[@harrylewis]: https://github.com/harrylewis
8 changes: 7 additions & 1 deletion lib/rubocop/rspec/factory_bot.rb
Expand Up @@ -4,7 +4,13 @@ module RuboCop
module RSpec
# RuboCop FactoryBot project namespace
module FactoryBot
ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
ATTRIBUTE_DEFINING_METHODS = %i[
factory
ignore
trait
traits_for_enum
transient
].freeze
Comment on lines -7 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding :traits_for_enum caused a Layout/LineLength offense, so I turned the horizontal list into a vertical list. I also alphabetized the list to align with what was done with the other constants below.


UNPROXIED_METHODS = %i[
__send__
Expand Down
Expand Up @@ -154,6 +154,16 @@
RUBY
end

it 'accepts valid traits_for_enum definition' do
expect_no_offenses(<<-RUBY)
FactoryBot.define do
factory :post do
traits_for_enum :status, [:draft, :published]
end
end
RUBY
end

bad = <<-RUBY
FactoryBot.define do
factory :post do
Expand Down