master
1require "rails_helper"
2
3describe "Logins" do
4 subject { LoginPage.new }
5 let(:error_message) { I18n.t("sessions.create.failure.invalid") }
6
7 before :each do
8 subject.visit_page
9 end
10
11 context "when an email is registered" do
12 let!(:user) { create(:user, password: "password") }
13
14 context "when the password is correct" do
15 before :each do
16 subject.login_with(email: user.email, password: "password")
17 end
18
19 it "logs the user in" do
20 expect(page).to have_content(I18n.t("logout"))
21 end
22
23 it "has no errors" do
24 expect(page).to_not have_content(error_message)
25 end
26 end
27
28 context "when the password is incorrect" do
29 before :each do
30 subject.login_with(email: user.email, password: "wrong")
31 end
32
33 it "displays an error" do
34 expect(page).to have_content(error_message)
35 end
36 end
37 end
38
39 context "when an email is not known" do
40 before :each do
41 subject.login_with(email: "test@example.com", password: "password")
42 end
43
44 it "displays an error message" do
45 expect(page).to have_content(error_message)
46 end
47 end
48
49 context "when clicking on the log out button" do
50 let(:dashboard_page) { DashboardPage.new }
51 let(:user) { create(:user, password: "password") }
52
53 it "redirects you to the home page" do
54 subject.visit_page
55 subject.login_with(email: user.email, password: "password")
56 dashboard_page.logout
57 expect(current_path).to eql(root_path)
58 end
59 end
60end