Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Forked from phillipkoebbe/base_controller.rb
Created January 5, 2010 17:48
Show Gist options
  • Save dchelimsky/269552 to your computer and use it in GitHub Desktop.
Save dchelimsky/269552 to your computer and use it in GitHub Desktop.
class Admin::BaseController < ApplicationController
before_filter :require_admin
protected
def require_admin
redirect_to error_path(403) unless current_user.is_administrator?
end
end
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