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

Rails/MigrationClassName triggers on inner classes #659

Closed
tomhughes opened this issue Mar 15, 2022 · 4 comments
Closed

Rails/MigrationClassName triggers on inner classes #659

tomhughes opened this issue Mar 15, 2022 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@tomhughes
Copy link

Expected behavior

The Rails/MigrationClassName cop should only trigger on the top level class in a migration.

Actual behavior

The Rails/MigrationClassName cop triggers on the inner classes in a migration.

Steps to reproduce the problem

Consider this example:

class AddEmailValid < ActiveRecord::Migration[4.2]
  class User < ApplicationRecord
  end

  def self.up
    add_column "users", "email_valid", :boolean, :default => false, :null => false
    User.update_all("email_valid = (active != 0)") # email_valid is :boolean, but active is :integer. "email_valid = active" (see r11802 or earlier) will fail for stricter dbs than mysql
  end

  def self.down
    remove_column "users", "email_valid"
  end
end

with rubocop-rails 2.14.0 the inner User class is renamed to AddEmailValid.

RuboCop version

1.26.0 (using Parser 3.1.1.0, rubocop-ast 1.16.0, running on ruby 3.0.2 x86_64-linux)

  • rubocop-minitest 0.18.0
  • rubocop-performance 1.13.3
  • rubocop-rails 2.14.0
  • rubocop-rake 0.6.0
tomhughes added a commit to tomhughes/openstreetmap-website that referenced this issue Mar 15, 2022
@koic
Copy link
Member

koic commented Mar 16, 2022

This issue is a dup with #657.

@koic koic added the duplicate This issue or pull request already exists label Mar 16, 2022
@koic koic closed this as completed Mar 16, 2022
@koic
Copy link
Member

koic commented Mar 16, 2022

RuboCop Rails 2.14.1 has been released.
https://github.com/rubocop/rubocop-rails/releases/tag/v2.14.1

@tomhughes
Copy link
Author

Thanks. Unfortunately I found another failing case now which I've reported as #660.

@mkllnk
Copy link

mkllnk commented Mar 16, 2022

I still see the same behaviour with v2.14.1. Inner classes descending from ActiveRecord::Base are flagged and "corrected".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants