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 passwords 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 => :createclause from the validates. Removing this will activate the validation during create and update.You have not mentioned but you can also remove
:on => :create, if it is needed in the before_validation too