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