Skip to content

Commit

Permalink
Enforce registration config in the controller. Close #91.
Browse files Browse the repository at this point in the history
  • Loading branch information
bamnet committed May 31, 2012
1 parent 8d56cc8 commit 1f59539
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/controllers/concerto_devise/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#Overriding the Devise Registrations controller for fun and profit
class ConcertoDevise::RegistrationsController < Devise::RegistrationsController
before_filter :check_permissions, :only=>[:new, :create]

def check_permissions
authorize! :create, User
end

def create
build_resource
Expand Down Expand Up @@ -33,4 +38,4 @@ def create
end
end

end
end
15 changes: 13 additions & 2 deletions test/functional/registration_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'test_helper'

class DeviseRegistrationsControllerTest < ActionController::TestCase
class ConcertoDeviseRegistrationsControllerTest < ActionController::TestCase
include Devise::TestHelpers
tests Devise::RegistrationsController
tests ConcertoDevise::RegistrationsController

def setup
request.env["devise.mapping"] = Devise.mappings[:user]
Expand All @@ -13,4 +13,15 @@ def setup
assert_response :success
end

test "registration form diabled" do
ConcertoConfig.set("allow_registration", "false")
get :new
assert_response :redirect
end

test "registration processing disabled" do
ConcertoConfig.set("allow_registration", "false")
post :create, {:user => {:first_name => "Name", :last_name => "Last", :email => "a@a.com"}}
assert_response :redirect
end
end
6 changes: 6 additions & 0 deletions test/unit/abilities/user/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ def setup
assert ability.cannot?(:update, @katie)
assert ability.cannot?(:destroy, @katie)
end

test "new users cannot sign up with disabled" do
ConcertoConfig.set(:allow_registration, "false")
ability = Ability.new(User.new)
assert ability.cannot?(:create, User)
end
end

0 comments on commit 1f59539

Please sign in to comment.