From 35935fb7266add358225dbbb08fb80ffaf11f98d Mon Sep 17 00:00:00 2001 From: Aditya Prakash Date: Thu, 7 Apr 2016 17:22:10 +0530 Subject: [PATCH] Add devise confirmation controller test --- .../confirmations_controller_spec.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/controllers/confirmations_controller_spec.rb diff --git a/spec/controllers/confirmations_controller_spec.rb b/spec/controllers/confirmations_controller_spec.rb new file mode 100644 index 00000000..1db675b3 --- /dev/null +++ b/spec/controllers/confirmations_controller_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe ConfirmationsController do + let(:user) { create(:user, confirmed_at: nil) } + + before do + @request.env['devise.mapping'] = Devise.mappings[:user] + end + + context 'user is not signed in' do + it 'confirms and signs in user' do + get :show, confirmation_token: user.confirmation_token + user.reload + expect(user.confirmed?).to eq true + expect(controller.current_user).to eq user + end + end + + context 'user is signed in' do + before { sign_in user } + + it 'confirms user' do + get :show, confirmation_token: user.confirmation_token + user.reload + expect(user.confirmed?).to eq true + end + end +end