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

Already on GitHub? Sign in to your account

Find account record from resourceful route when user model is overridden #377

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants

The password reset function breaks when the user model is overridden, as the record ID from the resourceful route is expected to be available as :user_id but instead is e.g. :person_id

This corrects that.

I'm not wild about the dummy class definitions in the password controller spec file; suggestions for improving that aspect welcomed.

@r00k r00k commented on the diff Jan 7, 2014

spec/controllers/passwords_controller_spec.rb
describe Clearance::PasswordsController do
+
+ context "custom user model adaptations" do
+ before do
Contributor

r00k commented Jan 7, 2014

I had one comment. Once that's addressed I'm fine with merging this.

@gylaz gylaz commented on the diff Jan 7, 2014

spec/controllers/passwords_controller_spec.rb
+ end
+
+ it "is :person_id" do
+ controller.send(:user_model_identifier).should eql(:multi_word_human_being_klass_id)
+ end
+ end
+ end
+
+ context "when the user model is User" do
+ describe "#user_model_identifier" do
+ it "is :user_id" do
+ controller.send(:user_model_identifier).should eql(:user_id)
+ end
+ end
+ end
+ end
@gylaz

gylaz Jan 7, 2014

Owner

Generally, we prefer not to write tests for private methods. Isntead, could you write a controller (regression) test that demonstrates the bug/failure that you found, and passes with this new fix?

@derekprior

derekprior Feb 7, 2014

Member

I'm trying to do this myself right now. It's difficult because you need to override the routes in the controller spec as well. I'm not sure there's an easy way to do this.

@derekprior derekprior added a commit that referenced this pull request Feb 7, 2014

@derekprior derekprior Get user_model id parameter from configuration
The password reset controller was previously assuming that the id
parameter would be available as 'user_id', but if you have customized
the user model this won't be the case. Get the proper name from the
configuration.

Supersedes #377
dd51b8e
Member

derekprior commented Feb 7, 2014

I went in a different, simpler-to-test direction with #395. Closing this.

@derekprior derekprior closed this Feb 7, 2014

@derekprior derekprior added a commit that referenced this pull request Feb 7, 2014

@derekprior derekprior Get user_model id parameter from configuration
The password reset controller was previously assuming that the id
parameter would be available as 'user_id', but if you have customized
the user model this won't be the case. Get the proper name from the
configuration.

Supersedes #377
0f71807
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment