Skip to content
This repository was archived by the owner on Jun 7, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ Style/FileName:

Style/Documentation:
Enabled: false

Metrics/MethodLength:
Enabled: false
18 changes: 16 additions & 2 deletions lib/lita/handlers/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ def store_queue(room, queue)
redis.set room.id, MultiJson.dump(queue)
end

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

response.reply t('messages.is_the_next_on_queue_motivate',
mention: queue.first)

robot.trigger(:queue_change,
current: queue.first,
room: room,
queue: queue)
end

# Commands

def queue_list(response)
Expand All @@ -47,6 +60,7 @@ def queue_me(response)
queue << me
store_queue(room, queue)
response.reply t('messages.added_to_queue', mention: me)
trigger_change(response) if queue.first == me
end
end

Expand Down Expand Up @@ -85,7 +99,7 @@ def queue_change_to_next(response)
removed = queue.shift
store_queue(room, queue)
response.reply t('messages.removed_from_queue', mention: removed)
response.reply t('messages.is_the_next_on_queue_motivate', mention: queue.first) unless queue.empty?
trigger_change(response) unless queue.empty?
end

response.reply display_queue(queue, room)
Expand All @@ -99,7 +113,7 @@ def queue_rotate(response)
new_queue = queue.rotate
store_queue(room, new_queue)
response.reply t('messages.moved_to_the_end_of_queue', mention: queue.first)
response.reply t('messages.is_the_next_on_queue_motivate', mention: new_queue.first)
trigger_change(response)
end

response.reply display_queue(queue, room)
Expand Down
13 changes: 12 additions & 1 deletion spec/lita/handlers/queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,24 @@
end
end

context "when I'm not on queue" do
context "when I'm not on queue, and the queue has someone else" do
before { subject.store_queue(room, ['someone']) }

it 'replies with a confirmation message' do
send_command('queue me', from: room)
expect(replies.last).to include("#{user.name} have been added to queue")
expect(subject.fetch_queue(room)).to include(user.mention_name)
end
end

context "when I'm not on queue, and the queue is empty" do
it 'replies with a confirmation message' do
send_command('queue me', from: room)
expect(replies).to include("#{user.name} have been added to queue.")
expect(replies).to include("#{user.name} is the next. Go ahead!")
expect(subject.fetch_queue(room)).to include(user.mention_name)
end
end
end

describe '#unqueue_me' do
Expand Down