Browse files

Adding api key

Signed-off-by: Nick Quaranto <nick@quaran.to>
  • Loading branch information...
1 parent d3f87e9 commit 7356ea1ee2d0820b5582f0a3da9b4e73fb253dcf @coreyhaines coreyhaines committed with qrush Jul 13, 2009
View
4 features/manage_collaborators.feature
@@ -1,14 +1,14 @@
Feature: Manage collaborators
Background:
- Given an account "thoughtbot"
+ Given an account "thoughtbot" with an api key of "deadbeef"
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
+ Enforcer "thoughtbot", "deadbeef" do
project "shoulda" do
collaborators 'rmmt'
end
View
7 features/step_definitions/enforcer_steps.rb
@@ -1,13 +1,14 @@
-Given /^an account "(.*)"$/ do |account|
+Given /^an account "(.*)" with an api key of "(.*)"$/ do |account, api_key|
@account = account
+ @api_key = api_key
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(@account, repo, user)
+ mock(GitHubApi).add_collaborator(@account, @api_key, repo, user)
@code = code
end
@@ -23,6 +24,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(@account, repo, user) }
+ assert_received(GitHubApi) { |subject| subject.add_collaborator(@account, @api_key, repo, user) }
end
View
9 lib/enforcer.rb
@@ -2,16 +2,17 @@
require 'github_api'
class Enforcer
- def initialize(account_name)
+ def initialize(account_name, api_key)
@account_name = account_name
+ @api_key = api_key
end
def project(project_name, &block)
instance_eval(&block)
return if @collaborators.nil?
@collaborators.each do |collaborator|
- GitHubApi.add_collaborator(@account_name, project_name, collaborator)
+ GitHubApi.add_collaborator(@account_name, @api_key, project_name, collaborator)
end
end
@@ -20,7 +21,7 @@ def collaborators(*names)
end
end
-def Enforcer(account_name, &block)
- enforcer = Enforcer.new(account_name)
+def Enforcer(account_name, api_key, &block)
+ enforcer = Enforcer.new(account_name, api_key)
enforcer.instance_eval(&block)
end
View
12 test/enforcer_test.rb
@@ -3,9 +3,10 @@
class EnforcerTest < Test::Unit::TestCase
context "with an enforcer" do
setup do
- stub(GitHubApi).add_collaborator(anything, anything, anything)
+ stub(GitHubApi).add_collaborator(anything, anything, anything, anything)
@username = "user"
- @enforcer = Enforcer.new(@username)
+ @api_key = "api key"
+ @enforcer = Enforcer.new(@username, @api_key)
end
should "add collaborators to the project" do
@@ -14,7 +15,7 @@ class EnforcerTest < Test::Unit::TestCase
end
assert_received(GitHubApi) do |subject|
- subject.add_collaborator(@username, 'foo', 'chaines')
+ subject.add_collaborator(@username, @api_key, 'foo', 'chaines')
end
end
end
@@ -25,10 +26,11 @@ class EnforcerTest < Test::Unit::TestCase
stub(@enforcer).project(anything)
@username = "thoughtbot"
- mock(Enforcer).new(@username) { @enforcer }
+ @api_key = "api key"
+ mock(Enforcer).new(@username, @api_key) { @enforcer }
end
should "be there and take a string and block" do
- Enforcer("thoughtbot") { project("corey") {} }
+ Enforcer(@username, @api_key) { project("corey") {} }
assert_received(@enforcer) { |subject| subject.project("corey") }
end
end
View
3 test/github_api_test.rb
@@ -7,8 +7,7 @@ class GitHubApiTest < Test::Unit::TestCase
@repo = "repo"
@user = "coreyhaines" + rand(10).to_s
@collaborators = '{"collaborators": ["qrush", "'+ @user +'"]}'
-# FakeWeb.register_uri(:post, "http://github.com/api/v2/json/repos/collaborators/#{@repo}/#{@user}", :string => @collaborators)
-# stub(GitHubApi).post(
+ stub(GitHubApi).post("http://github.com/api/v2/json/repos/collaborators/#{@repo}/add/#{@user}") { @collaborators }
end
should "hit the github api" do

0 comments on commit 7356ea1

Please sign in to comment.