Skip to content
Browse files

added spec for application controller

  • Loading branch information...
1 parent b1d96a4 commit 7158b3c870d229b5670aadfa4521aef6391e351e @tomcz tomcz committed Mar 11, 2010
Showing with 22 additions and 1 deletion.
  1. +2 −1 app/controllers/application_controller.rb
  2. +20 −0 spec/controllers/admin_controller_spec.rb
View
3 app/controllers/application_controller.rb
@@ -13,7 +13,8 @@ class ApplicationController < ActionController::Base
protected
def authorize
- unless User.find_by_uuid(session[:user_id])
+ user_id = session[:user_id]
+ unless user_id and User.find_by_uuid(user_id)
session[:original_uri] = request.request_uri
redirect_to :controller => 'admin', :action => 'login'
end
View
20 spec/controllers/admin_controller_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe AdminController do
+
+ context 'not logged in' do
+ it 'should redirect to login when asked for index page' do
+ get :index
+ response.should redirect_to(:controller => 'admin', :action => 'login')
+ end
+ end
+
+ context 'logged in as administrator' do
+ it 'should render index page'do
+ User.should_receive(:find_by_uuid).with('foo').and_return(mock_model(User))
+ get :index, {}, {:user_id => 'foo'}
+ response.should render_template('index')
+ end
+ end
+
+end

0 comments on commit 7158b3c

Please sign in to comment.
Something went wrong with that request. Please try again.