Skip to content

Commit

Permalink
Merge pull request #944 from harrylewis/bugfix/add-new-factory-bot-me…
Browse files Browse the repository at this point in the history
…thod-to-allow-list

Allow `#traits_for_enum` to be used in a `FactoryBot` factory without a block
  • Loading branch information
pirj committed Jun 29, 2020
2 parents 36b5c77 + 4d2278a commit 87229cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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

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

0 comments on commit 87229cc

Please sign in to comment.