Skip to content

Commit

Permalink
Update admin checking and improve specs. Specs not all passing yet. […
Browse files Browse the repository at this point in the history
…#19]
  • Loading branch information
marnen committed Oct 13, 2009
1 parent a94a361 commit d15ac9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base

# Check to see if the current user is an admin of at least one calendar.
def admin?
u = User.current_user
u = current_user
if u.nil? or u == false
return nil
else
Expand Down
20 changes: 18 additions & 2 deletions spec/controllers/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

describe ApplicationController, "(admin?)" do
it "should return nil if current user is nil or false" do
User.stub!(:current_user).and_return(nil)
UserSession.create nil
controller.admin?.should be_nil
User.stub!(:current_user).and_return(false)
UserSession.create false
controller.admin?.should be_nil
end

it "should return true if current user is an admin" do
@admin = User.make do |u|
u.permissions.make(:role => Role.make(:admin))
end
UserSession.create @admin
controller.admin?.should be_true
end

it "should return false if current user is not an admin" do
@user = User.make do |u|
u.permissions.make(:role => Role.make)
end
UserSession.create @user
controller.admin?.should be_false
end
end

0 comments on commit d15ac9b

Please sign in to comment.