Skip to content

Commit

Permalink
Add spec for RepoAuthorList.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed May 25, 2012
1 parent 3b197f4 commit 405dc18
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/gitsucker/author.rb
Expand Up @@ -28,6 +28,14 @@ def ruby_repo_count
github_profile.ruby_repo_count
end

def ==(other)
if other.is_a?(Author)
name == other.name
else
super
end
end

private

def github_profile
Expand Down
2 changes: 1 addition & 1 deletion lib/gitsucker/repo_author_list.rb
Expand Up @@ -5,7 +5,7 @@ def initialize(repo_name)
end

def authors
@authors ||= author_names.map { Author.new(name) }
@authors ||= author_names.map { |author_name| Author.new(author_name) }
end

private
Expand Down
15 changes: 15 additions & 0 deletions spec/gitsucker/author_spec.rb
Expand Up @@ -12,6 +12,21 @@
end
end

describe Gitsucker::Author, '#==' do
it 'returns true for two authors with the same name' do
Gitsucker::Author.new('same').should == Gitsucker::Author.new('same')
end

it 'returns false for two authors with different names' do
Gitsucker::Author.new('one').should_not == Gitsucker::Author.new('two')
end

it 'returns false for an author and a non-authors with the same name' do
non_author = stub('non-Author', :name => 'same')
Gitsucker::Author.new('same').should_not == non_author
end
end

This comment has been minimized.

Copy link
@adarsh

adarsh Jul 27, 2012

Interesting, although github authornames == usernames, which are unique.

This comment has been minimized.

Copy link
@gabebw

gabebw Jul 27, 2012

Owner

Touché. Not sure why I added this, honestly - I think I was just upping the test coverage.

This comment has been minimized.

Copy link
@adarsh

adarsh Jul 27, 2012

I want YOU to want to wear flair.

%w(original_repo_count forked_repo_count js_repo_count ruby_repo_count).each do |method_name|
describe Gitsucker::Author, "##{method_name}" do
it 'delegates to the github profile' do
Expand Down
29 changes: 29 additions & 0 deletions spec/gitsucker/repo_author_list_spec.rb
@@ -0,0 +1,29 @@
require 'spec_helper'

describe Gitsucker::RepoAuthorList do
let(:repo_name) { 'kangaroo' }
it 'shows correct authors' do
stub_github_repo_name_authors(repo_name, %w(one two))
repo_author_list = Gitsucker::RepoAuthorList.new(repo_name)
repo_author_list.authors.should == [Gitsucker::Author.new('one'),
Gitsucker::Author.new('two')]
end

def stub_github_repo_name_authors(repo_name, authors)
ShamRack.at('api.github.com', 443).sinatra do
authors.each do |author|
get "/repos/#{author}/#{repo_name}/forks" do
owner_hashes = authors.map do |login|
{ :owner => { :login => login } }
end
JSON.dump(owner_hashes)
end
end

get "/legacy/repos/search/#{repo_name}" do
usernames = authors.map { |author| { :username => author } }
JSON.dump({ :repositories => usernames })
end
end
end
end

0 comments on commit 405dc18

Please sign in to comment.