Factor out mocks
This commit is contained in:
parent
c6d9829092
commit
4445b8c3c0
|
@ -40,38 +40,21 @@ describe UsersController do
|
|||
end
|
||||
|
||||
describe '.authorize_email' do
|
||||
context 'invalid token' do
|
||||
before do
|
||||
EmailToken.expects(:confirm).with('asdfasdf').returns(nil)
|
||||
get :authorize_email, token: 'asdfasdf'
|
||||
end
|
||||
|
||||
it 'return success' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'sets a flash error' do
|
||||
flash[:error].should be_present
|
||||
end
|
||||
it 'errors out for invalid tokens' do
|
||||
get :authorize_email, token: 'asdfasdf'
|
||||
response.should be_success
|
||||
flash[:error].should be_present
|
||||
end
|
||||
|
||||
context 'valid token' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
EmailToken.expects(:confirm).with('asdfasdf').returns(user)
|
||||
get :authorize_email, token: 'asdfasdf'
|
||||
end
|
||||
it 'authorizes with a correct token' do
|
||||
user = Fabricate(:user)
|
||||
email_token = user.email_tokens.create(email: user.email)
|
||||
|
||||
it 'returns success' do
|
||||
get :authorize_email, token: email_token.token
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it "doesn't set an error" do
|
||||
flash[:error].should be_blank
|
||||
end
|
||||
|
||||
it 'logs in as the user' do
|
||||
session[:current_user_id].should be_present
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue