mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Users who have made no more than one post can delete their own accounts from their user preferences page.
This commit is contained in:
@ -1233,4 +1233,35 @@ describe UsersController do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '.destroy' do
|
||||
it 'raises an error when not logged in' do
|
||||
lambda { xhr :delete, :destroy, username: 'nobody' }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
context 'while logged in' do
|
||||
let!(:user) { log_in }
|
||||
|
||||
it 'raises an error when you cannot delete your account' do
|
||||
Guardian.any_instance.stubs(:can_delete_user?).returns(false)
|
||||
UserDestroyer.any_instance.expects(:destroy).never
|
||||
xhr :delete, :destroy, username: user.username
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "raises an error when you try to delete someone else's account" do
|
||||
UserDestroyer.any_instance.expects(:destroy).never
|
||||
xhr :delete, :destroy, username: Fabricate(:user).username
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "deletes your account when you're allowed to" do
|
||||
Guardian.any_instance.stubs(:can_delete_user?).returns(true)
|
||||
UserDestroyer.any_instance.expects(:destroy).with(user, anything).returns(user)
|
||||
xhr :delete, :destroy, username: user.username
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user