diff --git a/app/models/concerns/smooch_messages.rb b/app/models/concerns/smooch_messages.rb index caea4ef6bd..5170a06a98 100644 --- a/app/models/concerns/smooch_messages.rb +++ b/app/models/concerns/smooch_messages.rb @@ -343,9 +343,6 @@ def save_message(message_json, app_id, author = nil, request_type = 'default_req elsif ['relevant_search_result_requests', 'timeout_search_requests'].include?(request_type) message['archived'] = (request_type == 'relevant_search_result_requests' ? self.default_archived_flag : CheckArchivedFlags::FlagCodes::UNCONFIRMED) associated = self.create_project_media_from_message(message) - if associated != associated_obj && associated.is_a?(ProjectMedia) - Relationship.create(relationship_type: Relationship.suggested_type, source: associated_obj, target: associated, user: BotUser.smooch_user) - end end return if associated.nil? diff --git a/app/models/relationship.rb b/app/models/relationship.rb index b4308a834e..efe056edea 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -19,7 +19,6 @@ class Relationship < ApplicationRecord validates :relationship_type, uniqueness: { scope: [:source_id, :target_id], message: :already_exists }, on: :create before_create :destroy_same_suggested_item, if: proc { |r| r.is_confirmed? } - before_update :destroy_other_suggested_items, if: proc { |r| r.is_confirmed? } after_create :move_to_same_project_as_main, prepend: true after_create :point_targets_to_new_source, :update_counters, prepend: true after_update :reset_counters, prepend: true @@ -315,14 +314,6 @@ def destroy_same_suggested_item .destroy_all end - def destroy_other_suggested_items - # If created by Smooch Bot, destroy other suggestions to the same media - Relationship.where(target_id: self.target_id, user: BotUser.smooch_user) - .where('relationship_type = ?', Relationship.suggested_type.to_yaml) - .where('id != ?', self.id) - .destroy_all - end - def cant_be_related_to_itself errors.add(:base, I18n.t(:item_cant_be_related_to_itself)) if self.source_id == self.target_id end diff --git a/test/models/bot/smooch_6_test.rb b/test/models/bot/smooch_6_test.rb index df46b2cbe4..ebb1622db9 100644 --- a/test/models/bot/smooch_6_test.rb +++ b/test/models/bot/smooch_6_test.rb @@ -223,7 +223,7 @@ def send_message_outside_24_hours_window(template, pm = nil) Sidekiq::Testing.inline! do send_message 'hello', '1', '1', 'Foo bar', '1' assert_state 'search_result' - assert_difference 'TiplineRequest.count + ProjectMedia.count + Relationship.where(relationship_type: Relationship.suggested_type).count', 3 do + assert_difference 'TiplineRequest.count + ProjectMedia.count', 2 do send_message '1' end assert_state 'main' @@ -240,7 +240,7 @@ def send_message_outside_24_hours_window(template, pm = nil) Sidekiq::Testing.inline! do send_message 'hello', '1', '1', 'Foo bar foo bar foo bar', '1' assert_state 'search_result' - assert_difference 'TiplineRequest.count + ProjectMedia.count + Relationship.where(relationship_type: Relationship.suggested_type).count', 3 do + assert_difference 'TiplineRequest.count + ProjectMedia.count', 2 do send_message '1' end assert_state 'main' @@ -262,12 +262,8 @@ def send_message_outside_24_hours_window(template, pm = nil) Sidekiq::Testing.inline! do send_message 'hello', '1', '1', 'Image here', '1' assert_state 'search_result' - assert_difference 'TiplineRequest.count' do - assert_difference 'ProjectMedia.count' do - assert_difference 'Relationship.where(relationship_type: Relationship.suggested_type).count' do - send_message '1' - end - end + assert_difference 'TiplineRequest.count + ProjectMedia.count', 2 do + send_message '1' end assert_state 'main' end