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

Add support for generate scaffold password:digest #9699

Merged
merged 1 commit into from Mar 13, 2013
Merged

Add support for generate scaffold password:digest #9699

merged 1 commit into from Mar 13, 2013

Conversation

rubys
Copy link
Contributor

@rubys rubys commented Mar 13, 2013

has_secure_password is a useful feature that presents "virtual" password and password_confirmation attributes on creation and update backed by a password_digest attribute in the database. Getting the migration, model, views, tests, and fixtures correct is needlessly complicated. This change enables application developers to specify password:digest on a generate scaffold command. Doing so:

  • adds password_digest attribute to the migration
  • adds has_secure_password to the model
  • adds password and password_confirmation password_fields to _form.html
  • adds password_digest to index.html and show.html
  • adds password and password_confirmation to the controller
  • adds unencrypted password and password_confirmation to the controller test
  • adds encrypted password_digest to the fixture

The following tests have been run and pass successfully:

TEST_DIR=generators bundle exec rake test

Additionally, the unmodified Agile Web Development with Rails tests have been run (i.e., they haven't been updated to use this new option), and I've verified that absolutely no change to any of the generated artefacts results by this change.

Not done yet: changelog, new tests, jbuilder, and updating the edge guides and the AWDwR tests.

@steveklabnik, @jeremy, @carlosantoniodasilva

@rafaelfranca
Copy link
Member

I like it.

I have a question, do we need the password digest on the index and show?

@@ -2,8 +2,12 @@ class <%= migration_class_name %> < ActiveRecord::Migration
def change
create_table :<%= table_name %> do |t|
<% attributes.each do |attribute| -%>
<% if attribute.name == 'password' and attribute.type == :digest -%>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move the logic for attr name and type to the GeneratedAttribute class, so that the logic is in one place and you can check like attribute.password_digest? or something like that.

@rubys
Copy link
Contributor Author

rubys commented Mar 13, 2013

My initial thinking was that it was easier for an application developer to remove password digest lines from a template than it is to add them, but if most will remove them, and if adding these lines is both obvious and easy, then I can buy the argument that these lines shouldn't be added in the first place. Removed. I've also refactored the password digest attribute check based on Carlos' suggestion.

@rafaelfranca
Copy link
Member

👍 we can proceed in my opinion.

@rubys
Copy link
Contributor Author

rubys commented Mar 13, 2013

With the addition of a test case and a changelog entry, my recommendation is that this be pulled now. Updating jquery-rails, the edge guides, and my test suite can proceed after that is complete.

@rubys
Copy link
Contributor Author

rubys commented Mar 13, 2013

squashed

<strong><%= attribute.human_name %>:</strong>
<%%= @<%= singular_table_name %>.<%= attribute.name %> %>
<% end -%>
</p>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will generate an empty <p> tag for the digest attribute, can we move the check to avoid it?

@carlosantoniodasilva
Copy link
Member

Looks great 👍, thanks @rubys :)

* adds password_digest attribute to the migration
* adds has_secure_password to the model
* adds password and password_confirmation password_fields to _form.html
* omits password entirely from index.html and show.html
* adds password and password_confirmation to the controller
* adds unencrypted password and password_confirmation to the controller test
* adds encrypted password_digest to the fixture
carlosantoniodasilva added a commit that referenced this pull request Mar 13, 2013
Add support for generate scaffold password:digest

* adds password_digest attribute to the migration
* adds has_secure_password to the model
* adds password and password_confirmation password_fields to _form.html
* omits password from index.html and show.html
* adds password and password_confirmation to the controller
* adds unencrypted password and password_confirmation to the controller test
* adds encrypted password_digest to the fixture
@carlosantoniodasilva carlosantoniodasilva merged commit 16466e1 into rails:master Mar 13, 2013
@carlosantoniodasilva
Copy link
Member

💚 💛 ❤️ 💜 💙

@steveklabnik
Copy link
Member

👍

@Tonkpils
Copy link
Contributor

👍 I was actually thinking about this just yesterday creating the migration with the password_digest.

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

Successfully merging this pull request may close these issues.

None yet

5 participants