-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from gobuffalo/task-signin
Organizes routes a bit and avoids overriding index.html
- Loading branch information
Showing
6 changed files
with
104 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,66 +4,92 @@ import ( | |
"<%= app.PackagePkg %>/models" | ||
) | ||
|
||
func (as *ActionSuite) Test_Auth_New() { | ||
res := as.HTML("/signin").Get() | ||
as.Equal(200, res.Code) | ||
as.Contains(res.Body.String(), "Sign In") | ||
} | ||
|
||
func (as *ActionSuite) Test_Auth_Create() { | ||
func (as *ActionSuite) createUser() (*models.User, error) { | ||
u := &models.User{ | ||
Email: "[email protected]", | ||
Password: "password", | ||
PasswordConfirmation: "password", | ||
} | ||
|
||
verrs, err := u.Create(as.DB) | ||
as.NoError(err) | ||
as.False(verrs.HasAny()) | ||
|
||
res := as.HTML("/signin").Post(u) | ||
as.Equal(302, res.Code) | ||
as.Equal("/", res.Location()) | ||
return u, err | ||
} | ||
|
||
func (as *ActionSuite) Test_Auth_Create_Redirect() { | ||
u := &models.User{ | ||
Email: "[email protected]", | ||
Password: "password", | ||
PasswordConfirmation: "password", | ||
} | ||
verrs, err := u.Create(as.DB) | ||
as.NoError(err) | ||
as.False(verrs.HasAny()) | ||
func (as *ActionSuite) Test_Auth_Signin() { | ||
res := as.HTML("/auth/").Get() | ||
as.Equal(200, res.Code) | ||
as.Contains(res.Body.String(), `<a href="/signin" class="btn btn-primary">Sign In</a>`) | ||
} | ||
|
||
as.Session.Set("redirectURL", "/some/url") | ||
func (as *ActionSuite) Test_Auth_New() { | ||
res := as.HTML("/auth/new").Get() | ||
as.Equal(200, res.Code) | ||
as.Contains(res.Body.String(), "Sign In") | ||
} | ||
|
||
res := as.HTML("/signin").Post(u) | ||
func (as *ActionSuite) Test_Auth_SaveRedirect() { | ||
res := as.HTML("/").Get() | ||
as.Equal(302, res.Code) | ||
as.Equal(res.Location(), "/some/url") | ||
|
||
as.Equal("/auth", res.Location()) | ||
as.Equal(as.Session.Get("redirectURL"), "/") | ||
} | ||
|
||
func (as *ActionSuite) Test_Auth_Create_UnknownUser() { | ||
u := &models.User{ | ||
Email: "[email protected]", | ||
Password: "password", | ||
func (as *ActionSuite) Test_Auth_Create() { | ||
u, err := as.createUser() | ||
as.NoError(err) | ||
|
||
tcases := []struct { | ||
Email string | ||
Password string | ||
Status int | ||
RedirectURL string | ||
|
||
Identifier string | ||
}{ | ||
{u.Email, u.Password, http.StatusFound, "/", "Valid"}, | ||
{"[email protected]", "password", http.StatusUnauthorized, "", "Email Invalid"}, | ||
{u.Email, "invalidPassword", http.StatusUnauthorized, "", "Password Invalid"}, | ||
} | ||
res := as.HTML("/signin").Post(u) | ||
as.Equal(422, res.Code) | ||
as.Contains(res.Body.String(), "invalid email/password") | ||
} | ||
|
||
func (as *ActionSuite) Test_Auth_Create_BadPassword() { | ||
u := &models.User{ | ||
Email: "[email protected]", | ||
Password: "password", | ||
PasswordConfirmation: "password", | ||
for _, tcase := range tcases { | ||
as.Run(tcase.Identifier, func() { | ||
res := as.HTML("/auth").Post(&models.User{ | ||
Email: tcase.Email, | ||
Password: tcase.Password, | ||
}) | ||
|
||
as.Equal(tcase.Status, res.Code) | ||
as.Equal(tcase.RedirectURL, res.Location()) | ||
}) | ||
} | ||
verrs, err := u.Create(as.DB) | ||
} | ||
|
||
func (as *ActionSuite) Test_Auth_Redirect() { | ||
u, err := as.createUser() | ||
as.NoError(err) | ||
as.False(verrs.HasAny()) | ||
|
||
u.Password = "bad" | ||
res := as.HTML("/signin").Post(u) | ||
as.Equal(422, res.Code) | ||
as.Contains(res.Body.String(), "invalid email/password") | ||
tcases := []struct { | ||
redirectURL interface{} | ||
resultLocation string | ||
|
||
identifier string | ||
}{ | ||
{"/some/url", "/some/url", "RedirectURL defined"}, | ||
{nil, "/", "RedirectURL nil"}, | ||
{"", "/", "RedirectURL empty"}, | ||
} | ||
|
||
for _, tcase := range tcases { | ||
as.Run(tcase.identifier, func() { | ||
as.Session.Set("redirectURL", tcase.redirectURL) | ||
|
||
res := as.HTML("/auth").Post(u) | ||
|
||
as.Equal(302, res.Code) | ||
as.Equal(res.Location(), tcase.resultLocation) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.