Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix soundcloud test

  • Loading branch information...
commit 13bd710b0ebaff4c1164b35a6e7b23fb4c68b91b 1 parent 1edc3d0
Dejan Simić authored
3  Gemfile
View
@@ -3,4 +3,5 @@ source "http://rubygems.org"
gemspec
gem "rails", "~> 3.2.0"
-gem 'sqlite3', '~> 1.3.3'
+gem 'sqlite3', '~> 1.3.3'
+gem 'fakeweb'
2  Gemfile.lock
View
@@ -38,6 +38,7 @@ GEM
arel (3.0.0)
builder (3.0.0)
erubis (2.7.0)
+ fakeweb (1.3.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.1)
@@ -93,5 +94,6 @@ PLATFORMS
DEPENDENCIES
auto_html!
+ fakeweb
rails (~> 3.2.0)
sqlite3 (~> 1.3.3)
22 lib/auto_html/filters/soundcloud.rb
View
@@ -5,23 +5,19 @@
# set these options
# :maxwidth => '', :maxheight => '', :auto_play => false, :show_comments => false
text.gsub(/(https?:\/\/)?(www.)?soundcloud\.com\/.*/) do |match|
- begin
- new_uri = match.to_s
- new_uri = (new_uri =~ /^https?\:\/\/.*/) ? URI(new_uri) : URI("http://#{new_uri}")
- new_uri.normalize!
-
- uri = URI("http://soundcloud.com/oembed")
- params = {:format => 'json', :url => new_uri}
- params = params.merge options
- uri.query = URI.encode_www_form(params)
- response = Net::HTTP.get(uri)
- rescue
- end
+ new_uri = match.to_s
+ new_uri = (new_uri =~ /^https?\:\/\/.*/) ? URI(new_uri) : URI("http://#{new_uri}")
+ new_uri.normalize!
+ uri = URI("http://soundcloud.com/oembed")
+ params = {:format => 'json', :url => new_uri}.merge(options)
+ uri.query = params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
+ response = Net::HTTP.get(uri)
if !response.blank?
JSON.parse(response)["html"]
else
match
end
end
-end
+end
+
13 test/unit/filters/soundcloud_test.rb
View
@@ -1,7 +1,13 @@
require File.expand_path('../../unit_test_helper', __FILE__)
+require 'fakeweb'
class SoundcloudTest < Test::Unit::TestCase
-
+
+ def setup
+ response = '{"version":1.0,"type":"rich","provider_name":"SoundCloud","provider_url":"http://soundcloud.com","height":166,"width":"100%","title":"Flickermood by Forss","description":"From the Soulhack album,\u0026nbsp;recently featured in this ad \u003Ca href=\"https://www.dswshoes.com/tv_commercial.jsp?m=october2007\"\u003Ehttps://www.dswshoes.com/tv_commercial.jsp?m=october2007\u003C/a\u003E ","thumbnail_url":"http://i1.sndcdn.com/artworks-000000001720-91c40a-t500x500.jpg?330b92d","html":"\u003Ciframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293\u0026show_artwork=true\"\u003E\u003C/iframe\u003E","author_name":"Forss","author_url":"http://soundcloud.com/forss"}'
+ FakeWeb.register_uri(:get, %r|http://soundcloud\.com/oembed|, :body => response)
+ end
+
def test_transform_url_with_www
result = auto_html('http://www.soundcloud.com/forss/flickermood') { soundcloud }
assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293&show_artwork=true"></iframe>', result
@@ -23,7 +29,10 @@ def test_transform_url_with_ssl
end
def test_transform_url_with_options
+ response = '{"version":1.0,"type":"rich","provider_name":"SoundCloud","provider_url":"http://soundcloud.com","height":100,"width":100,"title":"Flickermood by Forss","description":"From the Soulhack album,\u0026nbsp;recently featured in this ad \u003Ca href=\"https://www.dswshoes.com/tv_commercial.jsp?m=october2007\"\u003Ehttps://www.dswshoes.com/tv_commercial.jsp?m=october2007\u003C/a\u003E ","thumbnail_url":"http://i1.sndcdn.com/artworks-000000001720-91c40a-t500x500.jpg?330b92d","html":"\u003Ciframe width=\"100\" height=\"100\" scrolling=\"no\" frameborder=\"no\" src=\"http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293\u0026show_artwork=true\u0026show_comments=false\u0026maxwidth=100\u0026maxheight=100\u0026auto_play=false\"\u003E\u003C/iframe\u003E","author_name":"Forss","author_url":"http://soundcloud.com/forss"}'
+ FakeWeb.register_uri(:get, %r|http://soundcloud\.com/oembed|, :body => response)
+
result = auto_html('http://www.soundcloud.com/forss/flickermood') { soundcloud(:maxwidth => '100', :maxheight => '100', :auto_play => false, :show_comments => false) }
- assert_equal '<iframe width="100" height="100" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293&show_artwork=true&maxwidth=100&maxheight=100&auto_play=false&show_comments=false"></iframe>', result
+ assert_equal '<iframe width="100" height="100" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293&show_artwork=true&show_comments=false&maxwidth=100&maxheight=100&auto_play=false"></iframe>', result
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.