-
-
Save dchelimsky/269552 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 Admin::BaseController < ApplicationController | |
before_filter :require_admin | |
protected | |
def require_admin | |
redirect_to error_path(403) unless current_user.is_administrator? | |
end | |
end |
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
require 'spec_helper' | |
describe Admin::BaseController do | |
describe 'before_filter' do | |
it 'should respond to :require_admin' do | |
controller.should respond_to(:require_admin) | |
end | |
end | |
describe 'not redirecting when user is an admin' do | |
before :each do | |
user = stub_model(User) | |
user.should_receive(:is_administrator?).and_return(true) | |
User.should_receive(:find_by_id).and_return(user) | |
get '/admin/home/index' | |
end | |
should_not_redirect_to { error_path(403) } | |
end | |
describe 'redirecting when user is not an admin' do | |
before :each do | |
user = stub_model(User) | |
user.should_receive(:is_administrator?).and_return(false) | |
User.should_receive(:find_by_id).and_return(user) | |
get '/admin/home/index' | |
end | |
should_redirect_to { error_path(403) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment