check_username api now returns correct error message for invalid lengths etc

This commit is contained in:
Neil Lalonde
2013-02-08 14:12:48 -05:00
parent 84191802df
commit ce7088f081
4 changed files with 40 additions and 21 deletions

View File

@ -484,11 +484,7 @@ describe UsersController do
it_should_behave_like 'when username is unavailable locally'
end
context 'has invalid characters' do
before do
xhr :get, :check_username, username: 'bad username'
end
shared_examples_for 'checking an invalid username' do
it 'should return success' do
response.should be_success
end
@ -501,6 +497,28 @@ describe UsersController do
::JSON.parse(response.body)['errors'].should_not be_empty
end
end
context 'has invalid characters' do
before do
xhr :get, :check_username, username: 'bad username'
end
it_should_behave_like 'checking an invalid username'
it 'should return the invalid characters message' do
::JSON.parse(response.body)['errors'].should include(I18n.t(:'user.username.characters'))
end
end
context 'is too long' do
before do
xhr :get, :check_username, username: 'abcdefghijklmnop'
end
it_should_behave_like 'checking an invalid username'
it 'should return the "too short" message' do
::JSON.parse(response.body)['errors'].should include(I18n.t(:'user.username.long', max: User.username_length.end))
end
end
end
context 'when call_mothership is enabled' do