add-to-org 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +24 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +100 -0
- data/Gemfile +3 -1
- data/Rakefile +5 -3
- data/add-to-org.gemspec +24 -21
- data/bower.json +1 -3
- data/lib/add-to-org/helpers.rb +6 -5
- data/lib/add-to-org/version.rb +3 -1
- data/lib/add-to-org/views/layout.erb +1 -12
- data/lib/add-to-org.rb +17 -18
- data/script/cibuild +1 -0
- data/spec/add-to-org-helpers_spec.rb +43 -40
- data/spec/add-to-org_spec.rb +72 -68
- data/spec/spec_helper.rb +14 -12
- metadata +73 -69
- data/.ruby-version +0 -1
- data/lib/add-to-org/public/vendor/bootstrap/.bower.json +0 -45
- data/lib/add-to-org/public/vendor/bootstrap/LICENSE +0 -21
- data/lib/add-to-org/public/vendor/bootstrap/bower.json +0 -34
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css +0 -587
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css.map +0 -1
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css +0 -6
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css.map +0 -1
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css +0 -6760
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css.map +0 -1
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css +0 -6
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css.map +0 -1
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +0 -288
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.js +0 -2363
- data/lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.min.js +0 -7
- data/lib/add-to-org/public/vendor/bootstrap/dist/js/npm.js +0 -13
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +0 -288
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/package.json +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d6e1d519910bd9dae03bcb2c8cea47fcebb6fb188c48d7103dfec6e1a40df664
|
4
|
+
data.tar.gz: 5ef8eb34932716326573c30beb922c55b2549bf5cb2d0ce2cd273ddd8ef409b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 336633b4e2062a6e8de5411bf38ae7cab6b085a626b7af679f83a880d5781d3713933df4bf5434d2b3f09b532dafe177364f88e02274fd2c8657540acfa7b983
|
7
|
+
data.tar.gz: 4b41e21b69c44f9109b47ba0408dc6ff63400d481bbc5738be4a035c35a0597a1e41d0d2045942749dba06fcf769d8e01561a6908a7b0009666f8e0cff6ce5b6
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- name: Checkout
|
15
|
+
uses: actions/checkout@v2
|
16
|
+
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 3.0
|
21
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
22
|
+
|
23
|
+
- name: Run tests
|
24
|
+
run: script/cibuild
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2021-10-07 20:24:39 UTC using RuboCop version 1.22.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Exclude:
|
14
|
+
- 'add-to-org.gemspec'
|
15
|
+
|
16
|
+
# Offense count: 3
|
17
|
+
# Configuration parameters: IgnoredMethods.
|
18
|
+
Lint/AmbiguousBlockAssociation:
|
19
|
+
Exclude:
|
20
|
+
- 'lib/add-to-org.rb'
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
# Configuration parameters: AllowedMethods.
|
24
|
+
# AllowedMethods: enums
|
25
|
+
Lint/ConstantDefinitionInBlock:
|
26
|
+
Exclude:
|
27
|
+
- 'spec/add-to-org-helpers_spec.rb'
|
28
|
+
|
29
|
+
# Offense count: 4
|
30
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
31
|
+
# IgnoredMethods: refine
|
32
|
+
Metrics/BlockLength:
|
33
|
+
Max: 88
|
34
|
+
|
35
|
+
# Offense count: 1
|
36
|
+
Naming/AccessorMethodName:
|
37
|
+
Exclude:
|
38
|
+
- 'lib/add-to-org.rb'
|
39
|
+
|
40
|
+
# Offense count: 3
|
41
|
+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
42
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
43
|
+
Naming/FileName:
|
44
|
+
Exclude:
|
45
|
+
- 'lib/add-to-org.rb'
|
46
|
+
- 'spec/add-to-org-helpers_spec.rb'
|
47
|
+
- 'spec/add-to-org_spec.rb'
|
48
|
+
|
49
|
+
# Offense count: 3
|
50
|
+
# Configuration parameters: IgnoredMetadata.
|
51
|
+
RSpec/DescribeClass:
|
52
|
+
Exclude:
|
53
|
+
- '**/spec/features/**/*'
|
54
|
+
- '**/spec/requests/**/*'
|
55
|
+
- '**/spec/routing/**/*'
|
56
|
+
- '**/spec/system/**/*'
|
57
|
+
- '**/spec/views/**/*'
|
58
|
+
- 'spec/add-to-org_spec.rb'
|
59
|
+
|
60
|
+
# Offense count: 6
|
61
|
+
# Configuration parameters: CountAsOne.
|
62
|
+
RSpec/ExampleLength:
|
63
|
+
Max: 16
|
64
|
+
|
65
|
+
# Offense count: 14
|
66
|
+
# Configuration parameters: AssignmentOnly.
|
67
|
+
RSpec/InstanceVariable:
|
68
|
+
Exclude:
|
69
|
+
- 'spec/add-to-org-helpers_spec.rb'
|
70
|
+
- 'spec/add-to-org_spec.rb'
|
71
|
+
|
72
|
+
# Offense count: 1
|
73
|
+
RSpec/LeakyConstantDeclaration:
|
74
|
+
Exclude:
|
75
|
+
- 'spec/add-to-org-helpers_spec.rb'
|
76
|
+
|
77
|
+
# Offense count: 1
|
78
|
+
RSpec/MultipleDescribes:
|
79
|
+
Exclude:
|
80
|
+
- 'spec/add-to-org_spec.rb'
|
81
|
+
|
82
|
+
# Offense count: 9
|
83
|
+
RSpec/MultipleExpectations:
|
84
|
+
Max: 6
|
85
|
+
|
86
|
+
# Offense count: 3
|
87
|
+
# Configuration parameters: AllowedConstants.
|
88
|
+
Style/Documentation:
|
89
|
+
Exclude:
|
90
|
+
- 'spec/**/*'
|
91
|
+
- 'test/**/*'
|
92
|
+
- 'lib/add-to-org.rb'
|
93
|
+
- 'lib/add-to-org/helpers.rb'
|
94
|
+
|
95
|
+
# Offense count: 1
|
96
|
+
# Cop supports --auto-correct.
|
97
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
98
|
+
# URISchemes: http, https
|
99
|
+
Layout/LineLength:
|
100
|
+
Max: 124
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems/package_task'
|
2
4
|
require 'rubygems/specification'
|
3
5
|
require 'bundler'
|
4
6
|
|
5
|
-
task :
|
7
|
+
task default: [:spec]
|
6
8
|
|
7
9
|
require 'rspec/core/rake_task'
|
8
|
-
desc
|
10
|
+
desc 'Run specs'
|
9
11
|
RSpec::Core::RakeTask.new do |t|
|
10
12
|
t.pattern = 'spec/**/*_spec.rb'
|
11
|
-
t.rspec_opts = [
|
13
|
+
t.rspec_opts = ['--order', 'rand', '--color']
|
12
14
|
end
|
data/add-to-org.gemspec
CHANGED
@@ -1,29 +1,32 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/add-to-org/version', __dir__)
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.summary =
|
6
|
-
s.description =
|
6
|
+
s.name = 'add-to-org'
|
7
|
+
s.summary = 'A simple Oauth App to automatically add users to an organization'
|
8
|
+
s.description = 'A simple Oauth App to automatically add users to an organization.'
|
7
9
|
s.version = AddToOrg::VERSION
|
8
|
-
s.authors = [
|
9
|
-
s.email =
|
10
|
-
s.homepage =
|
11
|
-
s.licenses = [
|
10
|
+
s.authors = ['Ben Balter']
|
11
|
+
s.email = 'ben.balter@github.com'
|
12
|
+
s.homepage = 'https://github.com/benbalter/add-to-org'
|
13
|
+
s.licenses = ['MIT']
|
12
14
|
|
13
15
|
s.files = `git ls-files`.split("\n")
|
14
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
-
s.require_paths = [
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
17
19
|
|
18
|
-
s.
|
19
|
-
s.add_dependency
|
20
|
-
s.add_dependency
|
21
|
-
s.add_dependency
|
22
|
-
s.add_dependency
|
23
|
-
s.
|
24
|
-
s.
|
25
|
-
s.add_development_dependency
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_development_dependency
|
20
|
+
s.add_dependency 'dotenv', '~> 2.0'
|
21
|
+
s.add_dependency 'octokit', '~> 4.0'
|
22
|
+
s.add_dependency 'rack-ssl-enforcer', '~> 0.2'
|
23
|
+
s.add_dependency 'rake'
|
24
|
+
s.add_dependency 'sinatra_auth_github', '~> 2.0'
|
25
|
+
s.add_development_dependency 'pry'
|
26
|
+
s.add_development_dependency 'rack-test'
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.1'
|
28
|
+
s.add_development_dependency 'rubocop'
|
29
|
+
s.add_development_dependency 'rubocop-performance'
|
30
|
+
s.add_development_dependency 'rubocop-rspec'
|
31
|
+
s.add_development_dependency 'webmock'
|
29
32
|
end
|
data/bower.json
CHANGED
data/lib/add-to-org/helpers.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AddToOrg
|
2
4
|
module Helpers
|
3
|
-
|
4
5
|
# query api for the user's verified emails
|
5
6
|
def verified_emails
|
6
|
-
emails = client.emails :
|
7
|
-
emails.select
|
7
|
+
emails = client.emails accept: 'application/vnd.github.v3'
|
8
|
+
emails.select(&:verified)
|
8
9
|
end
|
9
10
|
|
10
11
|
def valid?
|
@@ -15,12 +16,12 @@ module AddToOrg
|
|
15
16
|
|
16
17
|
# user client
|
17
18
|
def client
|
18
|
-
@client ||= Octokit::Client.new :
|
19
|
+
@client ||= Octokit::Client.new access_token: github_user.token
|
19
20
|
end
|
20
21
|
|
21
22
|
# org admin client
|
22
23
|
def sudo_client
|
23
|
-
@sudo_client ||= Octokit::Client.new :
|
24
|
+
@sudo_client ||= Octokit::Client.new access_token: ENV['GITHUB_TOKEN']
|
24
25
|
end
|
25
26
|
|
26
27
|
# true if user is already a member of the org
|
data/lib/add-to-org/version.rb
CHANGED
@@ -2,22 +2,11 @@
|
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8">
|
5
|
-
<meta
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
6
|
<title>Join <%= ENV['GITHUB_ORG_ID'] %></title>
|
8
|
-
|
9
|
-
<link rel="stylesheet" href="/vendor/bootstrap/dist/css/bootstrap.min.css">
|
10
|
-
<link rel="stylesheet" href="/vendor/bootstrap/dist/css/bootstrap-theme.min.css">
|
11
7
|
<style>
|
12
8
|
body { text-align: center; padding-top: 100px; }
|
13
9
|
</style>
|
14
|
-
|
15
|
-
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
16
|
-
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
17
|
-
<!--[if lt IE 9]>
|
18
|
-
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
19
|
-
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
20
|
-
<![endif]-->
|
21
10
|
</head>
|
22
11
|
<body>
|
23
12
|
<div class="container">
|
data/lib/add-to-org.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'octokit'
|
2
4
|
require 'sinatra_auth_github'
|
3
5
|
require 'dotenv'
|
4
6
|
require_relative 'add-to-org/helpers'
|
5
7
|
|
6
8
|
module AddToOrg
|
7
|
-
|
8
9
|
def self.root
|
9
|
-
File.expand_path
|
10
|
+
File.expand_path './add-to-org', File.dirname(__FILE__)
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.views_dir
|
13
|
-
@views_dir ||= File.expand_path
|
14
|
+
@views_dir ||= File.expand_path 'views', AddToOrg.root
|
14
15
|
end
|
15
16
|
|
16
17
|
def self.views_dir=(dir)
|
@@ -18,7 +19,7 @@ module AddToOrg
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.public_dir
|
21
|
-
@public_dir ||= File.expand_path
|
22
|
+
@public_dir ||= File.expand_path 'public', AddToOrg.root
|
22
23
|
end
|
23
24
|
|
24
25
|
def self.public_dir=(dir)
|
@@ -34,28 +35,27 @@ module AddToOrg
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def self.validator
|
37
|
-
@validator ||=
|
38
|
+
@validator ||= proc { raise 'You must define a custom validator to determine eligibility' }
|
38
39
|
end
|
39
40
|
|
40
41
|
class App < Sinatra::Base
|
41
|
-
|
42
42
|
include AddToOrg::Helpers
|
43
43
|
|
44
44
|
set :github_options, {
|
45
|
-
:
|
45
|
+
scopes: 'read:org,user:email'
|
46
46
|
}
|
47
47
|
|
48
48
|
use Rack::Session::Cookie, {
|
49
|
-
:
|
50
|
-
:
|
49
|
+
http_only: true,
|
50
|
+
secret: ENV['SESSION_SECRET'] || SecureRandom.hex
|
51
51
|
}
|
52
52
|
|
53
53
|
ENV['WARDEN_GITHUB_VERIFIER_SECRET'] ||= SecureRandom.hex
|
54
54
|
register Sinatra::Auth::Github
|
55
55
|
|
56
|
-
set :views,
|
57
|
-
set :root,
|
58
|
-
set :public_folder,
|
56
|
+
set :views, proc { AddToOrg.views_dir }
|
57
|
+
set :root, proc { AddToOrg.root }
|
58
|
+
set :public_folder, proc { AddToOrg.public_dir }
|
59
59
|
|
60
60
|
# require ssl
|
61
61
|
configure :production do
|
@@ -65,12 +65,12 @@ module AddToOrg
|
|
65
65
|
|
66
66
|
# dat auth
|
67
67
|
before do
|
68
|
-
session[:return_to] = request.url #store requested URL for post-auth redirect
|
68
|
+
session[:return_to] = request.url # store requested URL for post-auth redirect
|
69
69
|
authenticate!
|
70
70
|
end
|
71
71
|
|
72
|
-
def success(locals={})
|
73
|
-
halt erb :success, :
|
72
|
+
def success(locals = {})
|
73
|
+
halt erb :success, locals: locals
|
74
74
|
end
|
75
75
|
|
76
76
|
def forbidden
|
@@ -84,14 +84,13 @@ module AddToOrg
|
|
84
84
|
end
|
85
85
|
|
86
86
|
# request a GitHub (authenticated) URL
|
87
|
-
get
|
88
|
-
|
87
|
+
get '/*' do
|
89
88
|
path = request.path || "/#{team_id}"
|
90
89
|
halt redirect "https://github.com#{path}", 302 if member?
|
91
90
|
forbidden unless valid?
|
92
91
|
|
93
92
|
if add
|
94
|
-
success({ :
|
93
|
+
success({ redirect: "https://github.com#{path}", org_id: org_id })
|
95
94
|
else
|
96
95
|
error
|
97
96
|
end
|
data/script/cibuild
CHANGED
@@ -1,85 +1,88 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
|
+
describe 'AddToOrgHelpers' do
|
5
6
|
class TestHelper
|
6
7
|
include AddToOrg::Helpers
|
7
8
|
|
8
9
|
def github_user
|
9
|
-
User.make({
|
10
|
+
User.make({ 'login' => 'benbaltertest' }, 'asdf1234')
|
10
11
|
end
|
11
12
|
|
12
|
-
def initialize(path=nil)
|
13
|
+
def initialize(path = nil)
|
13
14
|
@path = path
|
14
15
|
end
|
15
16
|
|
16
17
|
def request
|
17
|
-
Rack::Request.new(
|
18
|
+
Rack::Request.new('PATH_INFO' => @path)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
before
|
22
|
+
before do
|
22
23
|
@helper = TestHelper.new
|
23
24
|
end
|
24
25
|
|
25
|
-
it
|
26
|
+
it 'initializes the client' do
|
26
27
|
expect(@helper.send(:client).class).to eql(Octokit::Client)
|
27
|
-
expect(@helper.send(:client).instance_variable_get(
|
28
|
+
expect(@helper.send(:client).instance_variable_get('@access_token')).to eql('asdf1234')
|
28
29
|
end
|
29
30
|
|
30
|
-
it
|
31
|
-
with_env
|
31
|
+
it 'initializes the sudo client' do
|
32
|
+
with_env 'GITHUB_TOKEN', 'SUDO_TOKEN' do
|
32
33
|
expect(@helper.send(:sudo_client).class).to eql(Octokit::Client)
|
33
|
-
expect(@helper.send(:sudo_client).instance_variable_get(
|
34
|
+
expect(@helper.send(:sudo_client).instance_variable_get('@access_token')).to eql('SUDO_TOKEN')
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
it
|
38
|
-
stub_request(:get,
|
39
|
-
|
40
|
-
expect(@helper.verified_emails.count).to
|
41
|
-
expect(@helper.verified_emails.first[:email]).to eql(
|
38
|
+
it 'retrieves a users verified emails' do
|
39
|
+
stub_request(:get, 'https://api.github.com/user/emails')
|
40
|
+
.to_return(status: 200, body: fixture('emails.json'), headers: { 'Content-Type' => 'application/json' })
|
41
|
+
expect(@helper.verified_emails.count).to be(1)
|
42
|
+
expect(@helper.verified_emails.first[:email]).to eql('octocat@github.com')
|
42
43
|
end
|
43
44
|
|
44
|
-
it
|
45
|
-
with_env
|
46
|
-
expect(@helper.send(:org_id)).to eql(
|
45
|
+
it 'retrieves the org id' do
|
46
|
+
with_env 'GITHUB_ORG_ID', 'some_org' do
|
47
|
+
expect(@helper.send(:org_id)).to eql('some_org')
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
it
|
51
|
-
with_env
|
52
|
-
expect(@helper.send(:team_id)).to eql(
|
51
|
+
it 'retrieves the team id' do
|
52
|
+
with_env 'GITHUB_TEAM_ID', '1234' do
|
53
|
+
expect(@helper.send(:team_id)).to eql('1234')
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
it
|
57
|
-
with_env
|
58
|
-
stub_request(:get,
|
59
|
-
|
60
|
-
expect(@helper.send(:member?)).to
|
57
|
+
it 'knows if a user is an org member' do
|
58
|
+
with_env 'GITHUB_ORG_ID', 'some_org' do
|
59
|
+
stub_request(:get, 'https://api.github.com/orgs/some_org/members/benbaltertest')
|
60
|
+
.to_return(status: 204)
|
61
|
+
expect(@helper.send(:member?)).to be(true)
|
61
62
|
|
62
|
-
stub_request(:get,
|
63
|
-
|
64
|
-
expect(@helper.send(:member?)).to
|
63
|
+
stub_request(:get, 'https://api.github.com/orgs/some_org/members/benbaltertest')
|
64
|
+
.to_return(status: 404)
|
65
|
+
expect(@helper.send(:member?)).to be(false)
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
it
|
69
|
-
with_env
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
it 'knows how to add a member to an org' do
|
70
|
+
with_env 'GITHUB_ORG_ID', 'some_org' do
|
71
|
+
with_env 'GITHUB_TEAM_ID', '1234' do
|
72
|
+
stub = stub_request(:put, 'https://api.github.com/teams/1234/memberships/benbaltertest')
|
73
|
+
.to_return(status: 204)
|
74
|
+
@helper.send(:add)
|
75
|
+
expect(stub).to have_been_requested
|
76
|
+
end
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
|
-
it
|
78
|
-
stub_request(:get,
|
79
|
-
to_return(:
|
80
|
+
it 'throws an error if valid? is not defined' do
|
81
|
+
stub_request(:get, 'https://api.github.com/user/emails')
|
82
|
+
.to_return(status: 200, body: fixture('emails.json'), headers: { 'Content-Type' => 'application/json' })
|
80
83
|
|
81
84
|
AddToOrg.validator = nil
|
82
|
-
error =
|
85
|
+
error = 'You must define a custom validator to determine eligibility'
|
83
86
|
expect { @helper.valid? }.to raise_error(error)
|
84
87
|
end
|
85
88
|
end
|