Fixed issue #186 - Related tickets are missing on ticket merge.

This commit is contained in:
Rolf Schmidt 2017-05-02 13:37:20 +02:00
parent da69501531
commit b1f65bf645
5 changed files with 67 additions and 0 deletions

View file

@ -298,6 +298,16 @@ returns
# add history to both
# reassign links to the new ticket
Link.where(
link_object_source_id: Link::Object.find_by(name: 'Ticket').id,
link_object_source_value: id,
).update_all(link_object_source_value: data[:ticket_id])
Link.where(
link_object_target_id: Link::Object.find_by(name: 'Ticket').id,
link_object_target_value: id,
).update_all(link_object_target_value: data[:ticket_id])
# link tickets
Link.add(
link_type: 'parent',

7
spec/factories/link.rb Normal file
View file

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :link do
link_type_id { Link::Type.find_by(name: 'normal').id }
link_object_source_id { Link::Object.find_by(name: 'Ticket').id }
link_object_target_id { Link::Object.find_by(name: 'Ticket').id }
end
end

11
spec/factories/ticket.rb Normal file
View file

@ -0,0 +1,11 @@
FactoryGirl.define do
factory :ticket do
title 'Test Ticket'
group { Group.lookup(name: 'Users') }
customer { FactoryGirl.create(:customer_user) }
state { Ticket::State.lookup(name: 'new') }
priority { Ticket::Priority.lookup(name: '2 normal') }
updated_by_id 1
created_by_id 1
end
end

View file

@ -18,6 +18,10 @@ FactoryGirl.define do
created_by_id 1
end
factory :customer_user, parent: :user do
role_ids { Role.signup_role_ids.sort }
end
factory :user_login_failed, parent: :user do
login_failed { (Setting.get('password_max_login_failed').to_i || 10) + 1 }
end

View file

@ -0,0 +1,35 @@
require 'rails_helper'
RSpec.describe Ticket do
describe '.merge_to' do
it 'reassigns all links to the target ticket after merge' do
source_ticket = create(:ticket)
target_ticket = create(:ticket)
important_ticket1 = create(:ticket)
important_ticket2 = create(:ticket)
important_ticket3 = create(:ticket)
create(:link, link_object_source_value: source_ticket.id, link_object_target_value: important_ticket1.id)
create(:link, link_object_source_value: source_ticket.id, link_object_target_value: important_ticket2.id)
create(:link, link_object_source_value: source_ticket.id, link_object_target_value: important_ticket3.id)
source_ticket.merge_to(
ticket_id: target_ticket.id,
user_id: 1,
)
links = Link.list(
link_object: 'Ticket',
link_object_value: target_ticket.id,
)
expected_ticket_ids = [source_ticket.id, important_ticket1.id, important_ticket2.id, important_ticket3.id ]
check_ticket_ids = links.collect { |link| link['link_object_value'] }
expect(check_ticket_ids).to match_array(expected_ticket_ids)
end
end
end