Skip to content

Instantly share code, notes, and snippets.

@azuby
Created March 3, 2012 03:46
Show Gist options
  • Save azuby/1964219 to your computer and use it in GitHub Desktop.
Save azuby/1964219 to your computer and use it in GitHub Desktop.
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