ruby on rails - Rspec fails for Devise model custom validation for valid_password? -


i using devise gem(authentication). implementing custom validation reset password. user can not reset there new password existing password. in user model code is:

 class user < activerecord::base      include activemodel::forbiddenattributesprotection      validate  :check_existed_password                                       def check_existed_password         if user.find_by_email(self.email).valid_password?(password)           errors.add(:password, "password existed, try other")         end       end     end                                

after running rspec, getting error: failure/error: no_email_user.should_not be_valid nomethoderror: undefined method `valid_password?' nil:nilclass. pre-existing test cases in user_spec.rb file getting fail. suggestion ?

blockquote

either email not present or email providing doesn't has user associated it. why geeting error. in spec checking no_email_user.should_not be_valid means user no email should not valid. validation have added check_existed_password needs run on update , not on create. make as:

validate  :check_existed_password, :on => :update 

beacuse user reset password on update action , not on create. try find user has not been created yet , throw error everytime.

hope helps.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -