about summary refs log tree commit diff
path: root/spec/features/log_in_spec.rb
blob: f6c26cd0f13b869dfb1ecc3e4a0bb662c0b59fee (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "rails_helper"

feature "Log in" do
  given(:email)        { "test@examle.com" }
  given(:password)     { "password" }
  given(:confirmed_at) { Time.zone.now }

  background do
    Fabricate(:user, email: email, password: password, confirmed_at: confirmed_at)
    visit new_user_session_path
  end

  subject { page }

  scenario "A valid email and password user is able to log in" do
    fill_in "user_email", with: email
    fill_in "user_password", with: password
    click_on I18n.t('auth.login')

    is_expected.to have_css("div.app-holder")
  end

  scenario "A invalid email and password user is not able to log in" do
    fill_in "user_email", with: "invalid_email"
    fill_in "user_password", with: "invalid_password"
    click_on I18n.t('auth.login')

    is_expected.to have_css(".flash-message", text: failure_message("invalid"))
  end

  context do
    given(:confirmed_at) { nil }

    scenario "A unconfirmed user is able to log in" do
      fill_in "user_email", with: email
      fill_in "user_password", with: password
      click_on I18n.t('auth.login')

      is_expected.to have_css("div.admin-wrapper")
    end
  end

  def failure_message(message)
    keys = User.authentication_keys.map { |key| User.human_attribute_name(key) }
    I18n.t("devise.failure.#{message}", authentication_keys: keys.join("support.array.words_connector"))
  end
end