From 4ca66c119509bd5228bf9f71eb2c295836386bf9 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 25 Feb 2022 18:01:21 +0530 Subject: [PATCH] fix: Automation loop on conversation_update (#4071) --- app/models/conversation.rb | 3 +++ spec/models/conversation_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 120d1cd3a..c9ce4f6a8 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -183,6 +183,9 @@ class Conversation < ApplicationRecord end def notify_conversation_updation + return unless previous_changes.keys.present? && (previous_changes.keys & %w[team_id assignee_id status snoozed_until + custom_attributes]).present? + dispatcher_dispatch(CONVERSATION_UPDATED) end diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 555957e77..356127043 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -90,6 +90,20 @@ RSpec.describe Conversation, type: :model do .with(described_class::CONVERSATION_READ, kind_of(Time), conversation: conversation, notifiable_assignee_change: true) expect(Rails.configuration.dispatcher).to have_received(:dispatch) .with(described_class::ASSIGNEE_CHANGED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true) + expect(Rails.configuration.dispatcher).to have_received(:dispatch) + .with(described_class::CONVERSATION_UPDATED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true) + end + + it 'will not run conversation_updated event for empty updates' do + conversation.save! + expect(Rails.configuration.dispatcher).not_to have_received(:dispatch) + .with(described_class::CONVERSATION_UPDATED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true) + end + + it 'will not run conversation_updated event for non whitelisted keys' do + conversation.update(updated_at: DateTime.now.utc) + expect(Rails.configuration.dispatcher).not_to have_received(:dispatch) + .with(described_class::CONVERSATION_UPDATED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true) end it 'creates conversation activities' do