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