2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-04 08:47:37 +08:00

FIX: Don't allow other flag actions after notify_moderator has happened.

https://meta.discourse.org/t/receiving-sorry-an-error-has-occurred-during-flagging-step-of-discobot-tutorial/77233/5
This commit is contained in:
Guo Xiang Tan 2018-02-28 11:22:51 +08:00
parent e997cc7b77
commit 902c5d11cf
4 changed files with 43 additions and 16 deletions

View file

@ -44,7 +44,7 @@ describe Guardian do
end
end
describe 'post_can_act?' do
describe '#post_can_act?' do
let(:post) { build(:post) }
let(:user) { build(:user) }
@ -100,9 +100,11 @@ describe Guardian do
end
it "returns false when you already flagged a post" do
expect(Guardian.new(user).post_can_act?(post, :off_topic, opts: {
taken_actions: { PostActionType.types[:spam] => 1 }
})).to be_falsey
PostActionType.notify_flag_types.each do |type, _id|
expect(Guardian.new(user).post_can_act?(post, :off_topic, opts: {
taken_actions: { PostActionType.types[type] => 1 }
})).to be_falsey
end
end
it "returns false for notify_user if private messages are disabled" do

View file

@ -659,4 +659,30 @@ describe PostAction do
end
describe '#is_flag?' do
describe 'when post action is a flag' do
it 'should return true' do
PostActionType.notify_flag_types.each do |_type, id|
post_action = PostAction.new(
user: codinghorror,
post_action_type_id: id
)
expect(post_action.is_flag?).to eq(true)
end
end
end
describe 'when post action is not a flag' do
it 'should return false' do
post_action = PostAction.new(
user: codinghorror,
post_action_type_id: 99
)
expect(post_action.is_flag?).to eq(false)
end
end
end
end