From 8d62ba7e4605f39e5d58d451793d0f64ab3d1e3e Mon Sep 17 00:00:00 2001 From: ArtOfCode- <hello@artofcode.co.uk> Date: Tue, 15 Dec 2020 14:28:39 +0000 Subject: [PATCH] Test non-public types --- test/controllers/posts_controller_test.rb | 22 ++++++++++++++++++++++ test/fixtures/post_types.yml | 15 ++++++++++++++- test/fixtures/posts.yml | 19 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/test/controllers/posts_controller_test.rb b/test/controllers/posts_controller_test.rb index e1e7f3a95..e0a7c821d 100644 --- a/test/controllers/posts_controller_test.rb +++ b/test/controllers/posts_controller_test.rb @@ -289,6 +289,28 @@ class PostsControllerTest < ActionController::TestCase assert_response 401 end + test 'cannot edit non-public post without permissions' do + sign_in users(:standard_user) + get :edit, params: { id: posts(:blog_post).id } + assert_response 302 + assert_redirected_to root_path + assert_not_nil flash[:danger] + end + + test 'author can edit non-public post' do + sign_in users(:closer) + get :edit, params: { id: posts(:blog_post).id } + assert_response 200 + assert_not_nil assigns(:post) + end + + test 'moderator can edit non-public post' do + sign_in users(:moderator) + get :edit, params: { id: posts(:blog_post).id } + assert_response 200 + assert_not_nil assigns(:post) + end + # Update test 'can update post' do diff --git a/test/fixtures/post_types.yml b/test/fixtures/post_types.yml index 8f0b3bce5..dea8f1923 100644 --- a/test/fixtures/post_types.yml +++ b/test/fixtures/post_types.yml @@ -61,4 +61,17 @@ help_doc: has_license: false is_public_editable: false is_closeable: false - is_top_level: false \ No newline at end of file + is_top_level: false + +blog_post: + name: BlogPost + description: ~ + has_answers: false + has_votes: true + has_tags: true + has_parent: false + has_category: true + has_license: true + is_public_editable: false + is_closeable: false + is_top_level: true \ No newline at end of file diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml index a207532c4..bdea67b9f 100644 --- a/test/fixtures/posts.yml +++ b/test/fixtures/posts.yml @@ -312,3 +312,22 @@ disabled_help_article: help_category: $Disabled help_ordering: 99 doc_slug: sample-disable + +blog_post: + post_type: blog_post + title: B1 ABCDEF GHIJKL MNOPQR STUVWX YZ + body: ABCDEF GHIJKL MNOPQR STUVWX YZ ABCDEF GHIJKL MNOPQR STUVWX YZ + body_markdown: ABCDEF GHIJKL MNOPQR STUVWX YZ ABCDEF GHIJKL MNOPQR STUVWX YZ + tags_cache: + - discussion + - support + - bug + tags: + - discussion + - support + - bug + user: closer + community: sample + category: main + license: cc_by_sa + -- GitLab