Permalink
Browse files

Adding check for authed.

  • Loading branch information...
steveklabnik committed Sep 16, 2011
1 parent 2d0cd6c commit 853ebce8fbfb092423f38b27dcd1cb8b4fcdd902
Showing with 14 additions and 5 deletions.
  1. +2 −2 lib/eployday/permission_checker.rb
  2. +12 −3 spec/permission_cheker_spec.rb
@@ -1,8 +1,8 @@
module Eployday
module PermissionChecker
class << self
- def allowed?(nick, list=load_whitelist)
- list.include?(nick)
+ def allowed?(user, list=load_whitelist)
+ list.include?(user.nick) and user.authed?
end
def load_whitelist
@@ -3,14 +3,23 @@
describe Eployday::PermissionChecker do
it "loads the whitelist" do
Eployday::PermissionChecker.should_receive(:load_whitelist).and_return([])
- Eployday::PermissionChecker.allowed?("steveklabnik")
+ Eployday::PermissionChecker.allowed?(stub.as_null_object)
end
it "allows people on the list" do
- Eployday::PermissionChecker.allowed?("imgood", ["imgood"]).should be_true
+ user = stub(:nick => "imgood", :authed? => true)
+ Eployday::PermissionChecker.allowed?(user, ["imgood"]).should be_true
end
it "disallows people not on the list" do
- Eployday::PermissionChecker.allowed?("imnot", []).should_not be_true
+ Eployday::PermissionChecker.allowed?(stub(:nick => "imnot"), []).should_not be_true
+ end
+
+ it "ensures that the nick is registered" do
+ authed_user = stub(:nick => "nick", :authed? => true)
+ unauthed_user = stub(:nick => "nick", :authed? => false)
+ whitelist = ["nick"]
+ Eployday::PermissionChecker.allowed?( authed_user, whitelist).should be_true
+ Eployday::PermissionChecker.allowed?(unauthed_user, whitelist).should_not be_true
end
end

0 comments on commit 853ebce

Please sign in to comment.