Permalink
Browse files

Everything should be in place.

  • Loading branch information...
1 parent 88925ee commit 2d0cd6cdd3e1161549fa131678f0878b37dcbf61 @steveklabnik committed Sep 16, 2011
Showing with 53 additions and 7 deletions.
  1. +6 −3 lib/eployday/deploy.rb
  2. +13 −0 lib/eployday/permission_checker.rb
  3. +18 −4 spec/deploy_spec.rb
  4. +16 −0 spec/permission_cheker_spec.rb
View
@@ -1,4 +1,5 @@
require 'cinch'
+require 'eployday/permission_checker'
module Eployday
class Deploy
@@ -7,9 +8,11 @@ class Deploy
match "deploy"
def execute(m)
- m.reply "#{m.user.nick}: beginning deploy."
- Kernel.system "sm deploy"
- m.reply "#{m.user.nick}: deploy finished."
+ if PermissionChecker.allowed?(m.user.nick)
+ m.reply "#{m.user.nick}: beginning deploy."
+ Kernel.system "sm deploy"
+ m.reply "#{m.user.nick}: deploy finished."
+ end
end
end
end
@@ -0,0 +1,13 @@
+module Eployday
+ module PermissionChecker
+ class << self
+ def allowed?(nick, list=load_whitelist)
+ list.include?(nick)
+ end
+
+ def load_whitelist
+ @whitelist = %w[steveklabnik carols10cents wilkie cl0ckw0rk ddagradi]
+ end
+ end
+ end
+end
View
@@ -6,10 +6,24 @@
Eployday::Deploy.ancestors.include?(Cinch::Plugin).should be_true
end
- it "executes a deploy" do
- Kernel.should_receive(:system).with("sm deploy")
- message = stub(:reply => nil, :user => stub(:nick => "steve"))
- Eployday::Deploy.new(stub.as_null_object).execute(message)
+ context "execute" do
+ let(:message) {
+ message = stub(:reply => nil, :user => stub(:nick => "steve"))
+ }
+
+ it "executes a deploy" do
+ Eployday::PermissionChecker.should_receive(:allowed?).and_return true
+ Kernel.should_receive(:system).with("sm deploy")
+
+ Eployday::Deploy.new(stub.as_null_object).execute(message)
+ end
+
+ it "respects the permissions checker" do
+ Eployday::PermissionChecker.should_receive(:allowed?).and_return false
+ Kernel.should_not_receive(:system)
+
+ Eployday::Deploy.new(stub.as_null_object).execute(message)
+ end
end
end
end
@@ -0,0 +1,16 @@
+require 'eployday/permission_checker'
+
+describe Eployday::PermissionChecker do
+ it "loads the whitelist" do
+ Eployday::PermissionChecker.should_receive(:load_whitelist).and_return([])
+ Eployday::PermissionChecker.allowed?("steveklabnik")
+ end
+
+ it "allows people on the list" do
+ Eployday::PermissionChecker.allowed?("imgood", ["imgood"]).should be_true
+ end
+
+ it "disallows people not on the list" do
+ Eployday::PermissionChecker.allowed?("imnot", []).should_not be_true
+ end
+end

0 comments on commit 2d0cd6c

Please sign in to comment.