FIX: Check if topic is assigned before assigning again. (#25)

This commit is contained in:
Bianca Nenciu 2019-03-15 19:49:22 +02:00 committed by Régis Hanol
parent f45a51fa4c
commit 801b1cd48c
2 changed files with 23 additions and 2 deletions

View File

@ -50,8 +50,10 @@ after_initialize do
end end
end end
DiscourseEvent.on(:assign_topic) do |topic, user, assigning_user| DiscourseEvent.on(:assign_topic) do |topic, user, assigning_user, force|
TopicAssigner.new(topic, assigning_user).assign(user) if force || !topic.custom_fields[TopicAssigner::ASSIGNED_TO_ID]
TopicAssigner.new(topic, assigning_user).assign(user)
end
end end
DiscourseEvent.on(:unassign_topic) do |topic, unassigning_user| DiscourseEvent.on(:unassign_topic) do |topic, unassigning_user|

View File

@ -83,4 +83,23 @@ describe 'integration tests' do
DiscourseEvent.trigger(:before_staff_flag_action, args) DiscourseEvent.trigger(:before_staff_flag_action, args)
end end
end end
describe "on assign_topic event" do
let(:post) { Fabricate(:post) }
let(:topic) { post.topic }
let(:admin) { Fabricate(:admin) }
let(:user1) { Fabricate(:user) }
let(:user2) { Fabricate(:user) }
it "assigns topic" do
DiscourseEvent.trigger(:assign_topic, topic, user1, admin)
expect(topic.reload.custom_fields[TopicAssigner::ASSIGNED_TO_ID].to_i).to eq(user1.id)
DiscourseEvent.trigger(:assign_topic, topic, user2, admin)
expect(topic.reload.custom_fields[TopicAssigner::ASSIGNED_TO_ID].to_i).to eq(user1.id)
DiscourseEvent.trigger(:assign_topic, topic, user2, admin, true)
expect(topic.reload.custom_fields[TopicAssigner::ASSIGNED_TO_ID].to_i).to eq(user2.id)
end
end
end end