Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
- describe User, "updating password" do
- before :each do
- @user = User.spawn
- @user.password = "111111"
- @user.password_confirmation = "111111"
- @user.save!
- @incurrect_set = {:password=>"123", :password_confirmation=>"123", :old_password=>"incorrect"}
- @correct_set = {:password=>"123", :password_confirmation=>"123", :old_password=>"111111"}
- end
- it "should be invalid with empty old_password" do
- @user.update_attributes(:password=>"123", :password_confirmation=>"123", :old_password=>"").should == false
- end
- it "should be invalid with incorrent old_password" do
- @user.update_attributes(@incurrect_set).should == false
- end
- it "should update password without old_password" do
- @user.update_attributes(:password=>"123", :password_confirmation=>"123").should == true
- @user.valid_password?("123").should == true
- end
- it "should update password with correct old_password and valid new password" do
- @user.update_attributes(@correct_set).should == true
- @user.valid_password?("123").should == true
- end
- it "should add configured error message if old_password didn't match" do
- User.acts_as_authentic_config[:old_password_did_not_match_message] = "custome message"
- @user.update_attributes(:password=>"123", :password_confirmation=>"123", :old_password=>"incorrect")
- @user.errors.on(:old_password).should == "custome message"
- end
- it "should work several times with incorrect old_password" do
- @user.update_attributes(@incurrect_set).should == false
- @user.update_attributes(@incurrect_set).should == false
- end
- it "should work several times with correct old_password" do
- @user.update_attributes(@correct_set).should == true
- @correct_set[:old_password] = "123"
- @user.update_attributes(@correct_set).should == true
- end
- end
- describe User, "updating non password fields" do
- before :each do
- @user = User.spawn
- @user.password = "111111"
- @user.password_confirmation = "111111"
- @user.save!
- end
- it "should update without old_password" do
- @user.update_attributes(:last_name=>'saldon').should == true
- end
- it "should update with empty old_password" do
- @user.update_attributes(:last_name=>'saldon', :old_password=>"").should == true
- end
- it "should update with incorrect old_password" do
- @user.update_attributes(:last_name=>'saldon', :old_password=>"231").should == true
- end
- it "should update with correct old_password" do
- @user.update_attributes(:last_name=>'saldon', :old_password=>"111111").should == true
- end
- end
Add Comment
Please, Sign In to add comment