mattetti / dm-gvideo-adapter
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
fcce0de
Matt Aimonetti (author)
Mon Sep 29 10:42:02 -0700 2008
commit fcce0de0203f947a0406bdf57f39d1ec2de9842b
tree 0181ba0c2a242970ef4888037e894412b0e47db8
parent 046d02489664228bfe58eb86cce32f8cb3229907
tree 0181ba0c2a242970ef4888037e894412b0e47db8
parent 046d02489664228bfe58eb86cce32f8cb3229907
dm-gvideo-adapter / spec / dm-gvideo-adapter_spec.rb
| caf1cbb4 » | Matt Aimonetti | 2008-09-28 | 1 | require File.dirname(__FILE__) + '/spec_helper' | |
| d227bdf2 » | Matt Aimonetti | 2008-09-28 | 2 | require 'gvideo' | |
| caf1cbb4 » | Matt Aimonetti | 2008-09-28 | 3 | ||
| 4 | describe "dm-gvideo-adapter" do | ||||
| d227bdf2 » | Matt Aimonetti | 2008-09-28 | 5 | ||
| 6 | before(:all) do | ||||
| 7 | DataMapper.setup(:default, { | ||||
| 8 | :adapter => 'gvideo', | ||||
| 9 | :user_id => 'A005148908335059515423' | ||||
| 10 | }) | ||||
| 11 | @adapter = DataMapper::Repository.adapters[:default] | ||||
| 12 | @google_user = @adapter.google_user | ||||
| caf1cbb4 » | Matt Aimonetti | 2008-09-28 | 13 | end | |
| d227bdf2 » | Matt Aimonetti | 2008-09-28 | 14 | ||
| 15 | it "should raise an error if the user_id isn't passed" do | ||||
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 16 | lambda{ DataMapper.setup(:default, {:adapter => 'gvideo'}) }.should raise_error(GvideoInterface::FetchError) | |
| d227bdf2 » | Matt Aimonetti | 2008-09-28 | 17 | end | |
| 18 | |||||
| 19 | describe "getting all resources" do | ||||
| 20 | |||||
| 21 | before(:all) do | ||||
| 22 | @gvideos = @google_user.fetch_videos | ||||
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 23 | @videos = Video.all | |
| d227bdf2 » | Matt Aimonetti | 2008-09-28 | 24 | end | |
| 25 | |||||
| 26 | it "should get a set of videos" do | ||||
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 27 | @videos.should_not be_nil | |
| 28 | @videos.first.should be_an_instance_of(Video) | ||||
| 29 | end | ||||
| 30 | |||||
| 31 | it "should have all the videos" do | ||||
| 32 | @videos.length.should == @gvideos.length | ||||
| 33 | end | ||||
| 34 | |||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 35 | it "should be able to retrieve items using a title (string) condition" do | |
| 36 | videos = Video.all(:title => "Durex: The Garden") | ||||
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 37 | videos.length.should == 1 | |
| 38 | videos.first.title.should == "Durex: The Garden" | ||||
| 39 | end | ||||
| 40 | |||||
| 41 | it "should be able to retrieve items using a title (regexp) condition" do | ||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 42 | videos = Video.all(:title.like => "The Garden") | |
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 43 | videos.length.should == 1 | |
| 44 | videos.first.title.should == "Durex: The Garden" | ||||
| 45 | end | ||||
| 46 | |||||
| 47 | it "should be able to retrieve items using a duration (integer) condition (seconds)" do | ||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 48 | videos = Video.all(:duration => 12) | |
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 49 | videos.length.should == 2 | |
| 50 | end | ||||
| 51 | |||||
| 52 | it "should be able to retrieve items using a duration condition :gte " do | ||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 53 | videos = Video.all(:duration.gte => 13) | |
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 54 | videos.length.should < @gvideos.length | |
| 55 | end | ||||
| 56 | |||||
| 57 | it "should be able to retrieve items using a duration condition :lte " do | ||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 58 | videos = Video.all(:duration.lte => 12) | |
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 59 | videos.length.should < @gvideos.length | |
| 60 | (@videos.all(:duration.gte => 13).length + @videos.all(:duration.lte => 12).length).should == @gvideos.length | ||||
| 61 | end | ||||
| 62 | |||||
| 63 | it "should be able to use 2 duration conditions" do | ||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 64 | videos = Video.all(:duration.lte => 12, :duration.gte => 12) | |
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 65 | videos.length.should == @videos.all(:duration => 12).length | |
| 66 | end | ||||
| 67 | |||||
| 68 | end | ||||
| 69 | |||||
| 70 | describe "getting one resource" do | ||||
| 71 | |||||
| 72 | it "should have all the attributes of a video" do | ||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 73 | video = Video.first | |
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 74 | methods = %W{docid title video_url duration duration_in_minutes thumbnail_url embed_player} | |
| 75 | methods.each do |meth| | ||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 76 | video.send(meth.to_sym).should_not be_nil | |
| 4badb2ed » | Matt Aimonetti | 2008-09-28 | 77 | end | |
| d227bdf2 » | Matt Aimonetti | 2008-09-28 | 78 | end | |
| 79 | |||||
| 046afc2f » | Matt Aimonetti | 2008-09-28 | 80 | it "should be able to retrieve an item using a title (string) condition" do | |
| 81 | video = Video.first(:title => "Durex: The Garden") | ||||
| 82 | video.should be_an_instance_of(Video) | ||||
| 83 | video.title.should == "Durex: The Garden" | ||||
| 84 | end | ||||
| 85 | |||||
| 86 | it "should be able to retrieve items using a title (regexp) condition" do | ||||
| 87 | video = Video.first(:title.like => "The Garden") | ||||
| 88 | video.should be_an_instance_of(Video) | ||||
| 89 | video.title.should == "Durex: The Garden" | ||||
| 90 | end | ||||
| 91 | |||||
| d227bdf2 » | Matt Aimonetti | 2008-09-28 | 92 | end | |
| 93 | |||||
| 94 | |||||
| caf1cbb4 » | Matt Aimonetti | 2008-09-28 | 95 | end | |
