Created
November 1, 2010 23:52
-
-
Save robustdj/659071 to your computer and use it in GitHub Desktop.
video spec
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
require 'spec_helper' | |
describe Video do | |
describe :validations do | |
before { Factory(:video) } | |
it { should validate_presence_of :artist, :title, :link, :user_id } | |
it { should validate_uniqueness_of :link } | |
it { should validate_uniqueness_of :title, :scope => :artist, :message => "and Artist are not unique. This song has already been added." } | |
end | |
let(:video) { Factory(:video) } | |
it "should return a valid image url" do | |
video.image_url.should == "http://img.youtube.com/vi/#{video.link_id}/0.jpg" | |
end | |
it "should return a valid display name" do | |
video = Factory(:video, :artist => "Jurassic 5", :title => "The Influence") | |
video.display_name.should == 'Jurassic 5 - "The Influence"' | |
end | |
it "should retrieve album info" do | |
video.retrieve_album | |
video.reload | |
video.album.should satisfy do |album| | |
album.title == "Quality Control" | |
album.image_url == "http://userserve-ak.last.fm/serve/300x300/8589897.jpg" | |
end | |
end | |
it "should get the most recent videos" do | |
2.times { Factory(:video, :updated_at => 2.days.ago) } | |
recent_videos = [] | |
3.times { recent_videos << Factory(:video) } | |
Video.most_recent.should include(*recent_videos) | |
end | |
it "should get the most popular videos" do | |
popular_video = Factory(:video, :play_count => 5) | |
2.times { Factory(:video, :play_count => 3) } | |
popular_video2 = Factory(:video, :play_count => 7) | |
popular_video3 = Factory(:video, :play_count => 4) | |
Video.most_popular.should include(popular_video, popular_video2, popular_video3) | |
end | |
it "should increment play count" do | |
expect { video.increment_play_count }.to change(video, :play_count).by(1) | |
end | |
it "#tag_list should print out comma separated tags" do | |
video.update_attribute(:tag_list, "hip hop, jazz") | |
video.tag_list.should == "hip hop, jazz" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment