Skip to content

Commit

Permalink
Use ruby 1.9 hash syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
fphilipe committed Sep 17, 2013
1 parent 33e7171 commit 44c2f76
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 98 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ source 'https://rubygems.org'
gemspec

if ENV['EDGE']
gem 'warden-github', :github => 'atmos/warden-github'
gem 'warden-github', github: 'atmos/warden-github'
end

rails_version = ENV['RAILS_VERSION']

rails_opts = case rails_version
when 'master'
{ :github => 'rails/rails' }
{ github: 'rails/rails' }
when nil
{}
else
Expand All @@ -21,7 +21,7 @@ gem "rails", rails_opts

group :development do
unless ENV['CI']
gem 'debugger', :platforms => :ruby_19, :require => false
gem 'ruby-debug', :platforms => :ruby_18, :require => false
gem 'debugger', platforms: :ruby_19, require: false
gem 'ruby-debug', platforms: :ruby_18, require: false
end
end
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ They allow you to restrict access to members of your organization or a certain t
This is how your rails `routes.rb` could look like:

```ruby
constraints(:subdomain => 'admin') do
github_authenticate(:org => 'my_company_inc') do
constraints(subdomain: 'admin') do
github_authenticate(org: 'my_company_inc') do
resources :users
resources :projects

github_authenticated(:team => 'sysadmins') do
github_authenticated(team: 'sysadmins') do
resource :infrastructure
end
end
Expand All @@ -43,11 +43,11 @@ class UsersController < ApplicationController

def new
github_authenticate! # Performs OAuth flow when not logged in.
@user = User.new(:name => github_user.name, :email => github_user.email)
@user = User.new(name: github_user.name, email: github_user.email)
end

def create
attrs = params.require(:user).permit(:name, :email).merge(:github_id => github_user.id)
attrs = params.require(:user).permit(:name, :email).merge(github_id: github_user.id)
@user = User.create(attrs)

if @user
Expand Down Expand Up @@ -88,14 +88,14 @@ Here's how such a config might look like:

```ruby
Warden::GitHub::Rails.setup do |config|
config.add_scope :user, :client_id => 'foo',
:client_secret => 'bar',
:scope => 'user'
config.add_scope :user, client_id: 'foo',
client_secret: 'bar',
scope: 'user'

config.add_scope :admin, :client_id => 'abc',
:client_secret => 'xyz',
:redirect_uri => '/admin/login/callback',
:scope => 'repo'
config.add_scope :admin, client_id: 'abc',
client_secret: 'xyz',
redirect_uri: '/admin/login/callback',
scope: 'repo'

config.default_scope = :admin

Expand Down Expand Up @@ -129,17 +129,17 @@ github_unauthenticated do
end

# Only matches when member of the organization. Initiates login if not logged in.
github_authenticate(:org => 'my_company') do
github_authenticate(org: 'my_company') do
resource :admin
end

# Only matches when member of the team. Does not initiate login if not logged in.
github_authenticated(:team => 'markting') do
github_authenticated(team: 'markting') do
get '/dashboard' => 'dashboard#show'
end

# Using dynamic membership values:
github_authenticate(:org => lambda { |req| r.params[:id] }) do
github_authenticate(org: lambda { |req| r.params[:id] }) do
get '/orgs/:id' => 'orgs#show'
end
```
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
2 changes: 1 addition & 1 deletion example/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ApplicationController < ActionController::Base
def not_found
render :status => 404
render status: 404
end
end
2 changes: 1 addition & 1 deletion example/app/views/organizations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ul>
<%- @orgs.each do |org| -%>
<li>
<%= image_tag org.avatar_url, :width => 25, :height => 25 %>
<%= image_tag org.avatar_url, width: 25, height: 25 %>
<%= link_to org.login, org_path(org.login) %>
</li>
<%- end -%>
Expand Down
4 changes: 2 additions & 2 deletions example/app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h2>
<%= image_tag @org.avatar_url, :width => 50, :height => 50 %>
<%= image_tag @org.avatar_url, width: 50, height: 50 %>
<%= @org.login %>
</h2>

Expand Down Expand Up @@ -31,7 +31,7 @@
<ul>
<%- @members.each do |member| -%>
<li>
<%= image_tag member.avatar_url, :width => 25, :height => 25 %>
<%= image_tag member.avatar_url, width: 25, height: 25 %>
<%= link_to member.login, user_path(member.login) %>
</li>
<%- end -%>
Expand Down
2 changes: 1 addition & 1 deletion example/app/views/teams/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ul>
<%- @members.each do |member| -%>
<li>
<%= image_tag member.avatar_url, :width => 25, :height => 25 %>
<%= image_tag member.avatar_url, width: 25, height: 25 %>
<%= link_to member.login, user_path(member.login) %>
</li>
<%- end -%>
Expand Down
2 changes: 1 addition & 1 deletion example/app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h2>
<%= image_tag @user.avatar_url, :width => 50, :height => 50 %>
<%= image_tag @user.avatar_url, width: 50, height: 50 %>
<%= @user.login %>
<%- if @user.name.present? %>
(<%= @user.name %>)
Expand Down
2 changes: 1 addition & 1 deletion example/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "active_resource/railtie"

if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
Bundler.require(*Rails.groups(assets: %w(development test)))
end

module Example
Expand Down
2 changes: 1 addition & 1 deletion example/config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Example::Application.config.session_store :cookie_store, :key => '_example_session'
Example::Application.config.session_store :cookie_store, key: '_example_session'
2 changes: 1 addition & 1 deletion example/config/initializers/warden_github_rails.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Warden::GitHub::Rails.setup do |config|
config.add_scope :user, :redirect_uri => '/login', :scope => 'user,repo'
config.add_scope :user, redirect_uri: '/login', scope: 'user,repo'
end
18 changes: 9 additions & 9 deletions example/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Example::Application.routes.draw do
github_authenticate do
get '/orgs' => 'organizations#index', :as => :orgs
get '/profile' => 'users#show', :as => :profile
get '/orgs' => 'organizations#index', as: :orgs
get '/profile' => 'users#show', as: :profile
end

github_authenticate(:team => lambda { |req| req.params[:id] }) do
get '/teams/:id' => 'teams#show', :as => :team
github_authenticate(team: lambda { |req| req.params[:id] }) do
get '/teams/:id' => 'teams#show', as: :team
end

github_authenticate(:org => lambda { |req| req.params[:id] }) do
get '/orgs/:id' => 'organizations#show', :as => :org
github_authenticate(org: lambda { |req| req.params[:id] }) do
get '/orgs/:id' => 'organizations#show', as: :org
end

get '/login' => 'sessions#create', :as => :login
get '/logout' => 'sessions#destroy', :as => :logout
get '/login' => 'sessions#create', as: :login
get '/logout' => 'sessions#destroy', as: :logout

resources :users

root :to => 'home#show'
root to: 'home#show'

match '*all' => 'application#not_found'
end
2 changes: 1 addition & 1 deletion lib/warden/github/rails/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.included(klass)
# Initiates the OAuth flow if not already authenticated for the
# specified scope.
def github_authenticate!(scope=Rails.default_scope)
request.env['warden'].authenticate!(:scope => scope)
request.env['warden'].authenticate!(scope: scope)
end

# Logs out a user if currently logged in for the specified scope.
Expand Down
4 changes: 2 additions & 2 deletions lib/warden/github/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Railtie < ::Rails::Railtie

def setup_scopes(config)
Rails.scopes.each do |scope, scope_config|
config.scope_defaults scope, :strategies => [:github],
:config => scope_config
config.scope_defaults scope, strategies: [:github],
config: scope_config
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/warden/github/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ module Routes
# authenticated, it initiates the OAuth flow.
#
# Team and organization memberships can be checked by specifying a hash
# such as `:team => 'foobar'` or `:org => 'my_company'`.
# such as `team: 'foobar'` or `org: 'my_company'`.
def github_authenticate(scope=nil, options={}, &routes_block)
github_constraint(scope, options, routes_block) do |warden, scope|
warden.authenticate!(:scope => scope)
warden.authenticate!(scope: scope)
end
end

# The routes will only be visible to authenticated GitHub users. When
# not authenticated, it does not initiate the OAuth flow.
#
# Team and organization memberships can be checked by specifying a hash
# such as `:team => 'foobar'` or `:org => 'my_company'`.
# such as `team: 'foobar'` or `org: 'my_company'`.
def github_authenticated(scope=nil, options={}, &routes_block)
github_constraint(scope, options, routes_block) do |warden, scope|
warden.authenticated?(:scope => scope)
warden.authenticated?(scope: scope)
end
end

Expand All @@ -30,7 +30,7 @@ def github_authenticated(scope=nil, options={}, &routes_block)
# limited usage.
def github_unauthenticated(scope=nil, options={}, &routes_block)
github_constraint(scope, options, routes_block) do |warden, scope|
not warden.authenticated?(:scope => scope)
not warden.authenticated?(scope: scope)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/warden/github/rails/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module TestHelpers
# Login a mock GitHub user and return it.
def github_login(scope=Rails.default_scope)
MockUser.new.tap do |user|
login_as(user, :scope => scope)
login_as(user, scope: scope)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/warden/github/rails/test_helpers/mock_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MockUser < User

def initialize(*args)
super
@memberships = { :team => [], :org => [] }
@memberships = { team: [], org: [] }
end

def stub_membership(args)
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/controller_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe 'controller helpers' do
{
:scoped => :admin,
:unscoped => Warden::GitHub::Rails.default_scope
scoped: :admin,
unscoped: Warden::GitHub::Rails.default_scope
}.each do |type, scope|
context "when using #{type}" do
describe '#github_authenticate!' do
Expand Down Expand Up @@ -86,7 +86,7 @@
context 'when logged in' do
it "returns the user's session" do
github_login(scope)
expect(request.body).to eq({ :foo => :bar }.to_s)
expect(request.body).to eq({ foo: :bar }.to_s)
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions spec/integration/membership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
context 'and team member' do
before do
user = github_login
user.stub_membership(:team => 123)
user.stub_membership(team: 123)
end

it { should be_ok }
Expand All @@ -37,7 +37,7 @@
context 'and team member' do
before do
user = github_login
user.stub_membership(:team => 456)
user.stub_membership(team: 456)
end

it { should be_ok }
Expand All @@ -57,7 +57,7 @@
context 'and team member' do
before do
user = github_login
user.stub_membership(:team => 123)
user.stub_membership(team: 123)
end

it { should be_ok }
Expand All @@ -72,7 +72,7 @@
end

context 'that requires an organization membership' do
{ :org => :foobar_inc, :organization => 'some_org' }.each do |key, value|
{ org: :foobar_inc, organization: 'some_org' }.each do |key, value|
context "which is specified as #{key}" do
subject { get "/#{key}/protected" }

Expand All @@ -84,7 +84,7 @@
context 'and organization member' do
before do
user = github_login
user.stub_membership(:org => value)
user.stub_membership(org: value)
end

it { should be_ok }
Expand All @@ -105,7 +105,7 @@
context 'and organization member' do
before do
user = github_login
user.stub_membership(:org => 'some_org')
user.stub_membership(org: 'some_org')
end

it { should be_ok }
Expand All @@ -128,7 +128,7 @@
context 'when team member' do
before do
user = github_login
user.stub_membership(:team => 123)
user.stub_membership(team: 123)
end

it { should be_ok }
Expand All @@ -146,7 +146,7 @@
context 'when team member' do
before do
user = github_login
user.stub_membership(:team => 456)
user.stub_membership(team: 456)
end

it { should be_ok }
Expand All @@ -160,14 +160,14 @@
end

context 'that requires an organization membership' do
{ :org => :foobar_inc, :organization => 'some_org' }.each do |key, value|
{ org: :foobar_inc, organization: 'some_org' }.each do |key, value|
context "which is specified as #{key}" do
subject { get "/#{key}/conditional" }

context 'when organization member' do
before do
user = github_login
user.stub_membership(:org => value)
user.stub_membership(org: value)
end

it { should be_ok }
Expand Down
Loading

0 comments on commit 44c2f76

Please sign in to comment.