Skip to content

Commit 109f04b

Browse files
authored
Merge pull request #1882 from codidact/0valt/more-complaints-suggestions
2 parents f0fd31a + 4ebca54 commit 109f04b

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

test/controllers/posts/restore_test.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,22 @@ class PostsControllerTest < ActionController::TestCase
4444
assert_response(:found)
4545
assert_redirected_to post_path(assigns(:post))
4646
assert_not_nil flash[:danger]
47-
assert_equal before_history, after_history, 'PostHistory event incorrectly created on deletion'
47+
assert_equal before_history, after_history, 'Expected no PostHistory events to be created'
48+
end
49+
50+
test 'no one but staff should be able to restore posts deleted by staff' do
51+
deleted_by_staff = posts(:deleted_staff)
52+
53+
sign_in users(:deleter)
54+
55+
before_history = PostHistory.where(post: deleted_by_staff).count
56+
post :restore, params: { id: deleted_by_staff.id }
57+
after_history = PostHistory.where(post: deleted_by_staff).count
58+
59+
assert_response(:found)
60+
assert_redirected_to post_path(assigns(:post))
61+
assert_not_nil flash[:danger]
62+
assert_equal before_history, after_history, 'Expected no PostHistory events to be created'
4863
end
4964

5065
test 'cannot restore a restored post' do

test/fixtures/posts.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ deleted_mod:
130130
upvote_count: 0
131131
downvote_count: 0
132132

133+
deleted_staff:
134+
post_type: question
135+
title: Q4DS - This question is deleted by a staff member
136+
body: Q4DS - This question is in category main, posted by standard_user. It has been deleted by a staff member.
137+
body_markdown: Q4DS - This question is in category main, posted by standard_user. It has been deleted by a staff member.
138+
tags_cache:
139+
- support
140+
tags:
141+
- support
142+
score: 0.5
143+
user: standard_user
144+
deleted: true
145+
deleted_at: 2019-01-01T00:00:00.000000Z
146+
deleted_by: staff
147+
community: sample
148+
category: main
149+
license: cc_by_sa
150+
upvote_count: 0
151+
downvote_count: 0
152+
133153
closed:
134154
post_type: question
135155
title: Q4C - This question is closed

0 commit comments

Comments
 (0)