mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: return proper error message when replying to a closed or deleted topic
This commit is contained in:
@@ -332,7 +332,10 @@ describe PostCreator do
|
||||
|
||||
it 'ensures the user can create the post' do
|
||||
Guardian.any_instance.expects(:can_create?).with(Post, topic).returns(false)
|
||||
expect { creator.create }.to raise_error(Discourse::InvalidAccess)
|
||||
post = creator.create
|
||||
expect(post).to be_blank
|
||||
expect(creator.errors.count).to eq 1
|
||||
expect(creator.errors.messages[:base][0]).to match I18n.t(:topic_not_found)
|
||||
end
|
||||
|
||||
context 'success' do
|
||||
@@ -347,6 +350,30 @@ describe PostCreator do
|
||||
|
||||
end
|
||||
|
||||
context 'closed topic' do
|
||||
let!(:topic) { Fabricate(:topic, user: user, closed: true) }
|
||||
let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) }
|
||||
|
||||
it 'responds with an error message' do
|
||||
post = creator.create
|
||||
expect(post).to be_blank
|
||||
expect(creator.errors.count).to eq 1
|
||||
expect(creator.errors.messages[:base][0]).to match I18n.t(:topic_not_found)
|
||||
end
|
||||
end
|
||||
|
||||
context 'missing topic' do
|
||||
let!(:topic) { Fabricate(:topic, user: user, deleted_at: 5.minutes.ago) }
|
||||
let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) }
|
||||
|
||||
it 'responds with an error message' do
|
||||
post = creator.create
|
||||
expect(post).to be_blank
|
||||
expect(creator.errors.count).to eq 1
|
||||
expect(creator.errors.messages[:base][0]).to match I18n.t(:topic_not_found)
|
||||
end
|
||||
end
|
||||
|
||||
context "cooking options" do
|
||||
let(:raw) { "this is my awesome message body hello world" }
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ describe SpamRulesEnforcer do
|
||||
|
||||
Invariant { expect(Guardian.new(spammer).can_create_topic?(nil)).to be false }
|
||||
Invariant { expect{PostCreator.create(spammer, {title: 'limited time offer for you', raw: 'better buy this stuff ok', archetype_id: 1})}.to raise_error(Discourse::InvalidAccess) }
|
||||
Invariant { expect{PostCreator.create(spammer, {topic_id: another_topic.id, raw: 'my reply is spam in your topic', archetype_id: 1})}.to raise_error(Discourse::InvalidAccess) }
|
||||
Invariant { PostCreator.create(spammer, {topic_id: another_topic.id, raw: 'my reply is spam in your topic', archetype_id: 1}).should == nil }
|
||||
|
||||
Then { expect(spammer.reload).to be_blocked }
|
||||
And { expect(spam_post.reload).to be_hidden }
|
||||
|
||||
Reference in New Issue
Block a user