-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: assignee_changed callback not getting triggered during conversat…
…ion creation (#9334) The reload method in our callback was refreshing the object and hence the saved_change_to_assignee_id? Method wasn't working in the following callbacks. This impacted the listeners subscribing to the event `ASSIGNEE_CHANGE`, `TEAM_CHANGE` etc
- Loading branch information
1 parent
2af0d58
commit f6d7f3b
Showing
9 changed files
with
59 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ParticipationListener < BaseListener | ||
include Events::Types | ||
|
||
def assignee_changed(event) | ||
conversation, _account = extract_conversation_and_account(event) | ||
conversation.conversation_participants.find_or_create_by!(user_id: conversation.assignee_id) if conversation.assignee_id.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rails_helper' | ||
describe ParticipationListener do | ||
let(:listener) { described_class.instance } | ||
let!(:account) { create(:account) } | ||
let!(:admin) { create(:user, account: account, role: :administrator) } | ||
let!(:inbox) { create(:inbox, account: account) } | ||
let!(:agent) { create(:user, account: account, role: :agent) } | ||
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: agent) } | ||
|
||
before do | ||
create(:inbox_member, inbox: inbox, user: agent) | ||
Current.user = nil | ||
Current.account = nil | ||
end | ||
|
||
describe '#assignee_changed' do | ||
let(:event_name) { :assignee_changed } | ||
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation) } | ||
|
||
it 'adds the assignee as a participant to the conversation' do | ||
expect(conversation.conversation_participants.map(&:user_id)).not_to include(admin.id) | ||
listener.assignee_changed(event) | ||
expect(conversation.conversation_participants.map(&:user_id)).to include(agent.id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters