From 7b4c377df12b8382670d8d8232aaaa8af8664186 Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Thu, 15 Mar 2012 19:44:18 +0100 Subject: [PATCH] make tests happy --- config/initializers/oembed.rb | 29 ++++++++++++++++++----------- spec/models/status_message_spec.rb | 23 ++++++++++++++--------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/config/initializers/oembed.rb b/config/initializers/oembed.rb index 8f615eed0..535e3a272 100644 --- a/config/initializers/oembed.rb +++ b/config/initializers/oembed.rb @@ -1,20 +1,27 @@ require 'oembed' require 'uri' -OEmbedCubbies = OEmbed::Provider.new("http://cubbi.es/oembed") - -OEmbed::Providers.register( - OEmbed::Providers::Youtube, - OEmbed::Providers::Vimeo, - OEmbed::Providers::Flickr, - OEmbed::Providers::SoundCloud, - OEmbedCubbies -) -OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery) - # # SECURITY NOTICE! CROSS-SITE SCRIPTING! # these endpoints may inject html code into our page # note that 'trusted_endpoint_url' is the only information # in OEmbed that we can trust. anything else may be spoofed! + +OEmbedCubbies = OEmbed::Provider.new("http://cubbi.es/oembed") + +oembed_provider_list = [ + OEmbed::Providers::Youtube, + OEmbed::Providers::Vimeo, + OEmbed::Providers::Flickr, + OEmbed::Providers::SoundCloud, + OEmbedCubbies +] + +SECURE_ENDPOINTS = oembed_provider_list.map do |provider| + OEmbed::Providers.register(provider) + provider.endpoint +end + +OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery) + TRUSTED_OEMBED_PROVIDERS = OEmbed::Providers diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index a11e075fc..02370e3d7 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -320,19 +320,24 @@ STR end end - describe '#contains_url_in_text?' do - it 'returns an array of all urls found in the raw message' do - sm = Factory(:status_message, :text => 'http://youtube.com is so cool. so is https://joindiaspora.com') - sm.contains_oembed_url_in_text?.should_not be_nil - sm.oembed_url.should == 'http://youtube.com' - end - end - describe 'oembed' do + before do + @youtube_url = "https://www.youtube.com/watch?v=3PtFwlKfvHI" + @message_text = "#{@youtube_url} is so cool. so is this link -> https://joindiaspora.com" + end + it 'should queue a GatherOembedData if it includes a link' do - sm = Factory.build(:status_message, :text => 'http://youtube.com is so cool. so is https://joindiaspora.com') + sm = Factory.build(:status_message, :text => @message_text) Resque.should_receive(:enqueue).with(Jobs::GatherOEmbedData, instance_of(Fixnum), instance_of(String)) sm.save end + + describe '#contains_oembed_url_in_text?' do + it 'returns the oembed urls found in the raw message' do + sm = Factory(:status_message, :text => @message_text) + sm.contains_oembed_url_in_text?.should_not be_nil + sm.oembed_url.should == @youtube_url + end + end end end