From 9ad4b1c2ee20aa7a35f1ca80c9a3520c47f036cc Mon Sep 17 00:00:00 2001 From: Harry Lewis Date: Fri, 26 Jun 2020 21:41:20 -0400 Subject: [PATCH 1/4] Include #traits_for_enum in allowed attribute defining methods --- lib/rubocop/rspec/factory_bot.rb | 2 +- .../factory_bot/attribute_defined_statically_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/rspec/factory_bot.rb b/lib/rubocop/rspec/factory_bot.rb index 539bcf70c..42b89ace4 100644 --- a/lib/rubocop/rspec/factory_bot.rb +++ b/lib/rubocop/rspec/factory_bot.rb @@ -4,7 +4,7 @@ module RuboCop module RSpec # RuboCop FactoryBot project namespace module FactoryBot - ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze + ATTRIBUTE_DEFINING_METHODS = %i[factory trait traits_for_enum transient ignore].freeze UNPROXIED_METHODS = %i[ __send__ diff --git a/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb b/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb index 2e44e5a04..4caba3915 100644 --- a/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +++ b/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb @@ -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 From 4a5b8ceb0d94307e19dd348edbe2ccd96b376c4c Mon Sep 17 00:00:00 2001 From: Harry Lewis Date: Fri, 26 Jun 2020 22:03:02 -0400 Subject: [PATCH 2/4] Turn horizontal list vertical --- lib/rubocop/rspec/factory_bot.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/rspec/factory_bot.rb b/lib/rubocop/rspec/factory_bot.rb index 42b89ace4..9fbda437f 100644 --- a/lib/rubocop/rspec/factory_bot.rb +++ b/lib/rubocop/rspec/factory_bot.rb @@ -4,7 +4,13 @@ module RuboCop module RSpec # RuboCop FactoryBot project namespace module FactoryBot - ATTRIBUTE_DEFINING_METHODS = %i[factory trait traits_for_enum transient ignore].freeze + ATTRIBUTE_DEFINING_METHODS = %i[ + factory + ignore + trait + traits_for_enum + transient + ].freeze UNPROXIED_METHODS = %i[ __send__ From e2a8382162d3afcc682ad151bf8d9dd2e87a1bf9 Mon Sep 17 00:00:00 2001 From: Harry Lewis Date: Mon, 29 Jun 2020 12:43:50 -0400 Subject: [PATCH 3/4] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cda0d7ae..7aba3529f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From 4d2278aaa113c74c4cac4f3e07e9304c23e5a239 Mon Sep 17 00:00:00 2001 From: Harry Lewis Date: Mon, 29 Jun 2020 12:52:35 -0400 Subject: [PATCH 4/4] Add link to contributor section --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aba3529f..4ce00fd95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -521,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