From 4fe2ded6080d54550a8febf18d9cf3b8065ebe07 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 4 Jan 2023 07:27:23 +0800 Subject: [PATCH] DEV: Change flaky spec to provide more information when it fails (#418) This spec has been detected to be flaky by https://github.com/discourse/flaky-tests-detective which we run internally. However, I could not reproduce the flakiness after multiple attempts so I rewrote the assertions such that we set up the expectations of what `Assignment#assigned_to_id` should be before and after the triggering of the DiscourseEvent. --- spec/integration/assign_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/integration/assign_spec.rb b/spec/integration/assign_spec.rb index 8da9319..028ffed 100644 --- a/spec/integration/assign_spec.rb +++ b/spec/integration/assign_spec.rb @@ -110,14 +110,17 @@ describe "integration tests" do end it "assigns topic" do - DiscourseEvent.trigger(:assign_topic, topic, user1, admin) - expect(topic.assignment.assigned_to_id).to eq(user1.id) + expect do DiscourseEvent.trigger(:assign_topic, topic, user1, admin) end.to change { + Assignment.where(topic: topic).pluck_first(:assigned_to_id) + }.from(nil).to(user1.id) - DiscourseEvent.trigger(:assign_topic, topic, user2, admin) - expect(topic.assignment.assigned_to_id).to eq(user1.id) + expect do DiscourseEvent.trigger(:assign_topic, topic, user2, admin) end.to_not change { + Assignment.where(topic: topic).pluck_first(:assigned_to_id) + }.from(user1.id) - DiscourseEvent.trigger(:assign_topic, topic, user2, admin, true) - expect(topic.assignment.assigned_to_id).to eq(user2.id) + expect do DiscourseEvent.trigger(:assign_topic, topic, user2, admin, true) end.to change { + Assignment.where(topic: topic).pluck_first(:assigned_to_id) + }.from(user1.id).to(user2.id) end it "triggers a webhook for assigned and unassigned" do