-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor tests and allow sending activation emails
- Loading branch information
1 parent
c35788f
commit ef5d44e
Showing
7 changed files
with
131 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,89 @@ | ||
require "test_helper" | ||
|
||
class UsersLoginTest < ActionDispatch::IntegrationTest | ||
class UsersLogin < ActionDispatch::IntegrationTest | ||
|
||
def setup | ||
@user = users(:amr) | ||
end | ||
end | ||
|
||
test "login with invalid information" do | ||
class InvalidPasswordTest < UsersLogin | ||
|
||
test "login path" do | ||
get login_path | ||
assert_template "sessions/new" | ||
assert_template 'sessions/new' | ||
end | ||
|
||
test "login with invalid information" do | ||
post login_path, params: { session: { email: "", password: "" } } | ||
assert_not is_logged_in? | ||
assert_response :unprocessable_entity | ||
assert_template "sessions/new" | ||
assert_not flash.empty? | ||
get root_path | ||
assert flash.empty? | ||
end | ||
end | ||
|
||
test "login with valid information" do | ||
get login_path | ||
post login_path, params: { session: { email: @user.email, password: "password" } } | ||
assert_redirected_to @user | ||
follow_redirect! | ||
assert_template "users/show" | ||
class ValidLogin < UsersLogin | ||
def setup | ||
super | ||
post login_path, params: { session: { email: @user.email, | ||
password: "password" } } | ||
end | ||
end | ||
|
||
test "login with valid information followed by logout" do | ||
post login_path, params: { session: { email: @user.email, | ||
password: "password" } } | ||
class ValidLoginTest < ValidLogin | ||
|
||
test "valid login" do | ||
assert is_logged_in? | ||
assert_redirected_to @user | ||
end | ||
|
||
test "redirect after login" do | ||
follow_redirect! | ||
assert_template "users/show" | ||
assert_select "a[href=?]", login_path, count: 0 | ||
assert_select "a[href=?]", logout_path | ||
assert_select "a[href=?]", user_path(@user) | ||
delete logout_path | ||
assert_not is_logged_in? | ||
assert_redirected_to root_url | ||
# Simulate user clicking logout in a second window | ||
delete logout_path | ||
follow_redirect! | ||
assert_select "a[href=?]", login_path | ||
assert_select "a[href=?]", logout_path, count: 0 | ||
assert_select "a[href=?]", user_path(@user), count: 0 | ||
end | ||
|
||
test "login with remembering" do | ||
log_in_as(@user, remember_me: "1") | ||
assert_not_nil cookies["remember_token"] | ||
class Logout < ValidLogin | ||
def setup | ||
super | ||
delete logout_path | ||
end | ||
end | ||
|
||
test "login without remembering" do | ||
log_in_as(@user, remember_me: "0") | ||
assert_nil cookies["remember_token"] | ||
class LogoutTest < Logout | ||
|
||
test "successful logout" do | ||
assert_not is_logged_in? | ||
assert_redirected_to root_url | ||
end | ||
|
||
test "redirect after logout" do | ||
follow_redirect! | ||
assert_select "a[href=?]", login_path | ||
assert_select "a[href=?]", logout_path, count: 0 | ||
assert_select "a[href=?]", user_path(@user), count: 0 | ||
end | ||
|
||
test "should still work after logout in second window" do | ||
delete logout_path | ||
assert_redirected_to root_url | ||
end | ||
end | ||
|
||
class RememberingTest < UsersLogin | ||
test "login with remembering" do | ||
log_in_as(@user, remember_me: "1") | ||
assert_not_nil cookies["remember_token"] | ||
end | ||
|
||
test "login without remembering" do | ||
log_in_as(@user, remember_me: "0") | ||
assert_nil cookies["remember_token"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters