warden-github-rails 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0d71776d5d7ebaad54e82b9acc5483d13bc1690
4
- data.tar.gz: 0955b110b3602bf13205c7c401d7194e59f27d17
3
+ metadata.gz: 37e76cad468bc0b04658632d0eb31771dede50b3
4
+ data.tar.gz: c6fecc13ba562142149e111f77030bf853b3cbb8
5
5
  SHA512:
6
- metadata.gz: 2772ed766c5f10da6b5799f981041584fcd0c31acfdb22be76c545983b8693df167f884c26890dc4f36231e4ec05c031278ee1d3d8a1a122b9fb6a97409008c7
7
- data.tar.gz: 181144304f3d540561f809068df3fb93321f9a8625a5993df865de8e300cd970afb63aaeba6afab1e3b82134701e070500b71fb604ac2ee5bd44c7b25196b2d0
6
+ metadata.gz: 9a6f23ae1e3bb517759c974626c446c248cd8856fa103a8ea3c307266ef3cc713da76bd133531b7bdaf4254291a2c041f5034d0812d0fe5b43e18eb238054c46
7
+ data.tar.gz: f5fe6318363b452b5556ce99949ded463fcd86c4f7a33c484b91edc50daa4d5bed824af1d7a85c054740687a1f1b21a869d0a09104d03c7177905221c3efbea1
data/.travis.yml CHANGED
@@ -5,3 +5,35 @@ rvm:
5
5
  - 1.9.2
6
6
  - 1.9.3
7
7
  - 2.0.0
8
+ - ruby-head
9
+ - jruby-18mode # JRuby in 1.8 mode
10
+ - jruby-19mode # JRuby in 1.9 mode
11
+ - rbx-18mode
12
+ - rbx-19mode
13
+ env:
14
+ - "RAILS_VERSION=3.1.0"
15
+ - "RAILS_VERSION=3.2.0"
16
+ - "RAILS_VERSION=4.0.0.pre"
17
+ - "RAILS_VERSION=master"
18
+ matrix:
19
+ allow_failures:
20
+ - env: "RAILS_VERSION=master"
21
+ - rvm: ruby-head
22
+ exclude:
23
+ - rvm: 1.8.7
24
+ env: "RAILS_VERSION=4.0.0.pre"
25
+ - rvm: 1.9.2
26
+ env: "RAILS_VERSION=4.0.0.pre"
27
+ - rvm: jruby-18mode
28
+ env: "RAILS_VERSION=4.0.0.pre"
29
+ - rvm: rbx-18mode
30
+ env: "RAILS_VERSION=4.0.0.pre"
31
+ - rvm: 1.8.7
32
+ env: "RAILS_VERSION=master"
33
+ - rvm: 1.9.2
34
+ env: "RAILS_VERSION=master"
35
+ - rvm: jruby-18mode
36
+ env: "RAILS_VERSION=master"
37
+ - rvm: rbx-18mode
38
+ env: "RAILS_VERSION=master"
39
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## v1.0.1
4
+
5
+ - Fully test on Rails 4
6
+ - Improve mock user membership stubbing
7
+ - Add testing instructions to README
8
+
9
+ ## v1.0.0
10
+
11
+ - Add Devise compatibility
12
+
13
+ ## v0.0.1
14
+
15
+ - Initial release
data/Gemfile CHANGED
@@ -6,6 +6,19 @@ if ENV['EDGE']
6
6
  gem 'warden-github', :github => 'atmos/warden-github'
7
7
  end
8
8
 
9
+ rails_version = ENV['RAILS_VERSION']
10
+
11
+ rails_opts = case rails_version
12
+ when 'master'
13
+ { :github => 'rails/rails' }
14
+ when nil
15
+ {}
16
+ else
17
+ "~> #{rails_version}"
18
+ end
19
+
20
+ gem "rails", rails_opts
21
+
9
22
  group :development do
10
23
  unless ENV['CI']
11
24
  gem 'debugger', :platforms => :ruby_19, :require => false
data/README.md CHANGED
@@ -12,7 +12,7 @@ It is built on top of [warden-github](https://github.com/atmos/warden-github), w
12
12
 
13
13
  **Wouldn't it be nice to**
14
14
 
15
- - use your organization and it's teams for user access control?
15
+ - use your organization and its teams for user access control?
16
16
  - add a new employee to your GitHub organization or team in order to grant them access to your app's admin area?
17
17
 
18
18
  The motivation for this gem was to provide a very easy authorization (not authentication) mechanism to existing rails apps for admins, especially in combination with organization and team memberships.
@@ -61,6 +61,18 @@ class UsersController < ApplicationController
61
61
  end
62
62
  ```
63
63
 
64
+ ## Installation
65
+
66
+ To use this gem, add it to your `Gemfile`:
67
+
68
+ ```ruby
69
+ gem 'warden-github-rails', '~> 1.0'
70
+ ```
71
+
72
+ If you're using devise, make sure to use version 2.2.4 or newer.
73
+ Previous versions are not compatible with warden-github-rails and thus will not work.
74
+ See the note at [*Using alongside Devise and other Warden Gems*](#using-alongside-devise-and-other-warden-gems) for an explanation.
75
+
64
76
  ## Usage
65
77
 
66
78
  ### Configuration
@@ -167,6 +179,48 @@ end
167
179
 
168
180
  Once a user is logged in, you'll have access to it in the controller using `github_user`. It is an instance of `Warden::GitHub::User` which is defined in the [warden-github](https://github.com/atmos/warden-github/blob/master/lib/warden/github/user.rb) gem. The instance has several methods to access user information such as `#name`, `#id`, `#email`, etc. It also features a method `#api` which returns a preconfigured [Octokit](https://github.com/pengwynn/octokit) client for that user.
169
181
 
182
+ ### Test Helpers
183
+
184
+ This gems comes with a couple test helpers to make your life easier:
185
+
186
+ - A method is added to `Rack::Response` called `#github_oauth_redirect?` which
187
+ returns true if the response is a redirect to a url that starts with
188
+ `https://github.com/login/oauth/authorize`. You can use it in your request
189
+ tests to make sure the OAuth dance is initiated. In rspec you could verify
190
+ this as follows:
191
+
192
+ ```ruby
193
+ subject { get '/some-url-that-triggers-oauth' }
194
+ it { should be_github_oauth_redirect }
195
+ ```
196
+
197
+ - A mock user that allows you to stub team and organization memberships:
198
+
199
+ ```ruby
200
+ user = Warden::GitHub::Rails::TestHelpers::MockUser.new
201
+ user.stub_membership(team: [234, 987], org: 'some-inc')
202
+ user.team_member?(234) # => true
203
+ user.organization_member?('rails') # => false
204
+ ```
205
+
206
+ - A method that creates a mock user and logs it in. If desired, the scope can
207
+ be specified. The method returns the mock user so that you can manipulate it
208
+ further:
209
+
210
+ ```ruby
211
+ user = github_login(:admin)
212
+
213
+ get '/org/rails/admin'
214
+ expect(response).to be_not_found
215
+
216
+ user.stub_membership(org: 'rails')
217
+ get '/org/rails/admin'
218
+ expect(response).to be_ok
219
+ ```
220
+
221
+ In order to use the mock user and the `#github_login` method, make sure to
222
+ include `Warden::GitHub::Rails::TestHelpers` in your tests.
223
+
170
224
  ## Using alongside Devise and other Warden Gems
171
225
 
172
226
  Currently this gem does not play nicely with other gems that setup a warden middleware.
@@ -175,7 +229,7 @@ The warden middleware configures a warden instance and adds it to the rack envir
175
229
  Any other warden middleware downstream checks for any existing warden instance in the environment and, if present, skips itself.
176
230
  I've opened an [issue](https://github.com/hassox/warden/issues/67) on the warden repository to discuss possible workarounds.
177
231
 
178
- Nevertheless, this gem is compatible with devise.
232
+ Nevertheless, this gem is compatible with devise for version 2.2.4 and newer.
179
233
  devise allows you to specify a block that will be invoked when the warden middleware is configured.
180
234
  This functionality is used in this gem in order to setup the github strategy for warden instead of inserting our own middleware.
181
235
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -10,8 +10,10 @@ module Warden
10
10
  @memberships = { :team => [], :org => [] }
11
11
  end
12
12
 
13
- def stub_membership(membership)
14
- memberships.fetch(membership.keys.first) << membership.values.first
13
+ def stub_membership(args)
14
+ args.each do |type, values|
15
+ memberships.fetch(type).concat(Array(values))
16
+ end
15
17
  end
16
18
 
17
19
  def team_member?(id)
@@ -11,14 +11,14 @@ describe 'controller helpers' do
11
11
 
12
12
  context 'when not logged in' do
13
13
  it 'initiates the oauth flow' do
14
- request.should be_github_oauth_redirect
14
+ expect(request).to be_github_oauth_redirect
15
15
  end
16
16
  end
17
17
 
18
18
  context 'when logged in' do
19
19
  before { github_login(scope) }
20
20
  it 'does nothing' do
21
- request.should be_ok
21
+ expect(request).to be_ok
22
22
  end
23
23
  end
24
24
  end
@@ -26,15 +26,15 @@ describe 'controller helpers' do
26
26
  describe '#github_logout' do
27
27
  context 'when not logged in' do
28
28
  it 'does nothing' do
29
- get("/#{type}/logout").body.should eq 'false'
29
+ expect(get("/#{type}/logout").body).to eq('false')
30
30
  end
31
31
  end
32
32
 
33
33
  context 'when logged in' do
34
34
  it 'logs out the user' do
35
35
  github_login(scope)
36
- get("/#{type}/logout").body.should eq 'true'
37
- get("/#{type}/logout").body.should eq 'false'
36
+ expect(get("/#{type}/logout").body).to eq('true')
37
+ expect(get("/#{type}/logout").body).to eq('false')
38
38
  end
39
39
  end
40
40
  end
@@ -44,14 +44,14 @@ describe 'controller helpers' do
44
44
 
45
45
  context 'when not logged in' do
46
46
  it 'returns false' do
47
- request.body.should eq 'false'
47
+ expect(request.body).to eq('false')
48
48
  end
49
49
  end
50
50
 
51
51
  context 'when logged in' do
52
52
  it 'returns true' do
53
53
  github_login(scope)
54
- request.body.should eq 'true'
54
+ expect(request.body).to eq('true')
55
55
  end
56
56
  end
57
57
  end
@@ -61,15 +61,15 @@ describe 'controller helpers' do
61
61
 
62
62
  context 'when not logged in' do
63
63
  it 'returns nil' do
64
- request.body.should be_blank
64
+ expect(request.body).to be_blank
65
65
  end
66
66
  end
67
67
 
68
68
  context 'when logged in' do
69
69
  it 'returns the logged in user' do
70
70
  github_login(scope)
71
- request.body.
72
- should include 'Warden::GitHub::Rails::TestHelpers::MockUser'
71
+ expect(request.body).to \
72
+ include('Warden::GitHub::Rails::TestHelpers::MockUser')
73
73
  end
74
74
  end
75
75
  end
@@ -79,14 +79,14 @@ describe 'controller helpers' do
79
79
 
80
80
  context 'when not logged in' do
81
81
  it 'should be nil' do
82
- request.body.should be_blank
82
+ expect(request.body).to be_blank
83
83
  end
84
84
  end
85
85
 
86
86
  context 'when logged in' do
87
87
  it "returns the user's session" do
88
88
  github_login(scope)
89
- request.body.should == { :foo => :bar }.to_s
89
+ expect(request.body).to eq({ :foo => :bar }.to_s)
90
90
  end
91
91
  end
92
92
  end
@@ -7,10 +7,10 @@ describe 'request to custom configured scope' do
7
7
  request = get url
8
8
  params = Addressable::URI.parse(request.location).query_values
9
9
 
10
- request.should be_github_oauth_redirect
11
- params.fetch('client_id').should eq args.fetch(:client_id)
12
- params.fetch('redirect_uri').should =~ args.fetch(:redirect_uri)
13
- params.fetch('scope').should eq args.fetch(:scope)
10
+ expect(request).to be_github_oauth_redirect
11
+ expect(params.fetch('client_id')).to eq(args.fetch(:client_id))
12
+ expect(params.fetch('redirect_uri')).to match(args.fetch(:redirect_uri))
13
+ expect(params.fetch('scope')).to eq(args.fetch(:scope))
14
14
  end
15
15
 
16
16
  context 'user' do
@@ -5,7 +5,7 @@ describe 'view helpers' do
5
5
  subject(:request) { get "/view_tests/user" }
6
6
 
7
7
  it 'is defined' do
8
- request.body.should include 'true'
8
+ expect(request.body).to include('true')
9
9
  end
10
10
  end
11
11
 
@@ -13,7 +13,7 @@ describe 'view helpers' do
13
13
  subject(:request) { get "/view_tests/authenticated" }
14
14
 
15
15
  it 'is defined' do
16
- request.body.should include 'true'
16
+ expect(request.body).to include('true')
17
17
  end
18
18
  end
19
19
  end
@@ -49,5 +49,5 @@ RailsApp::Application.routes.draw do
49
49
 
50
50
  # Everything else should be a 404:
51
51
 
52
- match '*all' => responses[404]
52
+ get '*all' => responses[404]
53
53
  end
data/spec/spec_helper.rb CHANGED
@@ -23,6 +23,9 @@ RSpec.configure do |config|
23
23
  config.run_all_when_everything_filtered = true
24
24
  config.filter_run :focus
25
25
  config.order = 'random'
26
+ config.expect_with :rspec do |c|
27
+ c.syntax = :expect
28
+ end
26
29
 
27
30
  config.include Rack::Test::Methods
28
31
  config.include Warden::GitHub::Rails::TestHelpers
@@ -5,19 +5,19 @@ describe Warden::GitHub::Rails::Config do
5
5
 
6
6
  describe '#default_scope' do
7
7
  it 'defaults to :user' do
8
- config.default_scope.should be :user
8
+ expect(config.default_scope).to eq(:user)
9
9
  end
10
10
  end
11
11
 
12
12
  describe '#scopes' do
13
13
  it 'defaults to an empty hash' do
14
- config.scopes.should == {}
14
+ expect(config.scopes).to eq({})
15
15
  end
16
16
  end
17
17
 
18
18
  describe '#teams' do
19
19
  it 'defaults to an empty hash' do
20
- config.scopes.should == {}
20
+ expect(config.scopes).to eq({})
21
21
  end
22
22
  end
23
23
 
@@ -25,35 +25,35 @@ describe Warden::GitHub::Rails::Config do
25
25
  it 'adds a scope with its configs' do
26
26
  scope_config = double
27
27
  config.add_scope :admin, scope_config
28
- config.scopes[:admin].should eq scope_config
28
+ expect(config.scopes[:admin]).to eq(scope_config)
29
29
  end
30
30
  end
31
31
 
32
32
  describe '#add_team' do
33
33
  it 'adds a name mapping for a team' do
34
34
  config.add_team :marketing, 1234
35
- config.teams[:marketing].should eq 1234
35
+ expect(config.teams[:marketing]).to eq(1234)
36
36
  end
37
37
 
38
38
  it 'normalizes the input' do
39
39
  config.add_team 'marketing', '1234'
40
- config.teams[:marketing].should eq 1234
40
+ expect(config.teams[:marketing]).to eq(1234)
41
41
  end
42
42
  end
43
43
 
44
44
  describe '#team_id' do
45
45
  context 'when passed a numeric value' do
46
46
  it 'returns that value' do
47
- config.team_id('1234').should eq 1234
48
- config.team_id(1234).should eq 1234
47
+ expect(config.team_id('1234')).to eq(1234)
48
+ expect(config.team_id(1234)).to eq(1234)
49
49
  end
50
50
  end
51
51
 
52
52
  context 'when passed an alias' do
53
53
  it 'returns the id for the alias' do
54
54
  config.add_team :marketing, 1234
55
- config.team_id(:marketing).should eq 1234
56
- config.team_id('marketing').should eq 1234
55
+ expect(config.team_id(:marketing)).to eq(1234)
56
+ expect(config.team_id('marketing')).to eq(1234)
57
57
  end
58
58
  end
59
59
 
@@ -7,14 +7,15 @@ describe Warden::GitHub::Rails::TestHelpers::MockUser do
7
7
  subject(:user) { described_class.new }
8
8
 
9
9
  it 'stubs memberships' do
10
- user.should_not be_team_member(123)
11
- user.should_not be_organization_member('foobar')
10
+ expect(user).not_to be_team_member(123)
11
+ expect(user).not_to be_team_member(456)
12
+ expect(user).not_to be_organization_member('foobar')
12
13
 
13
- user.stub_membership(:team => 123)
14
- user.stub_membership(:org => 'foobar')
14
+ user.stub_membership(:org => 'foobar', :team => [123, 456])
15
15
 
16
- user.should be_team_member(123)
17
- user.should be_organization_member('foobar')
16
+ expect(user).to be_team_member(123)
17
+ expect(user).to be_team_member(456)
18
+ expect(user).to be_organization_member('foobar')
18
19
  end
19
20
  end
20
21
  end
@@ -4,7 +4,7 @@ describe Warden::GitHub::Rails do
4
4
  describe '.setup' do
5
5
  it 'yields a config instance' do
6
6
  described_class.setup do |config|
7
- config.should be_a described_class::Config
7
+ expect(config).to be_a(described_class::Config)
8
8
  end
9
9
  end
10
10
  end
@@ -6,7 +6,7 @@ describe Warden::GitHub::Rails::TestHelpers do
6
6
  it 'uses the default scope from config to login' do
7
7
  Warden::GitHub::Rails.stub(:default_scope => :foobar)
8
8
  should_receive(:login_as).with do |_, opts|
9
- opts.fetch(:scope).should be :foobar
9
+ expect(opts.fetch(:scope)).to eq(:foobar)
10
10
  end
11
11
 
12
12
  github_login
@@ -16,7 +16,7 @@ describe Warden::GitHub::Rails::TestHelpers do
16
16
  context 'when a scope is specified' do
17
17
  it 'uses that scope to login' do
18
18
  should_receive(:login_as).with do |_, opts|
19
- opts.fetch(:scope).should be :admin
19
+ expect(opts.fetch(:scope)).to eq(:admin)
20
20
  end
21
21
 
22
22
  github_login(:admin)
@@ -28,12 +28,12 @@ describe Warden::GitHub::Rails::TestHelpers do
28
28
 
29
29
  should_receive(:login_as).with do |user, _|
30
30
  expected_user = user
31
- user.should be_a Warden::GitHub::Rails::TestHelpers::MockUser
31
+ expect(user).to be_a(Warden::GitHub::Rails::TestHelpers::MockUser)
32
32
  end
33
33
 
34
34
  user = github_login
35
35
 
36
- user.should be expected_user
36
+ expect(user).to eq(expected_user)
37
37
  end
38
38
  end
39
39
  end
@@ -14,12 +14,12 @@ Gem::Specification.new do |gem|
14
14
  gem.files = `git ls-files`.split($/) - Dir.glob('example/**/*')
15
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
16
 
17
- gem.add_development_dependency 'rspec', '~> 2.12'
17
+ gem.add_development_dependency 'rspec', '~> 2.14'
18
18
  gem.add_development_dependency 'simplecov'
19
19
  gem.add_development_dependency 'rails', '>= 3.2'
20
20
  gem.add_development_dependency 'rack-test', '~> 0.6'
21
21
  gem.add_development_dependency 'addressable', '~> 2.3'
22
22
 
23
23
  gem.add_dependency 'warden-github', '~> 0.14.0'
24
- gem.add_dependency 'railties', '>= 3.2'
24
+ gem.add_dependency 'railties', '>= 3.1'
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden-github-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipe Fatio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-08 00:00:00.000000000 Z
11
+ date: 2013-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '2.12'
19
+ version: '2.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '2.12'
26
+ version: '2.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - '>='
102
102
  - !ruby/object:Gem::Version
103
- version: '3.2'
103
+ version: '3.1'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
- version: '3.2'
110
+ version: '3.1'
111
111
  description: An easy drop in solution for rails to use GitHub authentication.
112
112
  email:
113
113
  - me@phili.pe
@@ -118,6 +118,7 @@ files:
118
118
  - .gitignore
119
119
  - .rspec
120
120
  - .travis.yml
121
+ - CHANGELOG.md
121
122
  - Gemfile
122
123
  - LICENSE.txt
123
124
  - README.md
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  version: '0'
180
181
  requirements: []
181
182
  rubyforge_project:
182
- rubygems_version: 2.0.3
183
+ rubygems_version: 2.0.2
183
184
  signing_key:
184
185
  specification_version: 4
185
186
  summary: An easy drop in solution for rails to use GitHub authentication.