Created
January 18, 2011 12:25
-
-
Save phillipkoebbe/784363 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseController < ApplicationController | |
# put everything in here that is common to all controllers | |
end | |
class User::BaseController < BaseController | |
before_filter :require_logged_in | |
private | |
def require_logged_in | |
redirect_to(login_path) and return false unless logged_in? | |
return true | |
end | |
end | |
class User::ProductsController < User::BaseController | |
end | |
class Admin::BaseController < BaseController | |
before_filter :require_admin | |
private | |
def require_admin | |
redirect_to(home_path) and return false unless logged_in? | |
redirect_to(user_home_path) and return false unless current_user.is_administrator? | |
return true | |
end | |
end | |
class Admin::ProductsController < Admin::BaseController | |
end | |
# spec for base controller | |
class Admin::BogusController < Admin::BaseController | |
def index | |
render :nothing => true | |
end | |
end | |
ActionController::Routing::Routes.draw do |map| | |
map.namespace :admin do |admin| | |
admin.resources :bogus | |
end | |
end | |
describe Admin::BogusController do | |
it 'should deny access to non-administrative users' do | |
login_as(:user) | |
get :index | |
response.should be_redirect | |
end | |
it 'should allow access to administrative users' do | |
login_as(:admin) | |
get :index | |
response.should be_success | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment