Skip to content

Commit

Permalink
CV2-6041: update suggested relation if new one is confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Feb 26, 2025
1 parent 5d38a98 commit d7dd02f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def self.create_unless_exists(source_id, target_id, relationship_type, options =
r = Relationship.where(target_id: target_id).where.not(source_id: source_id).last
return r unless r.nil?
# otherwise we should get the existing relationship based on source, target and type
r = Relationship.where(source_id: source_id, target_id: target_id).where('relationship_type = ?', relationship_type.to_yaml).last
r = Relationship.where(source_id: source_id, target_id: target_id).last
exception_message = nil
exception_class = nil
if r.nil?
Expand Down Expand Up @@ -196,6 +196,9 @@ def self.create_unless_exists(source_id, target_id, relationship_type, options =
exception_message = e.message
exception_class = e.class.name
end
elsif r.relationship_type != relationship_type && relationship_type == Relationship.confirmed_type
r.relationship_type = relationship_type
r.save!
end
if r.nil?
Rails.logger.error("[Relationship::create_unless_exists] returning nil: source_id #{source_id}, target_id #{target_id}, relationship_type #{relationship_type}.")
Expand Down
2 changes: 1 addition & 1 deletion test/models/relationship_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def setup
assert_no_difference 'Relationship.count' do
r2 = Relationship.create_unless_exists(source.id, target.id, Relationship.confirmed_type)
end
assert_nil Relationship.where(id: r.id).last
assert_equal r.id, r2.id
assert_equal Relationship.confirmed_type, r2.relationship_type
Relationship.any_instance.stubs(:save!).raises(ActiveRecord::RecordNotUnique)
target = create_project_media team: t
Expand Down

0 comments on commit d7dd02f

Please sign in to comment.