2015-07-10 00:19:01 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ApplicationController, type: :controller do
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:user_session) { create(:user_session, user: user) }
|
|
|
|
|
|
|
|
describe '#logged_in?' do
|
|
|
|
context 'when logged in' do
|
|
|
|
before(:each) { request.cookies['user_session'] = user_session.key }
|
|
|
|
|
|
|
|
it 'should return true' do
|
|
|
|
expect(controller.send(:logged_in?)).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not logged in' do
|
|
|
|
it 'should return false' do
|
|
|
|
expect(controller.send(:logged_in?)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#current_user' do
|
|
|
|
context 'when logged in' do
|
|
|
|
before(:each) { request.cookies['user_session'] = user_session.key }
|
|
|
|
|
|
|
|
it 'should return the current user' do
|
|
|
|
expect(controller.send(:current_user)).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not logged in' do
|
|
|
|
it 'should return nil' do
|
2015-12-14 13:28:39 -05:00
|
|
|
expect(controller.send(:current_user)).to be_a(GuestUser)
|
2015-07-10 00:19:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#current_session' do
|
|
|
|
context 'when logged in' do
|
|
|
|
before(:each) { request.cookies['user_session'] = user_session.key }
|
|
|
|
|
|
|
|
it 'should return the curren session' do
|
|
|
|
expect(controller.send(:current_session)).to eq(user_session)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not logged in' do
|
|
|
|
it 'should return nil' do
|
|
|
|
expect(controller.send(:current_session)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|