log_in_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. 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 'user_email', with: email
  15. fill_in 'user_password', with: password
  16. click_on I18n.t('auth.login')
  17. expect(subject).to have_css('div.app-holder')
  18. end
  19. it 'A invalid email and password user is not able to log in' do
  20. fill_in 'user_email', with: 'invalid_email'
  21. fill_in 'user_password', with: 'invalid_password'
  22. click_on I18n.t('auth.login')
  23. expect(subject).to have_css('.flash-message', text: failure_message('invalid'))
  24. end
  25. context 'when confirmed at is nil' do
  26. let(:confirmed_at) { nil }
  27. it 'A unconfirmed user is able to log in' do
  28. fill_in 'user_email', with: email
  29. fill_in 'user_password', with: password
  30. click_on I18n.t('auth.login')
  31. expect(subject).to have_css('div.admin-wrapper')
  32. end
  33. end
  34. def failure_message(message)
  35. keys = User.authentication_keys.map { |key| User.human_attribute_name(key) }
  36. I18n.t("devise.failure.#{message}", authentication_keys: keys.join('support.array.words_connector'))
  37. end
  38. end