Clarify the error behavior on AuthUser syncing
I added bangs to signify they're mutative operations, but also the bang on `create!` helps ensure we'll bail if User creation fails for some reason.
This commit is contained in:
parent
82be3bf5f9
commit
0e7bbd526f
2 changed files with 7 additions and 7 deletions
|
@ -15,14 +15,14 @@ class AuthUser < AuthRecord
|
||||||
#
|
#
|
||||||
# TODO: Should we sync deletions too? We don't do deletions anywhere in app
|
# TODO: Should we sync deletions too? We don't do deletions anywhere in app
|
||||||
# right now, so I'll hold off to avoid leaving dead code around.
|
# right now, so I'll hold off to avoid leaving dead code around.
|
||||||
after_create :create_user
|
after_create :create_user!
|
||||||
after_update :sync_name_with_user, if: :saved_change_to_name?
|
after_update :sync_name_with_user!, if: :saved_change_to_name?
|
||||||
|
|
||||||
def create_user
|
def create_user!
|
||||||
User.create(name: name, auth_server_id: 1, remote_id: id)
|
User.create!(name: name, auth_server_id: 1, remote_id: id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_name_with_user
|
def sync_name_with_user!
|
||||||
user.name = name
|
user.name = name
|
||||||
user.save!
|
user.save!
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,9 +24,9 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
scope :top_contributors, -> { order('points DESC').where('points > 0') }
|
scope :top_contributors, -> { order('points DESC').where('points > 0') }
|
||||||
|
|
||||||
after_update :sync_name_with_auth_user, if: :saved_change_to_name?
|
after_update :sync_name_with_auth_user!, if: :saved_change_to_name?
|
||||||
|
|
||||||
def sync_name_with_auth_user
|
def sync_name_with_auth_user!
|
||||||
auth_user.name = name
|
auth_user.name = name
|
||||||
auth_user.save!
|
auth_user.save!
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue