Fixed tag merge bug.
This commit is contained in:
parent
e76422952c
commit
d662546927
2 changed files with 52 additions and 3 deletions
|
@ -211,12 +211,12 @@ rename tag items
|
|||
|
||||
def self.rename(data)
|
||||
|
||||
new_tag_name = data[:name].strip
|
||||
old_tag_item = Tag::Item.find(data[:id])
|
||||
new_tag_name = data[:name].strip
|
||||
old_tag_item = Tag::Item.find(data[:id])
|
||||
already_existing_tag = Tag::Item.lookup(name: new_tag_name)
|
||||
|
||||
# check if no remame is needed
|
||||
return true if new_tag_name.downcase == old_tag_item.name.downcase
|
||||
return true if new_tag_name == old_tag_item.name
|
||||
|
||||
# merge old with new tag if already existing
|
||||
if already_existing_tag
|
||||
|
|
|
@ -342,4 +342,53 @@ class TagTest < ActiveSupport::TestCase
|
|||
assert(tags_ticket2.include?('some rename tag2'))
|
||||
|
||||
end
|
||||
|
||||
test 'tags - rename and merge tag with existing tag' do
|
||||
|
||||
ticket1 = Ticket.create(
|
||||
title: 'rename tag1',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer_id: 2,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
ticket2 = Ticket.create(
|
||||
title: 'rename tag2',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer_id: 2,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
||||
ticket1.tag_add('tagname1', 1)
|
||||
ticket1.tag_add('tagname2', 1)
|
||||
|
||||
ticket2.tag_add('Tagname2', 1)
|
||||
|
||||
tags_ticket1 = ticket1.tag_list
|
||||
assert_equal(2, tags_ticket1.count)
|
||||
assert(tags_ticket1.include?('tagname1'))
|
||||
assert(tags_ticket1.include?('tagname2'))
|
||||
|
||||
tags_ticket2 = ticket2.tag_list
|
||||
assert_equal(1, tags_ticket2.count)
|
||||
assert(tags_ticket2.include?('Tagname2'))
|
||||
|
||||
tag_item1 = Tag::Item.lookup(name: 'Tagname2')
|
||||
Tag::Item.rename(
|
||||
id: tag_item1.id,
|
||||
name: 'tagname2',
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
||||
tags_ticket1 = ticket1.tag_list
|
||||
assert_equal(2, tags_ticket1.count)
|
||||
assert(tags_ticket1.include?('tagname1'))
|
||||
assert(tags_ticket1.include?('tagname2'))
|
||||
|
||||
tags_ticket2 = ticket2.tag_list
|
||||
assert_equal(1, tags_ticket2.count)
|
||||
assert(tags_ticket2.include?('tagname2'))
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue