开发者

how to test password length on update of password

开发者 https://www.devze.com 2023-03-17 02:14 出处:网络
When a new user is created they are given a password. I want to test the case when the user updates or changes their password.

When a new user is created they are given a password.

I want to test the case when the user updates or changes their password.

User.rb

 validates :password, :on => :create,
                :presence => true,
                :confirmation => true,
                :length => {:within => 6..12}

before_validation :make_password, :on => :create

In spec/models/user_spec.rb I have the following:

describe "password validations" do before(:each) do @user = Factory(:user) end

it "should reject p开发者_如何学编程asswords that are too long" do
  too_long_password = "a" * 13
  @user.update_attributes(@attr.merge(:password => too_long_password, :password_confirmation => too_long_password)).should_not be_valid
end

end

Does not work. Now how do I test for the update? Any ideas appreciated.


remove the :on => :create clause from the validates. Removing this will activate the validation during create and update.

 validates :password,:presence => true,
                     :confirmation => true,
                     :length => {:within => 6..12}

You have not mentioned but you can also remove :on => :create, if it is needed in the before_validation too

0

精彩评论

暂无评论...
验证码 换一张
取 消