FIX: Check if topic is assigned before assigning again. (#25)
This commit is contained in:
parent
f45a51fa4c
commit
801b1cd48c
|
@ -50,9 +50,11 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
DiscourseEvent.on(:assign_topic) do |topic, user, assigning_user|
|
||||
DiscourseEvent.on(:assign_topic) do |topic, user, assigning_user, force|
|
||||
if force || !topic.custom_fields[TopicAssigner::ASSIGNED_TO_ID]
|
||||
TopicAssigner.new(topic, assigning_user).assign(user)
|
||||
end
|
||||
end
|
||||
|
||||
DiscourseEvent.on(:unassign_topic) do |topic, unassigning_user|
|
||||
TopicAssigner.new(topic, unassigning_user).unassign
|
||||
|
|
|
@ -83,4 +83,23 @@ describe 'integration tests' do
|
|||
DiscourseEvent.trigger(:before_staff_flag_action, args)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue