Skip to content

Commit

Permalink
Add spec and fixtures for successful check
Browse files Browse the repository at this point in the history
  • Loading branch information
jdennes committed Jun 9, 2014
1 parent 8007252 commit b3e0fd8
Show file tree
Hide file tree
Showing 8 changed files with 456 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/contribution-checker/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def commit_in_valid_branch?

# The compare status should be "identical" or "behind" if the commit is in
# the default branch
unless default_compare &&
%w(identical behind).include?(default_compare[:status])
if default_compare.nil? ||
!(%w(identical behind).include?(default_compare[:status]))

# If the commit is not in the default branch, check the gh-pages branch
begin
Expand Down Expand Up @@ -171,7 +171,7 @@ def user_has_starred_repo?
#
# @return [Boolean]
def user_is_repo_org_member?
false if @repo[:owner] != "Organization"
return false if @repo[:owner] != "Organization"
@client.organization_member? @repo[:owner][:login], @user[:login]
end

Expand Down
39 changes: 39 additions & 0 deletions spec/contribution-checker/checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,45 @@
end
end

context "when a commit is successfully checked" do
let(:checker) { checker = ContributionChecker::Checker.new \
:access_token => "token",
:commit_url => "https://github.com/jdennes/contribution-checker/commit/731e83d4abf1bd67ac6ab68d18387693482e47cf"
}

before do
stub_get("/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf").
to_return(json_response("commit.json"))
stub_get("/repos/jdennes/contribution-checker").
to_return(json_response("repo.json"))
stub_get("/user").
to_return(json_response("user.json"))
stub_get("/repos/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf").
to_return(json_response("default_compare.json"))
stub_get("/user/emails").
to_return(json_response("emails.json"))
stub_get("/user/starred/jdennes/contribution-checker").
to_return(:return => 404)
end

it "returns the check result" do
result = checker.check
expect(result).to be_a(Hash)

expect(result[:contribution]).to eq(true)

expect(result[:and_criteria][:commit_in_valid_branch]).to eq(true)
expect(result[:and_criteria][:commit_in_last_year]).to eq(true)
expect(result[:and_criteria][:repo_not_a_fork]).to eq(true)
expect(result[:and_criteria][:commit_email_linked_to_user]).to eq(true)

expect(result[:or_criteria][:user_has_starred_repo]).to eq(false)
expect(result[:or_criteria][:user_can_push_to_repo]).to eq(true)
expect(result[:or_criteria][:user_is_repo_org_member]).to eq(false)
expect(result[:or_criteria][:user_has_fork_of_repo]).to eq(false)
end
end

end

end
89 changes: 89 additions & 0 deletions spec/fixtures/commit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"sha": "731e83d4abf1bd67ac6ab68d18387693482e47cf",
"commit": {
"author": {
"name": "James Dennes",
"email": "[email protected]",
"date": "2014-06-08T10:25:34Z"
},
"committer": {
"name": "James Dennes",
"email": "[email protected]",
"date": "2014-06-08T10:25:34Z"
},
"message": "Version 0.0.2",
"tree": {
"sha": "30d937ac96b77183e8df7f319acc1e4387516981",
"url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees/30d937ac96b77183e8df7f319acc1e4387516981"
},
"url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf",
"comment_count": 0
},
"url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf",
"html_url": "https://github.com/jdennes/contribution-checker/commit/731e83d4abf1bd67ac6ab68d18387693482e47cf",
"comments_url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf/comments",
"author": {
"login": "jdennes",
"id": 65057,
"avatar_url": "https://avatars.githubusercontent.com/u/65057?",
"gravatar_id": "55fd031da91ef9af6e6ed88b101416a1",
"url": "https://api.github.com/users/jdennes",
"html_url": "https://github.com/jdennes",
"followers_url": "https://api.github.com/users/jdennes/followers",
"following_url": "https://api.github.com/users/jdennes/following{/other_user}",
"gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdennes/subscriptions",
"organizations_url": "https://api.github.com/users/jdennes/orgs",
"repos_url": "https://api.github.com/users/jdennes/repos",
"events_url": "https://api.github.com/users/jdennes/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdennes/received_events",
"type": "User",
"site_admin": true
},
"committer": {
"login": "jdennes",
"id": 65057,
"avatar_url": "https://avatars.githubusercontent.com/u/65057?",
"gravatar_id": "55fd031da91ef9af6e6ed88b101416a1",
"url": "https://api.github.com/users/jdennes",
"html_url": "https://github.com/jdennes",
"followers_url": "https://api.github.com/users/jdennes/followers",
"following_url": "https://api.github.com/users/jdennes/following{/other_user}",
"gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdennes/subscriptions",
"organizations_url": "https://api.github.com/users/jdennes/orgs",
"repos_url": "https://api.github.com/users/jdennes/repos",
"events_url": "https://api.github.com/users/jdennes/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdennes/received_events",
"type": "User",
"site_admin": true
},
"parents": [
{
"sha": "5514532ab61216d1d7d242fd624a2f215d225a31",
"url": "https://api.github.com/repos/jdennes/contribution-checker/commits/5514532ab61216d1d7d242fd624a2f215d225a31",
"html_url": "https://github.com/jdennes/contribution-checker/commit/5514532ab61216d1d7d242fd624a2f215d225a31"
}
],
"stats": {
"total": 2,
"additions": 1,
"deletions": 1
},
"files": [
{
"sha": "d8853e79dea5d3235cb470f4ea1de0ec2d17bcb5",
"filename": "lib/contribution-checker/version.rb",
"status": "modified",
"additions": 1,
"deletions": 1,
"changes": 2,
"blob_url": "https://github.com/jdennes/contribution-checker/blob/731e83d4abf1bd67ac6ab68d18387693482e47cf/lib/contribution-checker/version.rb",
"raw_url": "https://github.com/jdennes/contribution-checker/raw/731e83d4abf1bd67ac6ab68d18387693482e47cf/lib/contribution-checker/version.rb",
"contents_url": "https://api.github.com/repos/jdennes/contribution-checker/contents/lib/contribution-checker/version.rb?ref=731e83d4abf1bd67ac6ab68d18387693482e47cf",
"patch": "@@ -1,3 +1,3 @@\n module ContributionChecker\n- VERSION = \"0.0.1\"\n+ VERSION = \"0.0.2\"\n end"
}
]
}
157 changes: 157 additions & 0 deletions spec/fixtures/default_compare.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"url": "https://api.github.com/repos/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf",
"html_url": "https://github.com/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf",
"permalink_url": "https://github.com/jdennes/contribution-checker/compare/jdennes:8007252...jdennes:731e83d",
"diff_url": "https://github.com/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf.diff",
"patch_url": "https://github.com/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf.patch",
"base_commit": {
"sha": "80072520cb4a9dc70dabbc61492d94c962abdc0b",
"commit": {
"author": {
"name": "James Dennes",
"email": "[email protected]",
"date": "2014-06-08T22:47:15Z"
},
"committer": {
"name": "James Dennes",
"email": "[email protected]",
"date": "2014-06-08T22:47:15Z"
},
"message": "Add ContributionChecker::InvalidAccessTokenError",
"tree": {
"sha": "bad7a5547a5b973d74492aba53adb1da02aecb9c",
"url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees/bad7a5547a5b973d74492aba53adb1da02aecb9c"
},
"url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits/80072520cb4a9dc70dabbc61492d94c962abdc0b",
"comment_count": 0
},
"url": "https://api.github.com/repos/jdennes/contribution-checker/commits/80072520cb4a9dc70dabbc61492d94c962abdc0b",
"html_url": "https://github.com/jdennes/contribution-checker/commit/80072520cb4a9dc70dabbc61492d94c962abdc0b",
"comments_url": "https://api.github.com/repos/jdennes/contribution-checker/commits/80072520cb4a9dc70dabbc61492d94c962abdc0b/comments",
"author": {
"login": "jdennes",
"id": 65057,
"avatar_url": "https://avatars.githubusercontent.com/u/65057?",
"gravatar_id": "55fd031da91ef9af6e6ed88b101416a1",
"url": "https://api.github.com/users/jdennes",
"html_url": "https://github.com/jdennes",
"followers_url": "https://api.github.com/users/jdennes/followers",
"following_url": "https://api.github.com/users/jdennes/following{/other_user}",
"gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdennes/subscriptions",
"organizations_url": "https://api.github.com/users/jdennes/orgs",
"repos_url": "https://api.github.com/users/jdennes/repos",
"events_url": "https://api.github.com/users/jdennes/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdennes/received_events",
"type": "User",
"site_admin": true
},
"committer": {
"login": "jdennes",
"id": 65057,
"avatar_url": "https://avatars.githubusercontent.com/u/65057?",
"gravatar_id": "55fd031da91ef9af6e6ed88b101416a1",
"url": "https://api.github.com/users/jdennes",
"html_url": "https://github.com/jdennes",
"followers_url": "https://api.github.com/users/jdennes/followers",
"following_url": "https://api.github.com/users/jdennes/following{/other_user}",
"gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdennes/subscriptions",
"organizations_url": "https://api.github.com/users/jdennes/orgs",
"repos_url": "https://api.github.com/users/jdennes/repos",
"events_url": "https://api.github.com/users/jdennes/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdennes/received_events",
"type": "User",
"site_admin": true
},
"parents": [
{
"sha": "1a048d7745c5ea48eff015063f49369d6c7c3913",
"url": "https://api.github.com/repos/jdennes/contribution-checker/commits/1a048d7745c5ea48eff015063f49369d6c7c3913",
"html_url": "https://github.com/jdennes/contribution-checker/commit/1a048d7745c5ea48eff015063f49369d6c7c3913"
}
]
},
"merge_base_commit": {
"sha": "731e83d4abf1bd67ac6ab68d18387693482e47cf",
"commit": {
"author": {
"name": "James Dennes",
"email": "[email protected]",
"date": "2014-06-08T10:25:34Z"
},
"committer": {
"name": "James Dennes",
"email": "[email protected]",
"date": "2014-06-08T10:25:34Z"
},
"message": "Version 0.0.2",
"tree": {
"sha": "30d937ac96b77183e8df7f319acc1e4387516981",
"url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees/30d937ac96b77183e8df7f319acc1e4387516981"
},
"url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf",
"comment_count": 0
},
"url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf",
"html_url": "https://github.com/jdennes/contribution-checker/commit/731e83d4abf1bd67ac6ab68d18387693482e47cf",
"comments_url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf/comments",
"author": {
"login": "jdennes",
"id": 65057,
"avatar_url": "https://avatars.githubusercontent.com/u/65057?",
"gravatar_id": "55fd031da91ef9af6e6ed88b101416a1",
"url": "https://api.github.com/users/jdennes",
"html_url": "https://github.com/jdennes",
"followers_url": "https://api.github.com/users/jdennes/followers",
"following_url": "https://api.github.com/users/jdennes/following{/other_user}",
"gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdennes/subscriptions",
"organizations_url": "https://api.github.com/users/jdennes/orgs",
"repos_url": "https://api.github.com/users/jdennes/repos",
"events_url": "https://api.github.com/users/jdennes/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdennes/received_events",
"type": "User",
"site_admin": true
},
"committer": {
"login": "jdennes",
"id": 65057,
"avatar_url": "https://avatars.githubusercontent.com/u/65057?",
"gravatar_id": "55fd031da91ef9af6e6ed88b101416a1",
"url": "https://api.github.com/users/jdennes",
"html_url": "https://github.com/jdennes",
"followers_url": "https://api.github.com/users/jdennes/followers",
"following_url": "https://api.github.com/users/jdennes/following{/other_user}",
"gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdennes/subscriptions",
"organizations_url": "https://api.github.com/users/jdennes/orgs",
"repos_url": "https://api.github.com/users/jdennes/repos",
"events_url": "https://api.github.com/users/jdennes/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdennes/received_events",
"type": "User",
"site_admin": true
},
"parents": [
{
"sha": "5514532ab61216d1d7d242fd624a2f215d225a31",
"url": "https://api.github.com/repos/jdennes/contribution-checker/commits/5514532ab61216d1d7d242fd624a2f215d225a31",
"html_url": "https://github.com/jdennes/contribution-checker/commit/5514532ab61216d1d7d242fd624a2f215d225a31"
}
]
},
"status": "behind",
"ahead_by": 0,
"behind_by": 10,
"total_commits": 0,
"commits": [

],
"files": [

]
}
12 changes: 12 additions & 0 deletions spec/fixtures/emails.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"email": "[email protected]",
"primary": false,
"verified": true
},
{
"email": "[email protected]",
"primary": true,
"verified": true
}
]
Loading

0 comments on commit b3e0fd8

Please sign in to comment.