diff --git a/test/controllers/posts_controller_test.rb b/test/controllers/posts_controller_test.rb index e1e7f3a95ba7aeadd1b81dcc4dc66f7ad304d589..e0a7c821dee8c4cfe85e05721ee430f389b15329 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 8f0b3bce503358b0b3809e7aec18088bb6d5e600..dea8f1923fecae1422e2a244f1099156f06cd0ef 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 a207532c46a83281aed5aab8d7ec63713f5b7a81..bdea67b9f86f45b01feb236d2cea00824df523c9 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 +