Skip to content
Extraits de code Groupes Projets
Valider b6e2e945 rédigé par Sarah Mei's avatar Sarah Mei
Parcourir les fichiers

Fix YouTube titles on 1.9. (SIGH.)

parent 624e7277
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -10,7 +10,7 @@ module YoutubeTitles ...@@ -10,7 +10,7 @@ module YoutubeTitles
def youtube_title_for video_id def youtube_title_for video_id
http = Net::HTTP.new('gdata.youtube.com', 80) http = Net::HTTP.new('gdata.youtube.com', 80)
path = "/feeds/api/videos/#{video_id}?v=2" path = "/feeds/api/videos/#{video_id}?v=2"
resp, data = http.get(path, nil) resp, data = http.get(path)
title = data.match(/<title>(.*)<\/title>/) title = data.match(/<title>(.*)<\/title>/)
unless title.nil? unless title.nil?
title = title.to_s[7..-9] title = title.to_s[7..-9]
......
...@@ -18,13 +18,13 @@ describe YoutubeTitles do ...@@ -18,13 +18,13 @@ describe YoutubeTitles do
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( @mock_http.should_receive(:get).with(@api_path).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>"])
youtube_title_for(@video_id).should == @expected_title youtube_title_for(@video_id).should == @expected_title
end end
it 'returns a fallback for videos with no title' do it 'returns a fallback for videos with no title' do
@mock_http.should_receive(:get).with(@api_path, nil).and_return( @mock_http.should_receive(:get).with(@api_path).and_return(
[nil, "Foobar #{@expected_title}</title> hallo welt <asd><dasdd><a>dsd</a>"]) [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') youtube_title_for(@video_id).should == I18n.t('application.helper.video_title.unknown')
end end
...@@ -35,7 +35,7 @@ describe YoutubeTitles do ...@@ -35,7 +35,7 @@ describe YoutubeTitles do
@expected_title = '""Procrastination"" Tales Of Mere Existence' @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).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, :text => @url) @post = Factory.create(:status_message, :text => @url)
end end
......
...@@ -101,7 +101,7 @@ describe Comment do ...@@ -101,7 +101,7 @@ describe Comment do
mock_http = mock("http") mock_http = mock("http")
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).twice.and_return(mock_http) Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).twice.and_return(mock_http)
mock_http.should_receive(:get).with(/\/feeds\/api\/videos/, nil).twice.and_return( mock_http.should_receive(:get).with(/\/feeds\/api\/videos/).twice.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>'])
comment = alice.build_comment :text => url, :post => @message comment = alice.build_comment :text => url, :post => @message
......
...@@ -236,7 +236,7 @@ STR ...@@ -236,7 +236,7 @@ STR
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('/feeds/api/videos/'+video_id+'?v=2', nil).and_return( mock_http.should_receive(:get).with('/feeds/api/videos/'+video_id+'?v=2').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 = @user.build_post :status_message, :text => url, :to => @aspect.id post = @user.build_post :status_message, :text => url, :to => @aspect.id
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter