about summary refs log tree commit diff
path: root/spec/controllers/auth/sessions_controller_spec.rb
blob: c2a1fbe9100750ff232fb9d96633dec345dabd3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'rails_helper'

RSpec.describe Auth::SessionsController, type: :controller do
  render_views

  describe 'GET #new' do
    before do
      request.env["devise.mapping"] = Devise.mappings[:user]
    end

    it 'returns http success' do
      get :new
      expect(response).to have_http_status(:success)
    end
  end

  describe 'POST #create' do
    let(:user) { Fabricate(:user, email: 'foo@bar.com', password: 'abcdefgh') }

    before do
      request.env["devise.mapping"] = Devise.mappings[:user]
      post :create, params: { user: { email: user.email, password: user.password } }
    end

    it 'redirects to home' do
      expect(response).to redirect_to(root_path)
    end

    it 'logs the user in' do
      expect(controller.current_user).to eq user
    end
  end
end