log_in_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. feature 'Log in' do
  4. include ProfileStories
  5. given(:email) { "test@example.com" }
  6. given(:password) { "password" }
  7. given(:confirmed_at) { Time.zone.now }
  8. background do
  9. as_a_registered_user
  10. visit new_user_session_path
  11. end
  12. subject { page }
  13. scenario '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. is_expected.to have_css('div.app-holder')
  18. end
  19. scenario '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. is_expected.to have_css('.flash-message', text: failure_message('invalid'))
  24. end
  25. context do
  26. given(:confirmed_at) { nil }
  27. scenario '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. is_expected.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