FIX: do not log username change if the save process was unsuccessful
This commit is contained in:
parent
5605dba85c
commit
a2b1789c3e
|
@ -16,13 +16,13 @@ class UsernameChanger
|
||||||
end
|
end
|
||||||
|
|
||||||
def change(asynchronous: true, run_update_job: true)
|
def change(asynchronous: true, run_update_job: true)
|
||||||
if @actor && @old_username != @new_username
|
|
||||||
StaffActionLogger.new(@actor).log_username_change(@user, @old_username, @new_username)
|
|
||||||
end
|
|
||||||
|
|
||||||
@user.username = @new_username
|
@user.username = @new_username
|
||||||
|
|
||||||
if @user.save
|
if @user.save
|
||||||
|
if @actor && @old_username != @new_username
|
||||||
|
StaffActionLogger.new(@actor).log_username_change(@user, @old_username, @new_username)
|
||||||
|
end
|
||||||
|
|
||||||
UsernameChanger.update_username(user_id: @user.id,
|
UsernameChanger.update_username(user_id: @user.id,
|
||||||
old_username: @old_username,
|
old_username: @old_username,
|
||||||
new_username: @new_username,
|
new_username: @new_username,
|
||||||
|
|
|
@ -56,6 +56,10 @@ describe UsernameChanger do
|
||||||
expect do
|
expect do
|
||||||
UsernameChanger.change(myself, "HanSolo", myself)
|
UsernameChanger.change(myself, "HanSolo", myself)
|
||||||
end.to change { UserHistory.count }.by(0) # make sure it does not log a dupe
|
end.to change { UserHistory.count }.by(0) # make sure it does not log a dupe
|
||||||
|
|
||||||
|
expect do
|
||||||
|
UsernameChanger.change(myself, user.username, myself)
|
||||||
|
end.to change { UserHistory.count }.by(0) # does not log if the username already exists
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue