Permalink
Browse files

Add #team_member?

This allows checking for team membership analogous to #org_member?.
  • Loading branch information...
1 parent 664871e commit c80da4f9362ebcb1c9d8d332802b174a53009463 @fphilipe fphilipe committed Feb 1, 2013
Showing with 45 additions and 0 deletions.
  1. +19 −0 lib/octokit/client/organizations.rb
  2. +26 −0 spec/octokit/client/organizations_spec.rb
@@ -313,6 +313,25 @@ def remove_team_member(team_id, user, options={})
boolean_from_response(:delete, "teams/#{team_id}/members/#{user}", options)
end
+ # Check if a user is a member of a team.
+ #
+ # Use this to check if another user is a member of a team that
+ # you are a member.
+ #
+ # @param team_id [Integer] Team id.
+ # @param user [String] GitHub username of the user to check.
+ #
+ # @return [Boolean] Is a member?
+ #
+ # @see http://developer.github.com/v3/orgs/teams/#get-team-member
+ #
+ # @example Check if a user is in your team
+ # @client.team_member?('your_team', 'pengwynn')
+ # => false
+ def team_member?(team_id, user, options={})
+ boolean_from_response(:get, "teams/#{team_id}/members/#{user}", options)
+ end
+
# List team repositories
#
# Requires authenticated organization member.
@@ -222,6 +222,32 @@
end
+ describe ".team_member?" do
+
+ context "user is actually a member of the team" do
+
+ it "returns true" do
+ stub_get("https://api.github.com/teams/32598/members/pengwynn").
+ to_return(:status => 204)
+ is_team_member = @client.team_member?(32598, 'pengwynn')
+ expect(is_team_member).to eq(true)
+ end
+
+ end
+
+ context "user is not actually a member of the team" do
+
+ it "returns false" do
+ stub_get("https://api.github.com/teams/32598/members/joeyw").
+ to_return(:status => 404)
+ is_team_member = @client.team_member?(32598, 'joeyw')
+ expect(is_team_member).to be_false
+ end
+
+ end
+
+ end
+
describe ".remove_organization_member" do
it "removes a member from an organization" do
stub_delete("https://api.github.com/orgs/codeforamerica/members/glow-mdsol").

0 comments on commit c80da4f

Please sign in to comment.