Permalink
Browse files

Added account name to enforcer

Signed-off-by: Nick Quaranto <nick@quaran.to>
  • Loading branch information...
1 parent 4aeb4b3 commit d3f87e9b00508051e2431d6ee19189c3ecbb101f @coreyhaines coreyhaines committed with qrush Jul 13, 2009
Showing with 30 additions and 28 deletions.
  1. +15 −13 features/manage_collaborators.feature
  2. +6 −3 features/step_definitions/enforcer_steps.rb
  3. +6 −5 lib/enforcer.rb
  4. +3 −7 test/enforcer_test.rb
@@ -1,17 +1,19 @@
Feature: Manage collaborators
+ Background:
+ Given an account "thoughtbot"
Scenario: Adding a single collaborator for a specific project
- Given the following collaborators for "shoulda"
- |name |
- |thoughtbot|
- Given I am adding "rmmt" as a collaborator to "shoulda"
- """
- Enforcer "thoughtbot" do
- project "shoulda" do
- collaborators 'rmmt'
- end
- end
- """
- When I execute it
- Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda"
+ Given the following collaborators for "shoulda"
+ |name |
+ |thoughtbot|
+ Given I am adding "rmmt" as a collaborator to "shoulda"
+ """
+ Enforcer "thoughtbot" do
+ project "shoulda" do
+ collaborators 'rmmt'
+ end
+ end
+ """
+ When I execute it
+ Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda"
@@ -1,10 +1,13 @@
+Given /^an account "(.*)"$/ do |account|
+ @account = account
+end
+
Given /^I am adding "(.*)" as a collaborator to "(.*)"$/ do |user, repo, code|
@names << user
@names_list = @names.join('", "')
@collaborators = '{"collaborators: + ["' + @names_list + '"]}'
- mock(GitHubApi).add_collaborator(repo, user)
-# FakeWeb.register_uri(:post, "http://github.com/api/v2/json/repos/collaborators/#{@repo}/#{@user}", :string => @collaborators)
+ mock(GitHubApi).add_collaborator(@account, repo, user)
@code = code
end
@@ -20,6 +23,6 @@
end
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
View
@@ -2,15 +2,16 @@
require 'github_api'
class Enforcer
- def initialize(user_name)
+ def initialize(account_name)
+ @account_name = account_name
end
def project(project_name, &block)
instance_eval(&block)
return if @collaborators.nil?
@collaborators.each do |collaborator|
- GitHubApi.add_collaborator(project_name, collaborator)
+ GitHubApi.add_collaborator(@account_name, project_name, collaborator)
end
end
@@ -19,7 +20,7 @@ def collaborators(*names)
end
end
-def Enforcer(user_name, &block)
- enforcer = Enforcer.new(user_name)
- enforcer.instance_eval(&block)
+def Enforcer(account_name, &block)
+ enforcer = Enforcer.new(account_name)
+ enforcer.instance_eval(&block)
end
View
@@ -3,22 +3,18 @@
class EnforcerTest < Test::Unit::TestCase
context "with an enforcer" do
setup do
- stub(GitHubApi).add_collaborator(anything, anything)
+ stub(GitHubApi).add_collaborator(anything, anything, anything)
@username = "user"
@enforcer = Enforcer.new(@username)
end
- #should "store username" do
- #assert_equal @username, @enforcer.username
- #end
-
- should "adds the collaborators to the project" do
+ should "add collaborators to the project" do
@enforcer.project 'foo' do
collaborators 'chaines'
end
assert_received(GitHubApi) do |subject|
- subject.add_collaborator('foo', 'chaines')
+ subject.add_collaborator(@username, 'foo', 'chaines')
end
end
end

0 comments on commit d3f87e9

Please sign in to comment.