Skip to content

Commit

Permalink
Merge pull request #553 from octokit/check-for-valid-repo-string
Browse files Browse the repository at this point in the history
Ensure Repository is valid when passed a string. Fixes #552
  • Loading branch information
pengwynn committed Feb 13, 2015
2 parents 435963c + 450b969 commit 96f0042
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/octokit/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def initialize(repo)
@id = repo
when String
@owner, @name = repo.split('/')
unless @owner && @name
raise ArgumentError, "Invalid Repository. Use user/repo format."
end
when Repository
@owner = repo.owner
@name = repo.name
Expand Down
7 changes: 7 additions & 0 deletions spec/octokit/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
end
end

context "when passed a string without a slash" do
it "raises ArgumentError" do
expect { Octokit::Repository.new('raise-error') }.
to raise_error ArgumentError, "Invalid Repository. Use user/repo format."
end
end

describe ".path" do
context "with named repository" do
it "returns the url path" do
Expand Down

0 comments on commit 96f0042

Please sign in to comment.