Add data update script for backfilling usernames (#12728)
This commit is contained in:
parent
1b47f16291
commit
283b008e97
2 changed files with 23 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
module DataUpdateScripts
|
||||
class BackfillUsernames
|
||||
def run
|
||||
User.where(username: nil).find_each do |user|
|
||||
user.update(username: "user#{user.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
14
spec/lib/data_update_scripts/backfill_usernames_spec.rb
Normal file
14
spec/lib/data_update_scripts/backfill_usernames_spec.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require "rails_helper"
|
||||
require Rails.root.join(
|
||||
"lib/data_update_scripts/20210218041143_backfill_usernames.rb",
|
||||
)
|
||||
|
||||
describe DataUpdateScripts::BackfillUsernames do
|
||||
it " " do
|
||||
user = create(:user)
|
||||
user.update_column(:username, nil)
|
||||
expect do
|
||||
described_class.new.run
|
||||
end.to change { user.reload.username }.from(nil).to("user#{user.id}")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue