-
-
Notifications
You must be signed in to change notification settings - Fork 263
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/ThreeStateBoolean fails when it can't find create_table or change_table #979
Comments
I've encountered the same issue in a different context. Example: # rubocop:disable Rails/SkipsModelValidations
class MakeNewslettersPublishable < ActiveRecord::Migration[7.0]
class Newsletter < ApplicationRecord
end
class WeeklyNewsletter < ApplicationRecord
end
class MonthlyNewsletter < ApplicationRecord
end
def up_alteration(model)
->(t) {
t.string :status
t.index :status
model.where(public: true).update_all(status: "published")
model.where(public: false).update_all(status: "draft")
t.remove :public
}
end
def down_alteration(model)
->(t) {
t.boolean :public
model.where(status: "draft").update_all(public: false)
model.where(status: "published").update_all(public: true)
t.remove :status
}
end
def up
change_table :newsletters, &up_alteration(Newsletter)
change_table :weekly_newsletters, &up_alteration(WeeklyNewsletter)
change_table :monthly_newsletters, &up_alteration(MonthlyNewsletter)
end
def down
change_table :newsletters, &down_alteration(Newsletter)
change_table :weekly_newsletters, &down_alteration(WeeklyNewsletter)
change_table :monthly_newsletters, &down_alteration(MonthlyNewsletter)
end
end
# rubocop:enable Rails/SkipsModelValidations Expected behaviorRubocop shouldn't fail, but should report the three-state problem with the code. Although this cop is a bit awkward for legacy projects. We're never going to change these migration files, even if we do change the column default. So these files are guaranteed to sit in our rubocop_todo file forever, or we'll have to manually disable them. Maybe some way of configuring "migrations created after x date" would be a solution there? Actual Behavior
Rubocop Version
|
Third variant with drop_table: undefined method 'value' for nil:NilClass in lib/rubocop/cop/rails/three_state_boolean_column.rb Expected behaviorNo crash Actual behaviorDescribe here what actually happened.
Steps to reproduce the problem
RuboCop version
|
Started #980 but need someone to take it over/review the approach |
Fixes rubocop#979. This PR fixes an error for `Rails/ThreeStateBooleanColumn` when using `t.boolean` in `drop_table`.
…boolean [Fix #979] Fix an error for `Rails/ThreeStateBooleanColumn`
I have a custom
create_table
style function for enumerated types that also generates a database type and check constraint. This function accepts a block likecreate_table
.Rails/ThreeStateBoolean
fails when checking this.For example
Expected behavior
RuboCop Rails shouldn't fail, and should not report a problem with the example code.
Actual behavior
Steps to reproduce the problem
Run RuboCop Rails on the example code with the
Rails/ThreeStateBooleanColumn
cop enabled (which seems to be the default).RuboCop version
The text was updated successfully, but these errors were encountered: