diff --git a/spec/lib/youtube_titles_spec.rb b/spec/lib/youtube_titles_spec.rb index f84c075f8..a45c8ae24 100644 --- a/spec/lib/youtube_titles_spec.rb +++ b/spec/lib/youtube_titles_spec.rb @@ -1,29 +1,45 @@ require 'spec_helper' require 'youtube_titles' 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 describe '#youtube_title_for' 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 &" + @mock_http = mock("http") + Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(@mock_http) end it 'gets a youtube title corresponding to an id' do + @mock_http.should_receive(:get).with(@api_path, nil).and_return( + [nil, "Foobar #{@expected_title} hallo welt dsd"]) + 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} hallo welt dsd"]) + 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") Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http) mock_http.should_receive(:get).with(@api_path, nil).and_return( [nil, "Foobar #{@expected_title} hallo welt dsd"]) - - youtube_title_for(@video_id).should == @expected_title + @post = Factory.create(:status_message, :message => @url) end - it 'returns a fallback for videos with no title' do - mock_http = 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( - [nil, "Foobar #{@expected_title} hallo welt dsd"]) - - youtube_title_for(@video_id).should == I18n.t('application.helper.video_title.unknown') + it 'can be re-marshalled' do + lambda { + StatusMessage.find(@post.id).youtube_titles + }.should_not raise_error + end + it 'correctly marshals' do + StatusMessage.find(@post.id).youtube_titles.should == {@video_id => @expected_title} end end end