summaryrefslogtreecommitdiff
path: root/spec/features/login_spec.rb
blob: 3eb9ad4b02991f4de02e4c40629d15a9cd5a414b (plain)
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
require 'rails_helper'

describe "the signin process", type: :feature do
  let!(:user) { create(:user, password: 'password') }
  let(:login_page) { LoginPage.new }

  context "when the credentials are correct" do
    it 'signs the user in' do
      login_page.login_with(email: user.email, password: 'password')
      expect(page).to have_content("Dashboard")
      expect(current_path).to eql(root_path)
    end
  end

  context "when the password is incorrect" do
    it 'displays an error' do
      login_page.login_with(email: user.email, password: 'wrong')
      expect(page).to have_content(I18n.translate(:invalid_credentials))
      expect(current_path).to eql(new_session_path)
    end
  end

  context "when the email is unknown" do
    it 'displays an error' do
      login_page.login_with(email: 'test@example.com', password: 'password')
      expect(page).to have_content(I18n.translate(:invalid_credentials))
      expect(current_path).to eql(new_session_path)
    end
  end
end