2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe PostLocker do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:moderator)
|
|
|
|
fab!(:post)
|
2018-01-25 15:38:40 -05:00
|
|
|
|
|
|
|
it "doesn't allow regular users to lock posts" do
|
|
|
|
expect { PostLocker.new(post, post.user).lock }.to raise_error(Discourse::InvalidAccess)
|
|
|
|
|
|
|
|
expect(post).not_to be_locked
|
|
|
|
expect(post.locked_by_id).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't allow regular users to unlock posts" do
|
|
|
|
PostLocker.new(post, moderator).lock
|
|
|
|
|
|
|
|
expect { PostLocker.new(post, post.user).lock }.to raise_error(Discourse::InvalidAccess)
|
|
|
|
|
|
|
|
expect(post).to be_locked
|
|
|
|
expect(post.locked_by_id).to eq(moderator.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows staff to lock and unlock posts" do
|
|
|
|
expect(post).not_to be_locked
|
|
|
|
expect(post.locked_by_id).to be_blank
|
|
|
|
|
|
|
|
PostLocker.new(post, moderator).lock
|
|
|
|
expect(post).to be_locked
|
|
|
|
expect(post.locked_by_id).to eq(moderator.id)
|
|
|
|
expect(
|
|
|
|
UserHistory.where(
|
|
|
|
acting_user_id: moderator.id,
|
|
|
|
action: UserHistory.actions[:post_locked],
|
|
|
|
).exists?,
|
|
|
|
).to eq(true)
|
|
|
|
|
|
|
|
PostLocker.new(post, moderator).unlock
|
|
|
|
expect(post).not_to be_locked
|
|
|
|
expect(post.locked_by_id).to be_blank
|
|
|
|
expect(
|
|
|
|
UserHistory.where(
|
|
|
|
acting_user_id: moderator.id,
|
|
|
|
action: UserHistory.actions[:post_unlocked],
|
|
|
|
).exists?,
|
|
|
|
).to eq(true)
|
|
|
|
end
|
|
|
|
end
|