Skip to content

Commit

Permalink
CV2-6041: update suggested relation if new one is confirmed (#2238)
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy authored Feb 26, 2025
1 parent 46301d4 commit 0e70b5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def self.create_unless_exists(source_id, target_id, relationship_type, options =
r.update_options(options) unless r.nil?
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 @@ -198,6 +198,10 @@ def self.create_unless_exists(source_id, target_id, relationship_type, options =
exception_class = e.class.name
end
else
if r.relationship_type != relationship_type && relationship_type == Relationship.confirmed_type
r.relationship_type = relationship_type
r.save!
end
r.update_options(options)
end
if r.nil?
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 @@ -349,7 +349,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 0e70b5e

Please sign in to comment.