forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintenance: Handle Rails/ThreeStateBooleanColumn rubocop check properly
- Loading branch information
Showing
5 changed files
with
72 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
db/migrate/20230508101744_tech_debt_297_three_state_boolean.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
class TechDebt297ThreeStateBoolean < ActiveRecord::Migration[6.1] | ||
def up | ||
# return if it's a new setup | ||
return if !Setting.exists?(name: 'system_init_done') | ||
|
||
users_vip | ||
roles_default_at_signup | ||
import_jobs_dry_run | ||
tokens_persistent | ||
|
||
change_column_default :ticket_article_types, :communication, false | ||
change_column_default :settings, :frontend, false | ||
end | ||
|
||
private | ||
|
||
def users_vip | ||
User.where(vip: nil).in_batches.each_record do |user| | ||
user.update(vip: false) | ||
end | ||
|
||
change_column_null :users, :vip, false, false | ||
end | ||
|
||
def roles_default_at_signup | ||
Role.where(default_at_signup: nil).each do |role| | ||
role.update(default_at_signup: false) | ||
end | ||
|
||
change_column_null :roles, :default_at_signup, false, false | ||
end | ||
|
||
def import_jobs_dry_run | ||
ImportJob.where(dry_run: nil).each do |import_job| | ||
import_job.update(dry_run: false) | ||
end | ||
|
||
change_column_null :import_jobs, :dry_run, false, false | ||
end | ||
|
||
def tokens_persistent | ||
Token.where(persistent: nil).each do |token| | ||
token.update(persistent: false) | ||
end | ||
|
||
change_column_default :tokens, :persistent, false | ||
change_column_null :tokens, :persistent, false, false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe TechDebt297ThreeStateBoolean, db_strategy: :reset, type: :db_migration do | ||
it 'migrates users.vip' do | ||
change_column_null :users, :vip, true | ||
|
||
user = create(:user, vip: nil) | ||
|
||
expect { migrate }.to change { user.reload.vip }.from(nil).to(false) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters