main
 1require "rails_helper"
 2
 3describe ApplicationController do
 4  controller do
 5    def index
 6      current_user
 7      render text: 'hello'
 8    end
 9  end
10
11  context "when signed in" do
12    let(:user) { create(:user, password: 'password', password_confirmation: 'password') }
13    let(:user_session) { create(:session, user: user) }
14
15    before { cookies.signed[:raphael] = user_session.key }
16    before { get :index }
17
18    it "lets you continue to do whatever the heck you were trying to do" do
19      expect(response.status).to eql(200)
20    end
21
22    it "loads the current user" do
23      expect(assigns(:current_user)).to eql(user)
24    end
25  end
26
27  context "when not signed in" do
28    before :each do
29      cookies.signed[:raphael] = SecureRandom.uuid
30      get :index
31    end
32
33    it "boots you out when their is no session_id" do
34      expect(response).to redirect_to(new_session_path)
35    end
36
37    it "boots you out when the session id is not known" do
38      expect(response).to redirect_to(new_session_path)
39    end
40  end
41end