diff --git a/lib/oneboxer/gist_onebox.rb b/lib/oneboxer/gist_onebox.rb index d64f05474ab..a3f63cb8638 100644 --- a/lib/oneboxer/gist_onebox.rb +++ b/lib/oneboxer/gist_onebox.rb @@ -7,22 +7,16 @@ module Oneboxer favicon 'github.png' def translate_url - m = @url.match(/gist\.github\.com\/(?[0-9a-f]+)/mi) + m = @url.match(/gist\.github\.com\/([^\/]+\/)?(?[0-9a-f]+)/mi) return "https://api.github.com/gists/#{m[:id]}" if m - @url end def parse(data) - parsed = JSON.parse(data) - result = {files: [], title: parsed['description']} - parsed['files'].each do |filename, attrs| result[:files] << {filename: filename}.merge!(attrs) end - - result end diff --git a/spec/components/oneboxer/gist_onebox_spec.rb b/spec/components/oneboxer/gist_onebox_spec.rb new file mode 100644 index 00000000000..9a8bf5fd4a3 --- /dev/null +++ b/spec/components/oneboxer/gist_onebox_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' +require 'oneboxer' +require 'oneboxer/gist_onebox' + +describe Oneboxer::GistOnebox do + it "does not trip on user names" do + o = Oneboxer::GistOnebox.new('https://gist.github.com/aaa/4599619') + o.translate_url.should == 'https://api.github.com/gists/4599619' + end + + it "works for old school urls too" do + o = Oneboxer::GistOnebox.new('https://gist.github.com/4599619') + o.translate_url.should == 'https://api.github.com/gists/4599619' + end +end +