Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonathan Jackson
committed
Apr 16, 2013
1 parent
05812ed
commit 20fec24
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |