use translations for missing params

This commit is contained in:
Rimian Perkins 2017-05-04 20:11:26 +10:00
parent 4fe5a0462a
commit cc46445b24
2 changed files with 6 additions and 8 deletions

View File

@ -10,12 +10,10 @@ module DiscourseDonations
output = { 'messages' => [], 'rewards' => [] } output = { 'messages' => [], 'rewards' => [] }
if create_account if create_account
if (email.nil? || email.empty?) if !email.present? || params[:username].nil?
output['messages'] << 'Please enter your email address' output['messages'] << I18n.t('login.missing_user_field')
end end
if params[:username].nil? if params[:username].present? && ::User.reserved_username?(params[:username])
output['messages'] << 'Please enter a username'
elsif ::User.reserved_username?(params[:username])
output['messages'] << I18n.t('login.reserved_username') output['messages'] << I18n.t('login.reserved_username')
end end
end end

View File

@ -20,7 +20,7 @@ module DiscourseDonations
it 'expects a username if accounts are being created' do it 'expects a username if accounts are being created' do
post :create, { email: 'zipitydoodah@example.com', create_account: 'true' } post :create, { email: 'zipitydoodah@example.com', create_account: 'true' }
expect(body['messages']).to include('Please enter a username') expect(body['messages']).to include(I18n.t('login.missing_user_field'))
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
@ -34,12 +34,12 @@ module DiscourseDonations
describe 'new user' do describe 'new user' do
it 'has a message when the email is empty' do it 'has a message when the email is empty' do
post :create, { create_account: 'true', email: '' } post :create, { create_account: 'true', email: '' }
expect(body['messages']).to include('Please enter your email address') expect(body['messages']).to include(I18n.t('login.missing_user_field'))
end end
it 'has a message when the email is empty' do it 'has a message when the email is empty' do
post :create, { create_account: 'true' } post :create, { create_account: 'true' }
expect(body['messages']).to include('Please enter your email address') expect(body['messages']).to include(I18n.t('login.missing_user_field'))
end end
it 'has a message when the username is reserved' do it 'has a message when the username is reserved' do