Skip to content

Instantly share code, notes, and snippets.

@pmichaeljones
Created January 7, 2015 18:20
Show Gist options
  • Save pmichaeljones/f2d03213bf7db6511ea0 to your computer and use it in GitHub Desktop.
Save pmichaeljones/f2d03213bf7db6511ea0 to your computer and use it in GitHub Desktop.
Passing Validation Errors
class Video < ActiveRecord::Base
belongs_to :category , foreign_key: 'category_id'
validates :title, presence: true
validates :description, presence: true
end
--------- Different Code Below. Same Gist Though ----------
it "requires a title" do
harry = Video.create(title: nil, description:"A touching story.", category_id: 1)
expect(harry.errors.full_messages[0]).to eq("Title can't be blank")
end
it "requires a description" do
harry = Video.create(title:"When Harry Met Sally", description: nil, category_id: 1)
expect(harry.errors.full_messages[0]).to eq("Description can't be blank")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment