From 4445b8c3c097f456d3eedc1794b5d6a3aac384b0 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Apr 2014 00:34:55 +1000 Subject: [PATCH] Factor out mocks --- spec/controllers/users_controller_spec.rb | 33 ++++++----------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 7d25a2da36c..bd607088aa3 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -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