From 5cd08b3f98d28117c244ec4fc56df4c9ec321d9d Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 2 Oct 2020 03:11:23 +0800 Subject: [PATCH] chore: self-assign conversation activity message (#1293) --- app/models/conversation.rb | 1 + config/locales/en.yml | 1 + spec/models/conversation_spec.rb | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 5d5747a09..32bcb4083 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -210,6 +210,7 @@ class Conversation < ApplicationRecord def create_assignee_change(user_name) params = { assignee_name: assignee&.available_name, user_name: user_name }.compact key = assignee_id ? 'assigned' : 'removed' + key = 'self_assigned' if self_assign? assignee_id content = I18n.t("conversations.activity.assignee.#{key}", **params) messages.create(activity_message_params(content)) diff --git a/config/locales/en.yml b/config/locales/en.yml index e6f65e32d..56f1649b8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,6 +48,7 @@ en: resolved: "Conversation was marked resolved by %{user_name}" open: "Conversation was reopened by %{user_name}" assignee: + self_assigned: "%{user_name} self-assigned this conversation" assigned: "Assigned to %{assignee_name} by %{user_name}" removed: "Conversation unassigned by %{user_name}" templates: diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 4ec6717c8..f06105067 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -182,6 +182,17 @@ RSpec.describe Conversation, type: :model do expect(update_assignee).to eq(true) expect(agent.notifications.count).to eq(0) end + + context 'when agent is current user' do + before do + Current.user = agent + end + + it 'creates self-assigned message activity' do + expect(update_assignee).to eq(true) + expect(conversation.messages.pluck(:content)).to include("#{agent.available_name} self-assigned this conversation") + end + end end describe '#toggle_status' do