Created
January 18, 2011 16:28
-
-
Save repertoire/784692 to your computer and use it in GitHub Desktop.
This file contains 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
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