Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Commit

Permalink
List next on queue, some refractories and preparing for release
Browse files Browse the repository at this point in the history
  • Loading branch information
brodock committed Jun 15, 2015
1 parent 3eed24a commit f8d00eb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

We follow [Keep a Changelog](http://keepachangelog.com/) format.

## 0.1.0 - UNRELEASED
## 0.1.0 - 2015-06-14
### Added
- Initial plugin import with support for the following commands:
* lita queue
* lita queue me
* lita unqueue me
* lita queue next?
* lita queue next!
- RSpec, Travis CI and Coveralls support
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ The following commands are available:
* lita unqueue me
* lita queue next?
* lita queue next!

The following commands will be available in a further version:
* lita queue rotate!
* lita queue = [<new_queue,comma_separated>]
43 changes: 28 additions & 15 deletions lib/lita/handlers/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Queue < Handler
route(/^unqueue me$/, :unqueue_me, command: :true)
route(/^queue next\?$/, :queue_list_next, command: :true)
route(/^queue next!$/, :queue_change_to_next, command: :true)
route(/^queue rotate!$/, :queue_rotate, command: :true)
route(/^queue = \[([^\]]*)\]\s*$$/, :queue_recreate, command: :true)
#route(/^queue rotate!$/, :queue_rotate, command: :true)
#route(/^queue = \[([^\]]*)\]\s*$$/, :queue_recreate, command: :true)

# API

Expand All @@ -32,11 +32,7 @@ def queue_list(response)
room = room_for(response)
queue = fetch_queue(room)

if queue.empty?
response.reply "Queue is empty"
else
response.reply "Queue for #{room}: #{queue}"
end
response.reply display_queue(queue, room)
end

def queue_me(response)
Expand All @@ -49,7 +45,7 @@ def queue_me(response)
else
queue << me
store_queue(room, queue)
response.reply "#{me} have been added to queue: #{queue}"
response.reply "#{me} have been added to queue."
end
end

Expand All @@ -61,35 +57,52 @@ def unqueue_me(response)
if queue.include? me
queue.delete(me)
store_queue(room, queue)
response.reply "#{me} have been removed from queue"
response.reply "#{me} have been removed from queue."
else
response.reply "You are not on queue!"
end
end

def queue_change_to_next(response)
def queue_list_next(response)
room = room_for(response)
queue = fetch_queue(room)

if queue.empty?
response.reply "Queue is empty"
elsif queue.size == 1
response.reply "#{queue.first} is the last one on queue."
else
response.reply "#{queue[1]} will be the next!"
end
end

def queue_change_to_next(response)
room = room_for(response)
queue = fetch_queue(room)

unless queue.empty?
removed = queue.shift
store_queue(room, queue)
response.reply "#{removed} have been removed from queue"
if queue.empty?
response.reply "Queue is empty"
else
response.reply "Queue for #{room}: #{queue}"
end
response.reply "#{queue.first} is the next. Go ahead!" unless queue.empty?
end

response.reply display_queue(queue, room)
end

private

def room_for(response)
response.message.source.room || '--global--'
end

def display_queue(queue, room)
if queue.empty?
"Queue is empty"
else
"Queue for #{room}: #{queue}"
end
end
end

Lita.register_handler(Queue)
Expand Down
35 changes: 31 additions & 4 deletions spec/lita/handlers/queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
it { is_expected.to route_command("unqueue me").to(:unqueue_me) }
it { is_expected.to route_command("queue next?").to(:queue_list_next) }
it { is_expected.to route_command("queue next!").to(:queue_change_to_next) }
it { is_expected.to route_command("queue rotate!").to(:queue_rotate) }
it { is_expected.to route_command("queue = [something,here]").to(:queue_recreate) }
#it { is_expected.to route_command("queue rotate!").to(:queue_rotate) }
#it { is_expected.to route_command("queue = [something,here]").to(:queue_recreate) }

let(:channel) { source.room || '--global--' }

Expand Down Expand Up @@ -73,9 +73,35 @@
end
end

describe "#queue_list_next" do
context "when queue is empty" do
it "replies with an error message" do
send_command("queue next?")
expect(replies.last).to include("Queue is empty")
end
end

context "when queue has only one element" do
before { subject.store_queue(channel, [user1.mention_name]) }
it "replies listing current user on queue and warning that's the last one" do
send_command("queue next?")
expect(replies.last).to include(user1.mention_name)
expect(replies.last).to include("is the last one on queue")
end
end

context "when queue has more than one elements" do
before { subject.store_queue(channel, [user1.mention_name, user2.mention_name]) }
it "replies listing the next one on the queue" do
send_command("queue next?")
expect(replies.last).to include(user2.mention_name)
end
end
end

describe "#queue_change_to_next" do
context "when queue is empty" do
it "replies with and error message" do
it "replies with an error message" do
send_command("queue next!")
expect(replies.last).to include("Queue is empty")
end
Expand All @@ -86,9 +112,10 @@
subject.store_queue(channel, [user1.mention_name, user2.mention_name])

send_command("queue next!")
expect(replies.first).to include("#{user1.mention_name} have been removed from queue")
expect(replies[1]).to include("#{user2.mention_name} is the next")
expect(replies.last).to include(user2.mention_name)
expect(replies.last).not_to include(user1.mention_name)
expect(replies.first).to include("#{user1.mention_name} have been removed from queue")
end

it "replies with a notification message when removing the last element from queue" do
Expand Down

0 comments on commit f8d00eb

Please sign in to comment.