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

EnumHash breaks on nested constants #114

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec/rubocop/cop/rails/enum_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@
enum status: {:old=>0, :"very active"=>1, "is archived"=>2, 42=>3}
RUBY
end

it 'autocorrects nested constants' do
expect_offense(<<~RUBY)
STATUS::OLD = :old
STATUS::ACTIVE = :active
enum status: [STATUS::OLD, STATUS::ACTIVE]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead.
RUBY

expect_correction(<<~RUBY)
STATUS::OLD = :old
STATUS::ACTIVE = :active
enum status: {STATUS::OLD=>0, STATUS::ACTIVE=>1}
RUBY
end
end

context 'when hash syntax is used' do
Expand Down