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:
Selase Krakani 2022-12-01 15:04:05 +00:00 committed by GitHub
parent fca6805aca
commit 0270f9e45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -41,9 +41,9 @@ RSpec.describe PostCreator do
expect(post.wiki).to eq(true)
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]
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_at).to be_present
expect(post.hidden_reason_id).to eq(hri)
@ -52,6 +52,16 @@ RSpec.describe PostCreator do
expect(post.user.post_count).to eq(0)
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
Guardian.any_instance.expects(:can_create?).with(Topic, nil).returns(false)
expect { creator.create }.to raise_error(Discourse::InvalidAccess)