Просмотр исходного кода

Follow up 2616904 - Fixes #4834 - When an update via API fails, a notification is send to the agents that the change was made

Mantas Masalskis 11 месяцев назад
Родитель
Сommit
550c123f6d

+ 2 - 2
app/models/concerns/has_transaction_dispatcher.rb

@@ -4,8 +4,8 @@ module HasTransactionDispatcher
   extend ActiveSupport::Concern
 
   included do
-    after_create  TransactionDispatcher
-    before_update TransactionDispatcher
+    after_create TransactionDispatcher
+    after_update TransactionDispatcher
   end
 
 end

+ 2 - 2
lib/transaction_dispatcher.rb

@@ -194,14 +194,14 @@ class TransactionDispatcher
   end
 
   # Used as ActiveRecord lifecycle callback on the class.
-  def self.before_update(record)
+  def self.after_update(record)
 
     # return if we run import mode
     return true if Setting.get('import_mode')
 
     # ignore certain attributes
     real_changes = {}
-    record.changes_to_save.each do |key, value|
+    record.saved_changes.each do |key, value|
       next if key == 'updated_at'
       next if key == 'article_count'
       next if key == 'create_article_type_id'

+ 4 - 4
spec/models/ticket/has_transaction_dispatcher_spec.rb

@@ -6,7 +6,7 @@ RSpec.describe 'HasTransactionDispatcher', db_strategy: :reset, type: :model do
   let(:ticket) { create(:ticket) }
   let(:agent)  { create(:agent, groups: [ticket.group]) }
 
-  describe '#before_update' do
+  describe '#after_update' do
     context 'when ticket is updated without sending required values' do
       before do
         UserInfo.current_user_id = agent.id
@@ -15,11 +15,11 @@ RSpec.describe 'HasTransactionDispatcher', db_strategy: :reset, type: :model do
         ObjectManager::Attribute.migration_execute
       end
 
-      it 'does not call the TransactionDispatcher before_update hook', :aggregate_failures do
-        allow(TransactionDispatcher).to receive(:before_update)
+      it 'does not call the TransactionDispatcher after_update hook', :aggregate_failures do
+        allow(TransactionDispatcher).to receive(:after_update)
 
         expect { ticket.update(title: 'New title', screen: 'edit') }.to raise_error(Exceptions::ApplicationModel)
-        expect(TransactionDispatcher).not_to have_received(:before_update)
+        expect(TransactionDispatcher).not_to have_received(:after_update)
       end
     end
   end