Skip to content
Browse files

Return random open tickets when asking for work.

  • Loading branch information...
1 parent c8efb35 commit 6436957acb879522a0d6683be4fc7ba78eb14e20 @alloy alloy committed Dec 3, 2010
Showing with 22 additions and 35 deletions.
  1. +4 −0 lib/macruby_bugmash_bot/ticket.rb
  2. +2 −10 lib/macruby_bugmash_bot/trac.rb
  3. +16 −25 spec/trac_spec.rb
View
4 lib/macruby_bugmash_bot/ticket.rb
@@ -73,6 +73,10 @@ def self.tickets_marked_for_review
DB.tickets.filter(:marked_for_review => true, :closed => false).order(:id).all
end
+ def self.random_open_ticket
+ tickets.filter(:assigned_to => nil).order('RAND()').first
+ end
+
OPEN_TICKETS_RSS_FEED = URI.parse("http://www.macruby.org/trac/query?status=new&status=reopened&format=rss&col=id&col=summary&col=status&col=time&order=priority&max=1000")
def self.raw_open_tickets_feed
View
12 lib/macruby_bugmash_bot/trac.rb
@@ -55,16 +55,8 @@ def marked_for_review
# Returns a ticket that nobody is working on yet, in ascending order.
def open_ticket
- ot = nil
- @active_tickets.keys.sort.each do |id|
- t = ticket(id)
- unless t[:assigned_to]
- ot = t
- break
- end
- end
- if ot
- "Ticket available #{ticket_message(ot[:id])}"
+ if ot = DB.random_open_ticket
+ "Ticket available #{_ticket_message(ot)}"
else
"There are no more open tickets! \o/"
end
View
41 spec/trac_spec.rb
@@ -2,8 +2,6 @@
require "bacon"
Bacon.summary_at_exit
-require "fileutils"
-
$:.unshift File.expand_path("../../lib", __FILE__)
require "macruby_bugmash_bot/trac"
@@ -17,7 +15,7 @@ def fixture_read(name)
class DB
def self.db_path
- @db_path ||= "/tmp/bugmash-bot-test-#{Time.now.to_i}.sqlite3"
+ # in memory
end
def self.stubbed_feed=(xml)
@@ -40,32 +38,27 @@ def self.raw_open_tickets_feed
@trac = Trac.new
end
- #it "parses the raw RSS feed" do
- #@trac.active_tickets[189][:id].should == 189
- #@trac.active_tickets[189][:summary].should == "#189: Bugs with: Class#dup & Object#dup"
- #@trac.active_tickets[105][:id].should == 105
- #@trac.active_tickets[105][:summary].should == "#105: BridgeSupport can't convert KCGSessionEventTap as an argument for CGEventTapCreate"
- #end
-
it "returns a ticket by ID" do
@trac.ticket(105)[:id].should == 105
@trac.ticket(105)[:summary].should == "#105: BridgeSupport can't convert KCGSessionEventTap as an argument for CGEventTapCreate"
end
- # Make random
- #it "returns a ticket that nobody is working on yet, in ascending ID order" do
- #@trac.open_ticket.should == "Ticket available #19: Problems with method_missing (http://www.macruby.org/trac/ticket/19)"
- #@trac.open_ticket.should == "Ticket available #19: Problems with method_missing (http://www.macruby.org/trac/ticket/19)"
- #@trac.assign_ticket(19, "alloy")
- #@trac.open_ticket.should == "Ticket available #47: Cannot pass a :symbol directly as a named parameter (http://www.macruby.org/trac/ticket/47)"
- #@trac.open_ticket.should == "Ticket available #47: Cannot pass a :symbol directly as a named parameter (http://www.macruby.org/trac/ticket/47)"
- #@trac.assign_ticket("47", "alloy")
- #@trac.open_ticket.should == "Ticket available #81: Enumerable::Enumerator seems to be broken (http://www.macruby.org/trac/ticket/81)"
- #@trac.open_ticket.should == "Ticket available #81: Enumerable::Enumerator seems to be broken (http://www.macruby.org/trac/ticket/81)"
+ it "returns a ticket that nobody is working on yet, in ascending ID order" do
+ @trac.assign_ticket("19", "alloy")
+ 100.times do
+ @trac.open_ticket.should.not == "Ticket available #19: Problems with method_missing (http://www.macruby.org/trac/ticket/19)"
+ end
+
+ DB.tickets.filter(:assigned_to => nil).each do |ticket|
+ DB.tickets.filter(:id => ticket[:id]).update(:assigned_to => 1)
+ end
- #@trac.active_tickets.each { |_, t| t[:assigned_to] = "alloy" }
- #@trac.open_ticket.should == "There are no more open tickets! \o/"
- #end
+ @trac.resign_from_ticket("19", "alloy")
+ @trac.open_ticket.should == "Ticket available #19: Problems with method_missing (http://www.macruby.org/trac/ticket/19)"
+
+ @trac.assign_ticket("19", "alloy")
+ @trac.open_ticket.should == "There are no more open tickets! \o/"
+ end
it "assigns a ticket to a user" do
@trac.assign_ticket("19", "alloy").should == "Ticket #19 is now assigned to `alloy'."
@@ -186,5 +179,3 @@ def self.raw_open_tickets_feed
@trac.marked_for_review.should == ["There is currently 1 ticket marked for review:", "#105: BridgeSupport can't convert KCGSessionEventTap as an argument for CGEventTapCreate (http://www.macruby.org/trac/ticket/105)"]
end
end
-
-FileUtils.rm(DB.db_path)

0 comments on commit 6436957

Please sign in to comment.
Something went wrong with that request. Please try again.