From 2f7bc02712c616e0da3c526765e5c1fd2aa30dd3 Mon Sep 17 00:00:00 2001 From: archi Date: Sun, 17 Oct 2010 22:25:56 +0200 Subject: [PATCH] Some specs for the make_links function. Can i haz youtubeZ? :P --- spec/helpers/status_messages_helper_spec.rb | 30 +++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/spec/helpers/status_messages_helper_spec.rb b/spec/helpers/status_messages_helper_spec.rb index 0fe896ba6..0aee3826a 100644 --- a/spec/helpers/status_messages_helper_spec.rb +++ b/spec/helpers/status_messages_helper_spec.rb @@ -33,14 +33,28 @@ describe StatusMessagesHelper do make_links(proto+"://"+url).should == ""+url+"" end -# this will not work because the make_links requires an internet connection, which is disabled for the test :( -# it "should recognize youtube links" do -# proto="http" -# url="www.youtube.com/watch?v=UNgOJDL9iyQ&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" -# res = make_links(proto+"://"+url, true) -# puts "RES: " + res -# res.should == ""+url+"" -# end + it "should recognize youtube links" do + proto="http" + videoid = "0x__dDWdf23" + url="www.youtube.com/watch?v="+videoid+"&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" + title = "UP & down & UP & down &" + mock_http = mock("http") + Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http) + mock_http.should_receive(:get).with('/feeds/api/videos/'+videoid+'?v=2', nil).and_return([nil, 'Foobar '+title+' hallo welt dsd']) + res = make_links(proto+'://'+url) + res.should == "Youtube: "+title+"" + end + + it "should recognize a bunch of different links" do + message = "http:// Hello World, this is for www.joindiaspora.com and not for http://www.google.com though their Youtube service is neat, take http://www.youtube.com/watch?v=foobar or www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related It is a good idea we finally have youtube, so enjoy this video http://www.youtube.com/watch?v=rickrolld" + mock_http = mock("http") + Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http) + mock_http.should_receive(:get).with('/feeds/api/videos/foobar?v=2', nil).and_return([nil, 'Foobar F 007 - the bar is not enough hallo welt dsd']) + mock_http.should_receive(:get).with('/feeds/api/videos/BARFOO?v=2', nil).and_return([nil, 'Foobar BAR is the new FOO hallo welt dsd']) + mock_http.should_receive(:get).with('/feeds/api/videos/rickrolld?v=2', nil).and_return([nil, 'Foobar Never gonne give you up hallo welt dsd']) + res = make_links(message) + res.should == "http:// Hello World, this is for www.joindiaspora.com and not for www.google.com though their Youtube service is neat, take Youtube: F 007 - the bar is not enough or Youtube: BAR is the new FOO It is a good idea we finally have youtube, so enjoy this video Youtube: Never gonne give you up" + end it "should recognize basic ftp links" do proto="ftp"