From 40c08eab14f8f0889b7cc1b655192890b94ee1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 30 Sep 2013 19:09:57 +0200 Subject: [PATCH] do not break oneboxes' favicon after updating favicons --- lib/oneboxer/base_onebox.rb | 2 +- lib/oneboxer/handlebars_onebox.rb | 5 +++-- .../oneboxer/handlebars_onebox_spec.rb | 20 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/oneboxer/base_onebox.rb b/lib/oneboxer/base_onebox.rb index f0d4c3e53..b81873300 100644 --- a/lib/oneboxer/base_onebox.rb +++ b/lib/oneboxer/base_onebox.rb @@ -29,7 +29,7 @@ module Oneboxer end def uriencode(val) - return URI.escape(val, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) + URI.escape(val, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end end diff --git a/lib/oneboxer/handlebars_onebox.rb b/lib/oneboxer/handlebars_onebox.rb index 485655964..abe353e8b 100644 --- a/lib/oneboxer/handlebars_onebox.rb +++ b/lib/oneboxer/handlebars_onebox.rb @@ -39,9 +39,10 @@ module Oneboxer html = fetch_html args = parse(html) return default_url unless args.present? + args[:original_url] = @url args[:lang] = @lang || "" - args[:favicon] = ActionController::Base.helpers.image_path(self.class.favicon_file) if self.class.favicon_file.present? + args[:favicon] = ActionController::Base.helpers.asset_path(self.class.favicon_file, digest: false) if self.class.favicon_file.present? args[:host] = nice_host HandlebarsOnebox.generate_onebox(template,args) @@ -51,7 +52,7 @@ module Oneboxer default_url end - def self.generate_onebox(template, args) + def self.generate_onebox(template, args={}) Mustache.render(File.read(template), args) end diff --git a/spec/components/oneboxer/handlebars_onebox_spec.rb b/spec/components/oneboxer/handlebars_onebox_spec.rb index d8bbde389..6d1c50f5e 100644 --- a/spec/components/oneboxer/handlebars_onebox_spec.rb +++ b/spec/components/oneboxer/handlebars_onebox_spec.rb @@ -3,9 +3,10 @@ require 'oneboxer' require 'oneboxer/handlebars_onebox' describe Oneboxer::HandlebarsOnebox do - H = Oneboxer::HandlebarsOnebox describe 'simple onebox' do + H = Oneboxer::HandlebarsOnebox + it "is able to render image size when specified" do template = H.template_path('simple_onebox') result = H.generate_onebox(template, 'image_width' => 100, 'image_height' => 100, image: 'http://my.com/image.png') @@ -13,5 +14,22 @@ describe Oneboxer::HandlebarsOnebox do result.should =~ /width=/ result.should =~ /height=/ end + + class SimpleOnebox < Oneboxer::HandlebarsOnebox + favicon 'stackexchange.png' + + def parse(html) + { testing: true } + end + end + + it "does not use fingerprint on favicons" do + onebox = SimpleOnebox.new "http://domain.com" + onebox.stubs(:fetch_html).returns("") + ActionController::Base.helpers.expects(:asset_path).with('favicons/stackexchange.png', digest: false) + result = onebox.onebox + end + end + end