Jarek Radosz 2021-12-21 02:21:47 +01:00 committed by GitHub
parent 76498db7e5
commit c209be09f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 40 deletions

View File

@ -1365,52 +1365,61 @@ RSpec.describe TopicsController do
expect(response.status).to eq(200) expect(response.status).to eq(200)
end end
context 'when using SiteSetting.disable_category_edit_notifications or SiteSetting.disable_tags_edit_notifications' do context "when using SiteSetting.disable_category_edit_notifications" do
shared_examples 'a topic bump suppressor' do it "doesn't bump the topic if the setting is enabled" do
it "doesn't bump the topic if the setting is enabled" do SiteSetting.disable_category_edit_notifications = true
enable_setting last_bumped_at = topic.bumped_at
last_bumped_at = topic.bumped_at expect(last_bumped_at).not_to be_nil
expect(last_bumped_at).not_to be_nil
expect do expect do
put "/t/#{topic.slug}/#{topic.id}.json", params: params put "/t/#{topic.slug}/#{topic.id}.json", params: { category_id: category.id }
end.to change { topic.reload.send(attribute_to_change) }.to(expected_new_value) end.to change { topic.reload.category_id }.to(category.id)
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(topic.reload.bumped_at).to eq_time(last_bumped_at) 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
end end
it_behaves_like 'a topic bump suppressor' do it "bumps the topic if the setting is disabled" do
let(:attribute_to_change) { :category_id } SiteSetting.disable_category_edit_notifications = false
let(:expected_new_value) { category.id } last_bumped_at = topic.bumped_at
let(:params) { { category_id: category.id } } expect(last_bumped_at).not_to be_nil
let(:enable_setting) { SiteSetting.disable_category_edit_notifications = true }
let(:disable_setting) { SiteSetting.disable_category_edit_notifications = false } 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 end
it_behaves_like 'a topic bump suppressor' do it "bumps the topic if the setting is disabled" do
fab!(:t1) { Fabricate(:tag) } SiteSetting.disable_tags_edit_notifications = false
fab!(:t2) { Fabricate(:tag) } last_bumped_at = topic.bumped_at
let(:tags) { [t1, t2] } expect(last_bumped_at).not_to be_nil
let(:attribute_to_change) { :tags }
let(:expected_new_value) { tags } put "/t/#{topic.slug}/#{topic.id}.json", params: { tags: tags.map(&:name) }
let(:params) { { tags: tags.map(&:name) } }
let(:enable_setting) { SiteSetting.disable_tags_edit_notifications = true } expect(topic.reload.tags).to match_array(tags)
let(:disable_setting) { SiteSetting.disable_tags_edit_notifications = false } expect(response.status).to eq(200)
expect(topic.reload.bumped_at).not_to eq_time(last_bumped_at)
end end
end end