set_password plus some refactoring
This commit is contained in:
parent
7ff103a430
commit
0a4e41e5d1
|
|
@ -164,11 +164,12 @@ module JamRuby
|
|||
return id
|
||||
end
|
||||
|
||||
def set_password(old_password, new_password)
|
||||
raise JamRuby::JamArgumentError, ValidationMessages::OLD_PASSWORD_DOESNT_MATCH unless authenticate old_password
|
||||
# FIXME: Should verify that the new password meets certain quality criteria
|
||||
# FIXME: Need to run the new password through the validations here. Not sure if this does that.
|
||||
password = new_password
|
||||
def set_password(old_password, new_password, new_password_confirmation)
|
||||
raise JamRuby::JamArgumentError unless authenticate old_password
|
||||
# FIXME: Should verify that the new password meets certain quality criteria. Really, maybe that should be a
|
||||
# verification step.
|
||||
self.password = new_password
|
||||
self.password_confirmation = new_password_confirmation
|
||||
save
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -125,15 +125,32 @@ describe User do
|
|||
it { should be_invalid }
|
||||
end
|
||||
|
||||
describe "setting a new password should work" do
|
||||
describe "set_password" do
|
||||
before do
|
||||
@user.confirm_email!
|
||||
end
|
||||
|
||||
it "setting a new password should work" do
|
||||
@user.set_password("foobar", "newpassword", "newpassword")
|
||||
User.authenticate(@user.email, "newpassword").should_not be_nil
|
||||
end
|
||||
|
||||
it "setting a new password should fail if old one doesnt match" do
|
||||
@user.set_password("wrongold", "newpassword", "newpassword").should_raise # This doesnt work.
|
||||
end
|
||||
|
||||
it "setting a new password should fail if new ones dont match" do
|
||||
@user.set_password("foobar", "newpassword", "newpassword2")
|
||||
User.authenticate(@user.email, "newpassword").should be_nil
|
||||
end
|
||||
|
||||
it "setting a new password should fail if new one doesnt validate" do
|
||||
@user.set_password("foobar", "a", "a")
|
||||
User.authenticate(@user.email, "newpassword").should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
describe "setting a new password should fail if old one doesnt match" do
|
||||
|
||||
end
|
||||
describe "setting a new password should fail if new one doesnt validate" do
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "return value of authenticate method" do
|
||||
|
|
|
|||
Loading…
Reference in New Issue