FEATURE: Add "Reset Bump Date" action to topic admin wrench (#6246)

This commit is contained in:
Gerhard Schlager
2018-08-10 02:51:03 +02:00
committed by Sam
parent 6db623ef6b
commit b9072e8292
12 changed files with 113 additions and 1 deletions

View File

@@ -2296,4 +2296,27 @@ describe Topic do
end
end
end
describe "#reset_bumped_at" do
it "ignores hidden and deleted posts when resetting the topic's bump date" do
post = create_post(created_at: 10.hours.ago)
topic = post.topic
expect { topic.reset_bumped_at }.to_not change { topic.bumped_at }
post = Fabricate(:post, topic: topic, post_number: 2, created_at: 9.hours.ago)
Fabricate(:post, topic: topic, post_number: 3, created_at: 8.hours.ago, deleted_at: 1.hour.ago)
Fabricate(:post, topic: topic, post_number: 4, created_at: 7.hours.ago, hidden: true)
Fabricate(:post, topic: topic, post_number: 5, created_at: 6.hours.ago, user_deleted: true)
Fabricate(:post, topic: topic, post_number: 6, created_at: 5.hours.ago, post_type: Post.types[:whisper])
expect { topic.reset_bumped_at }.to change { topic.bumped_at }.to(post.reload.created_at)
post = Fabricate(:post, topic: topic, post_number: 7, created_at: 4.hours.ago, post_type: Post.types[:moderator_action])
expect { topic.reset_bumped_at }.to change { topic.bumped_at }.to(post.reload.created_at)
post = Fabricate(:post, topic: topic, post_number: 8, created_at: 3.hours.ago, post_type: Post.types[:small_action])
expect { topic.reset_bumped_at }.to change { topic.bumped_at }.to(post.reload.created_at)
end
end
end

View File

@@ -2266,4 +2266,41 @@ RSpec.describe TopicsController do
end
describe "#reset_bump_date" do
context "errors" do
let(:topic) { Fabricate(:topic) }
it "needs you to be logged in" do
put "/t/#{topic.id}/reset-bump-date.json"
expect(response.status).to eq(403)
end
[:user, :trust_level_4].each do |user|
it "denies access for #{user}" do
sign_in(Fabricate(user))
put "/t/#{topic.id}/reset-bump-date.json"
expect(response.status).to eq(403)
end
end
it "should fail for non-existend topic" do
sign_in(Fabricate(:admin))
put "/t/1/reset-bump-date.json"
expect(response.status).to eq(404)
end
end
[:admin, :moderator].each do |user|
it "should reset bumped_at as #{user}" do
sign_in(Fabricate(user))
topic = Fabricate(:topic, bumped_at: 1.hour.ago)
timestamp = 1.day.ago
Fabricate(:post, topic: topic, created_at: timestamp)
put "/t/#{topic.id}/reset-bump-date.json"
expect(response.status).to eq(200)
expect(topic.reload.bumped_at).to be_within_one_second_of(timestamp)
end
end
end
end