mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Observe unlisted topic creation restrictions in post creator specs (#19283)
Update failing spec which previously used non-staff user to create hidden posts. Also add new spec for non-staff use cases to prevent future regressions.
This commit is contained in:
parent
fca6805aca
commit
0270f9e45b
@ -41,9 +41,9 @@ RSpec.describe PostCreator do
|
|||||||
expect(post.wiki).to eq(true)
|
expect(post.wiki).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can be created with a hidden reason" do
|
it "creates post with a hidden reason for staff user" do
|
||||||
hri = Post.hidden_reasons[:flag_threshold_reached]
|
hri = Post.hidden_reasons[:flag_threshold_reached]
|
||||||
post = PostCreator.create(user, basic_topic_params.merge(hidden_reason_id: hri))
|
post = PostCreator.create(admin, basic_topic_params.merge(hidden_reason_id: hri))
|
||||||
expect(post.hidden).to eq(true)
|
expect(post.hidden).to eq(true)
|
||||||
expect(post.hidden_at).to be_present
|
expect(post.hidden_at).to be_present
|
||||||
expect(post.hidden_reason_id).to eq(hri)
|
expect(post.hidden_reason_id).to eq(hri)
|
||||||
@ -52,6 +52,16 @@ RSpec.describe PostCreator do
|
|||||||
expect(post.user.post_count).to eq(0)
|
expect(post.user.post_count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "fails to create post with a hidden reason for non-staff user" do
|
||||||
|
hri = Post.hidden_reasons[:flag_threshold_reached]
|
||||||
|
|
||||||
|
expect do
|
||||||
|
post = PostCreator.create(user, basic_topic_params.merge(hidden_reason_id: hri))
|
||||||
|
|
||||||
|
expect(post).to be_nil
|
||||||
|
end.not_to change { Post.count }
|
||||||
|
end
|
||||||
|
|
||||||
it "ensures the user can create the topic" do
|
it "ensures the user can create the topic" do
|
||||||
Guardian.any_instance.expects(:can_create?).with(Topic, nil).returns(false)
|
Guardian.any_instance.expects(:can_create?).with(Topic, nil).returns(false)
|
||||||
expect { creator.create }.to raise_error(Discourse::InvalidAccess)
|
expect { creator.create }.to raise_error(Discourse::InvalidAccess)
|
||||||
|
Loading…
Reference in New Issue
Block a user