add spec for youtube_titles
This commit is contained in:
parent
3f42c5bdb9
commit
5967ce25fd
1 changed files with 28 additions and 12 deletions
|
|
@ -1,29 +1,45 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'youtube_titles'
|
require 'youtube_titles'
|
||||||
describe YoutubeTitles do
|
describe YoutubeTitles do
|
||||||
|
before do
|
||||||
|
@video_id = "ABYnqp-bxvg"
|
||||||
|
@url="http://www.youtube.com/watch?v=#{@video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
||||||
|
@api_path = "/feeds/api/videos/#{@video_id}?v=2"
|
||||||
|
end
|
||||||
include YoutubeTitles
|
include YoutubeTitles
|
||||||
describe '#youtube_title_for' do
|
describe '#youtube_title_for' do
|
||||||
before do
|
before do
|
||||||
@video_id = "ABYnqp-bxvg"
|
|
||||||
@url="http://www.youtube.com/watch?v=#{@video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
|
||||||
@api_path = "/feeds/api/videos/#{@video_id}?v=2"
|
|
||||||
@expected_title = "UP & down & UP & down &"
|
@expected_title = "UP & down & UP & down &"
|
||||||
|
@mock_http = mock("http")
|
||||||
|
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(@mock_http)
|
||||||
end
|
end
|
||||||
it 'gets a youtube title corresponding to an id' do
|
it 'gets a youtube title corresponding to an id' do
|
||||||
|
@mock_http.should_receive(:get).with(@api_path, nil).and_return(
|
||||||
|
[nil, "Foobar <title>#{@expected_title}</title> hallo welt <asd><dasdd><a>dsd</a>"])
|
||||||
|
youtube_title_for(@video_id).should == @expected_title
|
||||||
|
end
|
||||||
|
it 'returns a fallback for videos with no title' do
|
||||||
|
@mock_http.should_receive(:get).with(@api_path, nil).and_return(
|
||||||
|
[nil, "Foobar #{@expected_title}</title> hallo welt <asd><dasdd><a>dsd</a>"])
|
||||||
|
youtube_title_for(@video_id).should == I18n.t('application.helper.video_title.unknown')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe 'serialization and marshalling' do
|
||||||
|
before do
|
||||||
|
@expected_title = '""Procrastination"" Tales Of Mere Existence'
|
||||||
mock_http = mock("http")
|
mock_http = mock("http")
|
||||||
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
|
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
|
||||||
mock_http.should_receive(:get).with(@api_path, nil).and_return(
|
mock_http.should_receive(:get).with(@api_path, nil).and_return(
|
||||||
[nil, "Foobar <title>#{@expected_title}</title> hallo welt <asd><dasdd><a>dsd</a>"])
|
[nil, "Foobar <title>#{@expected_title}</title> hallo welt <asd><dasdd><a>dsd</a>"])
|
||||||
|
@post = Factory.create(:status_message, :message => @url)
|
||||||
youtube_title_for(@video_id).should == @expected_title
|
|
||||||
end
|
end
|
||||||
it 'returns a fallback for videos with no title' do
|
it 'can be re-marshalled' do
|
||||||
mock_http = mock("http")
|
lambda {
|
||||||
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
|
StatusMessage.find(@post.id).youtube_titles
|
||||||
mock_http.should_receive(:get).with(@api_path, nil).and_return(
|
}.should_not raise_error
|
||||||
[nil, "Foobar #{@expected_title}</title> hallo welt <asd><dasdd><a>dsd</a>"])
|
end
|
||||||
|
it 'correctly marshals' do
|
||||||
youtube_title_for(@video_id).should == I18n.t('application.helper.video_title.unknown')
|
StatusMessage.find(@post.id).youtube_titles.should == {@video_id => @expected_title}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue