Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 5: Callback on generate_authentication_token #65

Open
casimcdaniels opened this issue Feb 21, 2016 · 3 comments
Open

Chapter 5: Callback on generate_authentication_token #65

casimcdaniels opened this issue Feb 21, 2016 · 3 comments

Comments

@casimcdaniels
Copy link

In chapter five, there is a callback hook statement to generate an authentication token upon user creation

before_create :generate_authentication_token!

This however is flawed, as there is a uniqueness validation requirement. Since validations are performed before a user save is even considered, auth_token has a value of "" (not unique) and thus generate_authentication_token is never called!

The correct hook should be
before_validation :generate_authentication_token!

@kurenn
Copy link
Owner

kurenn commented Feb 23, 2016

I'll take note on that, for the next book version!

https://media.giphy.com/media/U1XhGr8CWqvVC/giphy-facebook_s.jpg

@casimcdaniels
Copy link
Author

+1 for Breaking Bad

Also, take note shoulda matchers has issues with before_validation. For now in my project, I have left the test out since it always fails, but there may be a fix/monkeypatch for it.

@kurenn
Copy link
Owner

kurenn commented Feb 24, 2016

Yeah, probably, I''l leave this open as a reminder for the next book version! thanks for the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants