Fixed issue #1086 - Tag Bug - deleted without changes.

This commit is contained in:
Martin Edenhofer 2017-05-16 23:12:25 +02:00
parent 54d4a87ead
commit 2e062693ea
2 changed files with 64 additions and 13 deletions

View file

@ -215,6 +215,9 @@ rename tag items
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
# merge old with new tag if already existing
if already_existing_tag
@ -245,22 +248,21 @@ rename tag items
# delete not longer used tag
old_tag_item.destroy
return true
end
# update new tag name
else
old_tag_item.name = new_tag_name
old_tag_item.save
old_tag_item.name = new_tag_name
old_tag_item.save
# touch reference objects
Tag.where(tag_item_id: old_tag_item.id).each { |tag|
tag_object = Tag::Object.lookup(id: tag.tag_object_id)
Tag.touch_reference_by_params(
object: tag_object.name,
o_id: tag.o_id,
)
}
end
# touch reference objects
Tag.where(tag_item_id: old_tag_item.id).each { |tag|
tag_object = Tag::Object.lookup(id: tag.tag_object_id)
Tag.touch_reference_by_params(
object: tag_object.name,
o_id: tag.o_id,
)
}
true
end

View file

@ -293,4 +293,53 @@ class TagTest < ActiveSupport::TestCase
assert_not_equal(ticket2_lookup4.updated_at.to_s, ticket2_lookup3.updated_at.to_s)
travel_back
end
test 'tags - rename tag with same name' 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('some rename tag1', 1)
ticket1.tag_add('some rename tag2 ', 1)
ticket2.tag_add('some rename tag2', 1)
tags_ticket1 = ticket1.tag_list
assert_equal(2, tags_ticket1.count)
assert(tags_ticket1.include?('some rename tag1'))
assert(tags_ticket1.include?('some rename tag2'))
tags_ticket2 = ticket2.tag_list
assert_equal(1, tags_ticket2.count)
assert(tags_ticket2.include?('some rename tag2'))
tag_item1 = Tag::Item.find_by(name: 'some rename tag1')
Tag::Item.rename(
id: tag_item1.id,
name: ' some rename tag1',
created_by_id: 1,
)
tags_ticket1 = ticket1.tag_list
assert_equal(2, tags_ticket1.count)
assert(tags_ticket1.include?('some rename tag1'))
assert(tags_ticket1.include?('some rename tag2'))
tags_ticket2 = ticket2.tag_list
assert_equal(1, tags_ticket2.count)
assert(tags_ticket2.include?('some rename tag2'))
end
end