Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/gist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def shorten(url)
response = http(GIT_IO_URL, request)
case response.code
when "200"
URI.join(GIT_IO_URL, response.body)
URI.join(GIT_IO_URL, response.body).to_s
when "201"
response['Location']
else
Expand Down
12 changes: 8 additions & 4 deletions spec/shorten_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
describe '...' do
before do
stub_request(:post, /api\.github.com\/gists/).to_return(:body => '{"html_url": "http://github.com/"}')
stub_request(:post, "http://git.io/").to_return(:status => 201, :headers => { 'Location' => 'http://git.io/XXXXXX' })
end

it "should return a shortened version of the URL" do
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "http://git.io/XXXXXX"
it "should return a shortened version of the URL when response is 200" do
stub_request(:post, "https://git.io/create").to_return(:status => 200, :body => 'XXXXXX')
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
end
end

it "should return a shortened version of the URL when response is 201" do
stub_request(:post, "https://git.io/create").to_return(:status => 201, :headers => { 'Location' => 'https://git.io/XXXXXX' })
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
end
end