catstodon/spec/features/log_in_spec.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

require "rails_helper"
feature "Log in" do
given(:email) { "test@example.com" }
2017-06-01 17:25:59 +02:00
given(:password) { "password" }
given(:confirmed_at) { Time.zone.now }
background do
2017-06-01 17:25:59 +02:00
Fabricate(:user, email: email, password: password, confirmed_at: confirmed_at)
visit new_user_session_path
end
2017-06-01 17:25:59 +02:00
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
2017-06-01 17:25:59 +02:00
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
2017-06-01 17:25:59 +02:00
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")
2017-06-01 17:25:59 +02:00
end
end
2017-06-01 17:25:59 +02:00
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