mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
Refactors PostsController and adds unit tests.
This commit is contained in:
parent
6c23a1903e
commit
5b9a4d3581
2 changed files with 26 additions and 2 deletions
|
@ -79,6 +79,16 @@ describe PostsController do
|
|||
let(:user) { log_in(:moderator) }
|
||||
let(:post) { Fabricate(:post, user: user, post_number: 2) }
|
||||
|
||||
it 'does not allow to destroy when edit time limit expired' do
|
||||
Guardian.any_instance.stubs(:can_delete_post?).with(post).returns(false)
|
||||
Post.any_instance.stubs(:edit_time_limit_expired?).returns(true)
|
||||
|
||||
xhr :delete, :destroy, id: post.id
|
||||
|
||||
response.status.should == 422
|
||||
JSON.parse(response.body)['errors'].should include(I18n.t('too_late_to_edit'))
|
||||
end
|
||||
|
||||
it "raises an error when the user doesn't have permission to see the post" do
|
||||
Guardian.any_instance.expects(:can_delete?).with(post).returns(false)
|
||||
xhr :delete, :destroy, id: post.id
|
||||
|
@ -195,6 +205,16 @@ describe PostsController do
|
|||
}
|
||||
end
|
||||
|
||||
it 'does not allow to update when edit time limit expired' do
|
||||
Guardian.any_instance.stubs(:can_edit?).with(post).returns(false)
|
||||
Post.any_instance.stubs(:edit_time_limit_expired?).returns(true)
|
||||
|
||||
xhr :put, :update, update_params
|
||||
|
||||
response.status.should == 422
|
||||
JSON.parse(response.body)['errors'].should include(I18n.t('too_late_to_edit'))
|
||||
end
|
||||
|
||||
it 'passes the image sizes through' do
|
||||
Post.any_instance.expects(:image_sizes=)
|
||||
xhr :put, :update, update_params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue