From 18199419892257a4b6d1902f05e4316772653696 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Mon, 23 Jul 2018 17:53:51 +0800 Subject: [PATCH] Add example for User callback spec (for #2057 fix) --- spec/models/user_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f17817753..dfca9cfcc 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -691,6 +691,25 @@ RSpec.describe User do end end + context 'falsely added on update (change: [nil, ""])' do + let(:orig_number) { nil } + let(:new_number) { '' } + + before { subject } # create user + + it 'does not attempt to update CallerId record' do + allow(Cti::CallerId).to receive(:build).with(any_args) + + expect(Cti::CallerId.where(object: 'User', o_id: subject.id).count) + .to eq(0) + + expect { subject.update(phone: new_number) } + .to change { Cti::CallerId.where(object: 'User', o_id: subject.id).count }.by(0) + + expect(Cti::CallerId).not_to have_received(:build) + end + end + context 'removed on update' do let(:orig_number) { '1234567890' } let(:new_number) { nil }