diff --git a/app/services/update_user.rb b/app/services/update_user.rb index ea887f5df98..0ba47d6c107 100644 --- a/app/services/update_user.rb +++ b/app/services/update_user.rb @@ -21,7 +21,7 @@ def call def manage_phone_configuration if attributes[:phone_id].present? - update_phone_configuration + update_phone_configuration unless phone_configuration.nil? else create_phone_configuration end diff --git a/spec/services/update_user_spec.rb b/spec/services/update_user_spec.rb index b1d43fbeb81..7c15f91ed52 100644 --- a/spec/services/update_user_spec.rb +++ b/spec/services/update_user_spec.rb @@ -127,6 +127,16 @@ to be_within(1.second).of original_made_default_at end end + + context 'when phone does not belong to user' do + it 'does not update the user if the phone does not belong to them' do + other_phone = create(:phone_configuration) + attributes[:phone_id] = other_phone.id + expect do + UpdateUser.new(user: user, attributes: attributes).call + end.to_not(change { other_phone.updated_at }) + end + end end end end