Skip to content

Commit

Permalink
Initial commit for pollster plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Jackson committed Apr 16, 2013
1 parent 05812ed commit 20fec24
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
29 changes: 29 additions & 0 deletions plugin/pollster_cinch_plugin.rb
@@ -0,0 +1,29 @@
module TurbotPlugins
class Pollster
include Cinch::Plugin
set :prefix, PREFIX

PluginHandler.add_plugin(self)

def self.commands
end


attr_accessor :question

def set_poll(m, question)
if authenticated_users.include?(m.user.nick)
self.question = question
m.reply "Your poll was successfully created!"
else
m.reply "You do not have the correct permissions"
end
end

private

def authenticated_users
['rondale_sc']
end
end
end
40 changes: 40 additions & 0 deletions spec/plugin/pollster_spec.rb
@@ -0,0 +1,40 @@
require 'spec_helper'

require_relative '../../plugin/pollster_cinch_plugin.rb'

describe TurbotPlugins::Pollster do

context "#set_poll" do
context "If passed a string from a valid user." do
let(:m) { double(:user => stub(:nick => "rondale_sc")) }
let(:question) { "This is a question" }

it "should set the question for a poll" do
m.should_receive(:reply).with("Your poll was successfully created!")

plugin = TurbotPlugins::Pollster.new(double.as_null_object)
plugin.set_poll(m,question)
end

it "save the question to an accessor" do
m.stub(:reply)

plugin = TurbotPlugins::Pollster.new(double.as_null_object)
plugin.set_poll(m, question)

expect(plugin.question).to eq(question)
end

end

context "If passed a string from invalid user." do
let(:m) { double(:user => stub(:nick => "not_valid_nick")) }
it "should return false" do
m.should_receive(:reply).with("You do not have the correct permissions")

plugin = TurbotPlugins::Pollster.new(double.as_null_object)
plugin.set_poll(m, "This is a question")
end
end
end
end

0 comments on commit 20fec24

Please sign in to comment.