Add scenarios for log in (#3497)

This commit is contained in:
Yamagishi Kazutoshi 2017-06-02 00:25:59 +09:00 committed by Eugen Rochko
parent fda5c699c2
commit 509b0cfafc
1 changed files with 34 additions and 6 deletions

View File

@ -3,17 +3,45 @@ require "rails_helper"
feature "Log in" do
given(:email) { "test@examle.com" }
given(:password) { "password" }
given(:confirmed_at) { Time.now }
background do
Fabricate(:user, email: email, password: password)
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
visit new_user_session_path
fill_in "user_email", with: email
fill_in "user_password", with: password
click_on "Log in"
click_on I18n.t('auth.login')
expect(page).to have_css "div.app-holder"
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 not 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(".flash-message", text: failure_message("unconfirmed"))
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