do not break oneboxes' favicon after updating favicons

This commit is contained in:
Régis Hanol 2013-09-30 19:09:57 +02:00
parent 57f7c794d7
commit 40c08eab14
3 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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