Skip to content

Commit 87229cc

Browse files
authored
Merge pull request #944 from harrylewis/bugfix/add-new-factory-bot-method-to-allow-list
Allow `#traits_for_enum` to be used in a `FactoryBot` factory without a block
2 parents 36b5c77 + 4d2278a commit 87229cc

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Master (Unreleased)
44

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

78
## 1.40.0 (2020-06-11)
89

@@ -520,3 +521,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
520521
[@robotdana]: https://github.com/robotdana
521522
[@rolfschmidt]: https://github.com/rolfschmidt
522523
[@andrykonchin]: https://github.com/andrykonchin
524+
[@harrylewis]: https://github.com/harrylewis

lib/rubocop/rspec/factory_bot.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ module RuboCop
44
module RSpec
55
# RuboCop FactoryBot project namespace
66
module FactoryBot
7-
ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
7+
ATTRIBUTE_DEFINING_METHODS = %i[
8+
factory
9+
ignore
10+
trait
11+
traits_for_enum
12+
transient
13+
].freeze
814

915
UNPROXIED_METHODS = %i[
1016
__send__

spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@
154154
RUBY
155155
end
156156

157+
it 'accepts valid traits_for_enum definition' do
158+
expect_no_offenses(<<-RUBY)
159+
FactoryBot.define do
160+
factory :post do
161+
traits_for_enum :status, [:draft, :published]
162+
end
163+
end
164+
RUBY
165+
end
166+
157167
bad = <<-RUBY
158168
FactoryBot.define do
159169
factory :post do

0 commit comments

Comments
 (0)