Minor spec clean-up

This commit is contained in:
Neil Lalonde 2013-06-28 14:43:35 -04:00
parent 2deaf8ef98
commit b37b6ce664

View File

@ -409,7 +409,7 @@ describe UsersController do
end end
end end
shared_examples_for 'honeypot fails' do shared_examples 'honeypot fails' do
it 'should not create a new user' do it 'should not create a new user' do
expect { expect {
xhr :post, :create, create_params xhr :post, :create, create_params
@ -433,7 +433,7 @@ describe UsersController do
UsersController.any_instance.stubs(:honeypot_value).returns('abc') UsersController.any_instance.stubs(:honeypot_value).returns('abc')
end end
let(:create_params) { {name: @user.name, username: @user.username, password: "strongpassword", email: @user.email, password_confirmation: 'wrong'} } let(:create_params) { {name: @user.name, username: @user.username, password: "strongpassword", email: @user.email, password_confirmation: 'wrong'} }
it_should_behave_like 'honeypot fails' include_examples 'honeypot fails'
end end
context 'when challenge answer is wrong' do context 'when challenge answer is wrong' do
@ -441,7 +441,7 @@ describe UsersController do
UsersController.any_instance.stubs(:challenge_value).returns('abc') UsersController.any_instance.stubs(:challenge_value).returns('abc')
end end
let(:create_params) { {name: @user.name, username: @user.username, password: "strongpassword", email: @user.email, challenge: 'abc'} } let(:create_params) { {name: @user.name, username: @user.username, password: "strongpassword", email: @user.email, challenge: 'abc'} }
it_should_behave_like 'honeypot fails' include_examples 'honeypot fails'
end end
context "when 'invite only' setting is enabled" do context "when 'invite only' setting is enabled" do
@ -454,10 +454,10 @@ describe UsersController do
email: @user.email email: @user.email
}} }}
it_should_behave_like 'honeypot fails' include_examples 'honeypot fails'
end end
shared_examples_for 'failed signup' do shared_examples 'failed signup' do
it 'should not create a new User' do it 'should not create a new User' do
expect { xhr :post, :create, create_params }.to_not change { User.count } expect { xhr :post, :create, create_params }.to_not change { User.count }
end end
@ -471,12 +471,12 @@ describe UsersController do
context 'when password is blank' do context 'when password is blank' do
let(:create_params) { {name: @user.name, username: @user.username, password: "", email: @user.email} } let(:create_params) { {name: @user.name, username: @user.username, password: "", email: @user.email} }
it_should_behave_like 'failed signup' include_examples 'failed signup'
end end
context 'when password param is missing' do context 'when password param is missing' do
let(:create_params) { {name: @user.name, username: @user.username, email: @user.email} } let(:create_params) { {name: @user.name, username: @user.username, email: @user.email} }
it_should_behave_like 'failed signup' include_examples 'failed signup'
end end
context 'when an Exception is raised' do context 'when an Exception is raised' do
@ -491,7 +491,7 @@ describe UsersController do
password: "strongpassword", email: @user.email} password: "strongpassword", email: @user.email}
} }
it_should_behave_like 'failed signup' include_examples 'failed signup'
end end
end end
@ -539,7 +539,7 @@ describe UsersController do
lambda { xhr :get, :check_username }.should raise_error(ActionController::ParameterMissing) lambda { xhr :get, :check_username }.should raise_error(ActionController::ParameterMissing)
end end
shared_examples_for 'when username is unavailable locally' do shared_examples 'when username is unavailable locally' do
it 'should return success' do it 'should return success' do
response.should be_success response.should be_success
end end
@ -553,7 +553,7 @@ describe UsersController do
end end
end end
shared_examples_for 'when username is available everywhere' do shared_examples 'when username is available everywhere' do
it 'should return success' do it 'should return success' do
response.should be_success response.should be_success
end end
@ -574,14 +574,14 @@ describe UsersController do
before do before do
xhr :get, :check_username, username: 'BruceWayne' xhr :get, :check_username, username: 'BruceWayne'
end end
it_should_behave_like 'when username is available everywhere' include_examples 'when username is available everywhere'
end end
context 'available locally but not globally' do context 'available locally but not globally' do
before do before do
xhr :get, :check_username, username: 'BruceWayne' xhr :get, :check_username, username: 'BruceWayne'
end end
it_should_behave_like 'when username is available everywhere' include_examples 'when username is available everywhere'
end end
context 'unavailable locally but available globally' do context 'unavailable locally but available globally' do
@ -589,7 +589,7 @@ describe UsersController do
before do before do
xhr :get, :check_username, username: user.username xhr :get, :check_username, username: user.username
end end
it_should_behave_like 'when username is unavailable locally' include_examples 'when username is unavailable locally'
end end
context 'unavailable everywhere' do context 'unavailable everywhere' do
@ -597,10 +597,10 @@ describe UsersController do
before do before do
xhr :get, :check_username, username: user.username xhr :get, :check_username, username: user.username
end end
it_should_behave_like 'when username is unavailable locally' include_examples 'when username is unavailable locally'
end end
shared_examples_for 'checking an invalid username' do shared_examples 'checking an invalid username' do
it 'should return success' do it 'should return success' do
response.should be_success response.should be_success
end end
@ -618,7 +618,7 @@ describe UsersController do
before do before do
xhr :get, :check_username, username: 'bad username' xhr :get, :check_username, username: 'bad username'
end end
it_should_behave_like 'checking an invalid username' include_examples 'checking an invalid username'
it 'should return the invalid characters message' do it 'should return the invalid characters message' do
::JSON.parse(response.body)['errors'].should include(I18n.t(:'user.username.characters')) ::JSON.parse(response.body)['errors'].should include(I18n.t(:'user.username.characters'))
@ -629,7 +629,7 @@ describe UsersController do
before do before do
xhr :get, :check_username, username: 'abcdefghijklmnop' xhr :get, :check_username, username: 'abcdefghijklmnop'
end end
it_should_behave_like 'checking an invalid username' include_examples 'checking an invalid username'
it 'should return the "too short" message' do 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)) ::JSON.parse(response.body)['errors'].should include(I18n.t(:'user.username.long', max: User.username_length.end))
@ -648,7 +648,7 @@ describe UsersController do
DiscourseHub.stubs(:nickname_match?).returns([false, true, nil]) # match = false, available = true, suggestion = nil DiscourseHub.stubs(:nickname_match?).returns([false, true, nil]) # match = false, available = true, suggestion = nil
end end
shared_examples_for 'check_username when nickname is available everywhere' do shared_examples 'check_username when nickname is available everywhere' do
it 'should return success' do it 'should return success' do
response.should be_success response.should be_success
end end
@ -666,18 +666,18 @@ describe UsersController do
before do before do
xhr :get, :check_username, username: 'BruceWayne' xhr :get, :check_username, username: 'BruceWayne'
end end
it_should_behave_like 'check_username when nickname is available everywhere' include_examples 'check_username when nickname is available everywhere'
end end
context 'and email is given' do context 'and email is given' do
before do before do
xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@gmail.com' xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@gmail.com'
end end
it_should_behave_like 'check_username when nickname is available everywhere' include_examples 'check_username when nickname is available everywhere'
end end
end end
shared_examples_for 'when email is needed to check nickname match' do shared_examples 'when email is needed to check nickname match' do
it 'should return success' do it 'should return success' do
response.should be_success response.should be_success
end end
@ -700,14 +700,14 @@ describe UsersController do
before do before do
xhr :get, :check_username, username: 'BruceWayne' xhr :get, :check_username, username: 'BruceWayne'
end end
it_should_behave_like 'when email is needed to check nickname match' include_examples 'when email is needed to check nickname match'
end end
context 'email param is an empty string' do context 'email param is an empty string' do
before do before do
xhr :get, :check_username, username: 'BruceWayne', email: '' xhr :get, :check_username, username: 'BruceWayne', email: ''
end end
it_should_behave_like 'when email is needed to check nickname match' include_examples 'when email is needed to check nickname match'
end end
context 'email matches global nickname' do context 'email matches global nickname' do
@ -715,7 +715,7 @@ describe UsersController do
DiscourseHub.stubs(:nickname_match?).returns([true, false, nil]) DiscourseHub.stubs(:nickname_match?).returns([true, false, nil])
xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com' xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com'
end end
it_should_behave_like 'when username is available everywhere' include_examples 'when username is available everywhere'
it 'should indicate a global match' do it 'should indicate a global match' do
::JSON.parse(response.body)['global_match'].should be_true ::JSON.parse(response.body)['global_match'].should be_true
@ -727,7 +727,7 @@ describe UsersController do
DiscourseHub.stubs(:nickname_match?).returns([false, false, 'suggestion']) DiscourseHub.stubs(:nickname_match?).returns([false, false, 'suggestion'])
xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com' xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com'
end end
it_should_behave_like 'when username is unavailable locally' include_examples 'when username is unavailable locally'
it 'should not indicate a global match' do it 'should not indicate a global match' do
::JSON.parse(response.body)['global_match'].should be_false ::JSON.parse(response.body)['global_match'].should be_false
@ -743,7 +743,7 @@ describe UsersController do
xhr :get, :check_username, username: user.username xhr :get, :check_username, username: user.username
end end
it_should_behave_like 'when username is unavailable locally' include_examples 'when username is unavailable locally'
end end
context 'unavailable locally and available globally' do context 'unavailable locally and available globally' do
@ -754,7 +754,7 @@ describe UsersController do
xhr :get, :check_username, username: user.username xhr :get, :check_username, username: user.username
end end
it_should_behave_like 'when username is unavailable locally' include_examples 'when username is unavailable locally'
end end
end end