Skip to content

Instantly share code, notes, and snippets.

@repertoire
Created January 18, 2011 16:28
Show Gist options
  • Save repertoire/784692 to your computer and use it in GitHub Desktop.
Save repertoire/784692 to your computer and use it in GitHub Desktop.
class Video < ActiveRecord::Base
has_many :video_locations
has_many :locations, :through => :video_locations
attr_accessible :title, :date, :url
validate :validates_presence_of_locations
def validates_presence_of_locations
errors.add(:locations, "must have at least one video") if
locations.length < 1
end
validates_presence_of :title, :date, :url
end
# Tests which are passing
before(:each) do
@attr = {
:title => "Title",
:date => DateTime.now,
:url => 'http://youtube.com',
:location => Location.new,
:people => Person.new
}
end
it "should require a location" do
no_location_video = Video.new(@attr.merge(:location => nil))
no_location_video.should_not be_valid
end
it "should require a person" do
no_person_video = Video.new(@attr.merge(:people => nil))
no_person_video.should_not be_valid
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment