log_in_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Log in' do
  4. include ProfileStories
  5. subject { page }
  6. let(:email) { 'test@example.com' }
  7. let(:password) { 'password' }
  8. let(:confirmed_at) { Time.zone.now }
  9. before do
  10. as_a_registered_user
  11. visit new_user_session_path
  12. end
  13. it 'A valid email and password user is able to log in' do
  14. fill_in_auth_details(email, password)
  15. expect(subject).to have_css('div.app-holder')
  16. end
  17. it 'A invalid email and password user is not able to log in' do
  18. fill_in_auth_details('invalid_email', 'invalid_password')
  19. expect(subject).to have_css('.flash-message', text: failure_message('invalid'))
  20. end
  21. context 'when confirmed at is nil' do
  22. let(:confirmed_at) { nil }
  23. it 'A unconfirmed user is able to log in' do
  24. fill_in_auth_details(email, password)
  25. expect(subject).to have_css('div.admin-wrapper')
  26. end
  27. end
  28. def failure_message(message)
  29. keys = User.authentication_keys.map { |key| User.human_attribute_name(key) }
  30. I18n.t("devise.failure.#{message}", authentication_keys: keys.join('support.array.words_connector'))
  31. end
  32. end