Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Added account name to enforcer
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Quaranto <nick@quaran.to>
  • Loading branch information
coreyhaines authored and qrush committed Jul 13, 2009
1 parent 4aeb4b3 commit d3f87e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
28 changes: 15 additions & 13 deletions features/manage_collaborators.feature
@@ -1,17 +1,19 @@
Feature: Manage collaborators Feature: Manage collaborators
Background:
Given an account "thoughtbot"


Scenario: Adding a single collaborator for a specific project Scenario: Adding a single collaborator for a specific project
Given the following collaborators for "shoulda" Given the following collaborators for "shoulda"
|name | |name |
|thoughtbot| |thoughtbot|
Given I am adding "rmmt" as a collaborator to "shoulda" Given I am adding "rmmt" as a collaborator to "shoulda"
""" """
Enforcer "thoughtbot" do Enforcer "thoughtbot" do
project "shoulda" do project "shoulda" do
collaborators 'rmmt' collaborators 'rmmt'
end end
end end
""" """
When I execute it When I execute it
Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda" Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda"


9 changes: 6 additions & 3 deletions features/step_definitions/enforcer_steps.rb
@@ -1,10 +1,13 @@
Given /^an account "(.*)"$/ do |account|
@account = account
end

Given /^I am adding "(.*)" as a collaborator to "(.*)"$/ do |user, repo, code| Given /^I am adding "(.*)" as a collaborator to "(.*)"$/ do |user, repo, code|
@names << user @names << user
@names_list = @names.join('", "') @names_list = @names.join('", "')
@collaborators = '{"collaborators: + ["' + @names_list + '"]}' @collaborators = '{"collaborators: + ["' + @names_list + '"]}'


mock(GitHubApi).add_collaborator(repo, user) mock(GitHubApi).add_collaborator(@account, repo, user)
# FakeWeb.register_uri(:post, "http://github.com/api/v2/json/repos/collaborators/#{@repo}/#{@user}", :string => @collaborators)
@code = code @code = code
end end


Expand All @@ -20,6 +23,6 @@
end end


Then /^the GitHub API should have received a request to add a "(.*)" as a collaborator for "(.*)"$/ do |user, repo| Then /^the GitHub API should have received a request to add a "(.*)" as a collaborator for "(.*)"$/ do |user, repo|
assert_received(GitHubApi) { |subject| subject.add_collaborator(repo, user) } assert_received(GitHubApi) { |subject| subject.add_collaborator(@account, repo, user) }
end end


11 changes: 6 additions & 5 deletions lib/enforcer.rb
Expand Up @@ -2,15 +2,16 @@
require 'github_api' require 'github_api'


class Enforcer class Enforcer
def initialize(user_name) def initialize(account_name)
@account_name = account_name
end end


def project(project_name, &block) def project(project_name, &block)
instance_eval(&block) instance_eval(&block)
return if @collaborators.nil? return if @collaborators.nil?


@collaborators.each do |collaborator| @collaborators.each do |collaborator|
GitHubApi.add_collaborator(project_name, collaborator) GitHubApi.add_collaborator(@account_name, project_name, collaborator)
end end
end end


Expand All @@ -19,7 +20,7 @@ def collaborators(*names)
end end
end end


def Enforcer(user_name, &block) def Enforcer(account_name, &block)
enforcer = Enforcer.new(user_name) enforcer = Enforcer.new(account_name)
enforcer.instance_eval(&block) enforcer.instance_eval(&block)
end end
10 changes: 3 additions & 7 deletions test/enforcer_test.rb
Expand Up @@ -3,22 +3,18 @@
class EnforcerTest < Test::Unit::TestCase class EnforcerTest < Test::Unit::TestCase
context "with an enforcer" do context "with an enforcer" do
setup do setup do
stub(GitHubApi).add_collaborator(anything, anything) stub(GitHubApi).add_collaborator(anything, anything, anything)
@username = "user" @username = "user"
@enforcer = Enforcer.new(@username) @enforcer = Enforcer.new(@username)
end end


#should "store username" do should "add collaborators to the project" do
#assert_equal @username, @enforcer.username
#end

should "adds the collaborators to the project" do
@enforcer.project 'foo' do @enforcer.project 'foo' do
collaborators 'chaines' collaborators 'chaines'
end end


assert_received(GitHubApi) do |subject| assert_received(GitHubApi) do |subject|
subject.add_collaborator('foo', 'chaines') subject.add_collaborator(@username, 'foo', 'chaines')
end end
end end
end end
Expand Down

0 comments on commit d3f87e9

Please sign in to comment.