Created
March 3, 2012 03:46
-
-
Save azuby/1964219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates :password, format: { with: /\d/, message: "must contain at least one number" }, | |
allow_blank: true | |
validates :password, format: { with: /[a-zA-Z]/, message: "must contain at least one letter" }, | |
allow_blank: true | |
it "should require a letter" do | |
numbers = "12345678" | |
user = User.new(@attr.merge(:password => numbers, :password_confirmation => numbers)) | |
user.should have(1).error_on(:password) | |
user.errors_on(:password).should include("must contain at least one letter") | |
end | |
it "should require a number" do | |
letters = "abcdefgh" | |
user = User.new(@attr.merge(:password => letters, :password_confirmation => letters)) | |
user.should have(1).error_on(:password) | |
user.errors_on(:password).should include("must contain at least one number") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment