fix: Update associations when a label is updated (#3046)

This commit is contained in:
Pranav Raj S
2021-09-21 10:16:32 +05:30
committed by GitHub
parent aaadd61e09
commit b59e73b10b
7 changed files with 124 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
require 'rails_helper'
describe Labels::UpdateService do
let(:account) { create(:account) }
let(:conversation) { create(:conversation, account: account) }
let(:label) { create(:label, account: account) }
let(:contact) { conversation.contact }
before do
conversation.label_list.add(label.title)
conversation.save!
contact.label_list.add(label.title)
contact.save!
end
describe '#perform' do
it 'updates associated conversations/contacts labels' do
expect(conversation.label_list).to eq([label.title])
expect(contact.label_list).to eq([label.title])
described_class.new(
new_label_title: 'updated-label-title',
old_label_title: label.title,
account_id: account.id
).perform
expect(conversation.reload.label_list).to eq(['updated-label-title'])
expect(contact.reload.label_list).to eq(['updated-label-title'])
end
end
end