From c209be09f15bea2cd05ec8a72df1c86add3fb76c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 21 Dec 2021 02:21:47 +0100 Subject: [PATCH] DEV: Fix a flaky test (#15374) See: https://github.com/discourse/discourse/runs/4589134998?check_suite_focus=true --- spec/requests/topics_controller_spec.rb | 89 ++++++++++++++----------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 53d54da9c79..46d0ed08d3b 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1365,52 +1365,61 @@ RSpec.describe TopicsController do expect(response.status).to eq(200) end - context 'when using SiteSetting.disable_category_edit_notifications or SiteSetting.disable_tags_edit_notifications' do - shared_examples 'a topic bump suppressor' do - it "doesn't bump the topic if the setting is enabled" do - enable_setting - last_bumped_at = topic.bumped_at - expect(last_bumped_at).not_to be_nil + context "when using SiteSetting.disable_category_edit_notifications" do + it "doesn't bump the topic if the setting is enabled" do + SiteSetting.disable_category_edit_notifications = true + last_bumped_at = topic.bumped_at + expect(last_bumped_at).not_to be_nil - expect do - put "/t/#{topic.slug}/#{topic.id}.json", params: params - end.to change { topic.reload.send(attribute_to_change) }.to(expected_new_value) + expect do + put "/t/#{topic.slug}/#{topic.id}.json", params: { category_id: category.id } + end.to change { topic.reload.category_id }.to(category.id) - expect(response.status).to eq(200) - expect(topic.reload.bumped_at).to eq_time(last_bumped_at) - end - - it "bumps the topic if the setting is disabled" do - disable_setting - last_bumped_at = topic.bumped_at - expect(last_bumped_at).not_to be_nil - - expect do - put "/t/#{topic.slug}/#{topic.id}.json", params: params - end.to change { topic.reload.send(attribute_to_change) }.to(expected_new_value) - - expect(response.status).to eq(200) - expect(topic.reload.bumped_at).not_to eq_time(last_bumped_at) - end + expect(response.status).to eq(200) + expect(topic.reload.bumped_at).to eq_time(last_bumped_at) end - it_behaves_like 'a topic bump suppressor' do - let(:attribute_to_change) { :category_id } - let(:expected_new_value) { category.id } - let(:params) { { category_id: category.id } } - let(:enable_setting) { SiteSetting.disable_category_edit_notifications = true } - let(:disable_setting) { SiteSetting.disable_category_edit_notifications = false } + it "bumps the topic if the setting is disabled" do + SiteSetting.disable_category_edit_notifications = false + last_bumped_at = topic.bumped_at + expect(last_bumped_at).not_to be_nil + + expect do + put "/t/#{topic.slug}/#{topic.id}.json", params: { category_id: category.id } + end.to change { topic.reload.category_id }.to(category.id) + + expect(response.status).to eq(200) + expect(topic.reload.bumped_at).not_to eq_time(last_bumped_at) + end + end + + context "when using SiteSetting.disable_tags_edit_notifications" do + fab!(:t1) { Fabricate(:tag) } + fab!(:t2) { Fabricate(:tag) } + let(:tags) { [t1, t2] } + + it "doesn't bump the topic if the setting is enabled" do + SiteSetting.disable_tags_edit_notifications = true + last_bumped_at = topic.bumped_at + expect(last_bumped_at).not_to be_nil + + put "/t/#{topic.slug}/#{topic.id}.json", params: { tags: tags.map(&:name) } + + expect(topic.reload.tags).to match_array(tags) + expect(response.status).to eq(200) + expect(topic.reload.bumped_at).to eq_time(last_bumped_at) end - it_behaves_like 'a topic bump suppressor' do - fab!(:t1) { Fabricate(:tag) } - fab!(:t2) { Fabricate(:tag) } - let(:tags) { [t1, t2] } - let(:attribute_to_change) { :tags } - let(:expected_new_value) { tags } - let(:params) { { tags: tags.map(&:name) } } - let(:enable_setting) { SiteSetting.disable_tags_edit_notifications = true } - let(:disable_setting) { SiteSetting.disable_tags_edit_notifications = false } + it "bumps the topic if the setting is disabled" do + SiteSetting.disable_tags_edit_notifications = false + last_bumped_at = topic.bumped_at + expect(last_bumped_at).not_to be_nil + + put "/t/#{topic.slug}/#{topic.id}.json", params: { tags: tags.map(&:name) } + + expect(topic.reload.tags).to match_array(tags) + expect(response.status).to eq(200) + expect(topic.reload.bumped_at).not_to eq_time(last_bumped_at) end end