From e7e14f01e4e22d5cabec776cb457dc1799b52c78 Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Mon, 15 Jan 2024 15:07:36 +0530 Subject: [PATCH] fix: undefined method 'zero?' for nil:NilClass (#8689) --- app/services/action_service.rb | 6 ++++-- spec/services/action_service_spec.rb | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/services/action_service.rb b/app/services/action_service.rb index 6ef2766f8..5a38db47f 100644 --- a/app/services/action_service.rb +++ b/app/services/action_service.rb @@ -49,8 +49,10 @@ class ActionService end def assign_team(team_ids = []) - return unassign_team if team_ids[0].zero? - return unless team_belongs_to_account?(team_ids) + return unassign_team if team_ids[0]&.zero? + # check if team belongs to account only if team_id is present + # if team_id is nil, then it means that the team is being unassigned + return unless !team_ids[0].nil? && team_belongs_to_account?(team_ids) @conversation.update!(team_id: team_ids[0]) end diff --git a/spec/services/action_service_spec.rb b/spec/services/action_service_spec.rb index edae23974..bdc9c88ff 100644 --- a/spec/services/action_service_spec.rb +++ b/spec/services/action_service_spec.rb @@ -39,5 +39,10 @@ describe ActionService do action_service.assign_agent(['nil']) expect(conversation.reload.assignee).to be_nil end + + it 'unassigns the team if team_id is nil' do + action_service.assign_team([nil]) + expect(conversation.reload.team).to be_nil + end end end