disallows reserved usernames

This commit is contained in:
Rimian Perkins 2017-05-04 19:49:30 +10:00
parent bafa91f255
commit 4fe5a0462a
2 changed files with 20 additions and 11 deletions

View File

@ -15,6 +15,8 @@ module DiscourseDonations
end
if params[:username].nil?
output['messages'] << 'Please enter a username'
elsif ::User.reserved_username?(params[:username])
output['messages'] << I18n.t('login.reserved_username')
end
end

View File

@ -18,17 +18,6 @@ module DiscourseDonations
expect(response).to have_http_status(200)
end
it 'responds with a message when the email is empty' do
post :create, { create_account: 'true', email: '' }
expect(body['messages']).to include('Please enter your email address')
end
it 'responds ok when the email is empty' do
post :create, { create_account: 'true' }
expect(body['messages']).to include('Please enter your email address')
expect(response).to have_http_status(200)
end
it 'expects a username if accounts are being created' do
post :create, { email: 'zipitydoodah@example.com', create_account: 'true' }
expect(body['messages']).to include('Please enter a username')
@ -42,6 +31,24 @@ module DiscourseDonations
expect(response).to have_http_status(200)
end
describe 'new user' do
it 'has a message when the email is empty' do
post :create, { create_account: 'true', email: '' }
expect(body['messages']).to include('Please enter your email address')
end
it 'has a message when the email is empty' do
post :create, { create_account: 'true' }
expect(body['messages']).to include('Please enter your email address')
end
it 'has a message when the username is reserved' do
User.expects(:reserved_username?).returns(true)
post :create, { username: 'admin', create_account: 'true', email: 'something@example.com' }
expect(body['messages']).to include(I18n.t('login.reserved_username'))
end
end
describe 'rewards' do
let(:group_name) { 'Zasch' }
let(:badge_name) { 'Beanie' }