Skip to content

Instantly share code, notes, and snippets.

@timuruski
Created February 13, 2012 19:53
Show Gist options
  • Select an option

  • Save timuruski/1819679 to your computer and use it in GitHub Desktop.

Select an option

Save timuruski/1819679 to your computer and use it in GitHub Desktop.
describe "validations" do
context "birthday" do
["bad format","2100-01-01","1800-01-01","2000-13-01","2000-00-01","2000-01-32","2000-01-00"].each do |bday|
it "errors with invalid date - #{bday}" do
person = Person.create(:name => "not blank", :birthday => bday)
person.errors.messages[:birthday].first.should == "is invalid"
end
end
["2099-12-31", nil].each do |bday|
it "accepts with good birthday - #{bday}" do
Person.count.should == 0
person = Person.create(:name => "name not blank", :birthday => "2099-12-31") #max year-max month-max day
person.errors.messages.should == {}
Person.count.should == 1
Person.first.name.should == "name not blank"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment