Spec: Test a url helper function (#428)
This commit is contained in:
parent
5fde22461e
commit
828d639348
|
@ -79,7 +79,7 @@ module GitHubChangelogGenerator
|
||||||
last_response = client.last_response
|
last_response = client.last_response
|
||||||
|
|
||||||
if (last_pg = last_response.rels[:last])
|
if (last_pg = last_response.rels[:last])
|
||||||
parse_url_for_vars(last_pg.href)["page"].to_i
|
querystring_as_hash(last_pg.href)["page"].to_i
|
||||||
else
|
else
|
||||||
1
|
1
|
||||||
end
|
end
|
||||||
|
@ -307,16 +307,12 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
|
||||||
"#{@options[:user]}/#{@options[:project]}"
|
"#{@options[:user]}/#{@options[:project]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parses a URI and returns a hash of all GET variables
|
# Returns Hash of all querystring variables in given URI.
|
||||||
#
|
#
|
||||||
# @param [String] uri eg. https://api.github.com/repositories/43914960/tags?page=37&foo=1
|
# @param [String] uri eg. https://api.github.com/repositories/43914960/tags?page=37&foo=1
|
||||||
# @return [Hash] of all GET variables. eg. { 'page' => 37, 'foo' => 1 }
|
# @return [Hash] of all GET variables. eg. { 'page' => 37, 'foo' => 1 }
|
||||||
def parse_url_for_vars(uri)
|
def querystring_as_hash(uri)
|
||||||
URI(uri).query.split("&").each_with_object({}) do |get_var, params|
|
Hash[URI.decode_www_form(URI(uri).query || "")]
|
||||||
k, v = get_var.split("=")
|
|
||||||
params[k] = v
|
|
||||||
params
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -426,6 +426,20 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#querystring_as_hash" do
|
||||||
|
it "works on the blank URL" do
|
||||||
|
expect { fetcher.send(:querystring_as_hash, "") }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it "where there are no querystring params" do
|
||||||
|
expect { fetcher.send(:querystring_as_hash, "http://example.com") }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a String-keyed Hash of querystring params" do
|
||||||
|
expect(fetcher.send(:querystring_as_hash, "http://example.com/o.html?str=18&wis=12")).to include("wis" => "12", "str" => "18")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#fetch_commit" do
|
describe "#fetch_commit" do
|
||||||
context "when API call is valid", :vcr do
|
context "when API call is valid", :vcr do
|
||||||
it "returns commit" do
|
it "returns commit" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user