From e133bd2ad6be8a359cfa9dbc2029b879a679a79f Mon Sep 17 00:00:00 2001 From: Matthew Terwilliger Date: Sun, 7 Jan 2018 17:04:26 -0500 Subject: [PATCH] Update queue pop button functionality to allow popping people from the queue that are pinned by others. The pop order is now: pinned by you, not pinned, pinned by others, which mirrors the way it is displayed in the UI. Since the queue pop button can now pop up to $requests.length requests, this closes #98. --- app/models/course_queue.rb | 2 ++ test/models/course_queue_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/course_queue.rb b/app/models/course_queue.rb index d7f780e..90d3542 100644 --- a/app/models/course_queue.rb +++ b/app/models/course_queue.rb @@ -41,6 +41,8 @@ def pop!(user) first_pinned.resolve_by!(user) elsif first_non_pinned = self.outstanding_requests.where(resolver: nil).first first_non_pinned.resolve_by!(user) + elsif first_pinned_by_others = self.outstanding_requests.where.not(resolver: user).first + first_pinned_by_others.resolve_by!(user) end end diff --git a/test/models/course_queue_test.rb b/test/models/course_queue_test.rb index 7a9559e..dccb3fe 100644 --- a/test/models/course_queue_test.rb +++ b/test/models/course_queue_test.rb @@ -91,8 +91,8 @@ class CourseQueueTest < ActiveSupport::TestCase assert request == course_queue_entries(:unresolved_entry) - # pinned by matt shouldn't be resolvable by jim - assert_nil @queue.pop!(users(:jim)) + # if the queue is empty we will allow entries pinned by others to be popped + assert @queue.pop!(users(:jim)) == pinned_by_matt end test "request validates duplicates in group mode" do