From 0a49faf417a993e838d1c37361d573bb86223f75 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 29 Nov 2012 15:56:41 -0800 Subject: Not yet done, but more sophisticated and refactored ticket filtering. Still have to do more, including allowing user to pick sort order. --- help/test/unit/ticket_test.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'help/test') diff --git a/help/test/unit/ticket_test.rb b/help/test/unit/ticket_test.rb index 691597a..e93a121 100644 --- a/help/test/unit/ticket_test.rb +++ b/help/test/unit/ticket_test.rb @@ -64,27 +64,30 @@ class TicketTest < ActiveSupport::TestCase end test "find tickets user commented on" do + # clear old tickets just in case - Ticket.by_commented_by.key('123').each {|t| t.destroy} + # this will cause RestClient::ResourceNotFound errors if there are multiple copies of the same ticket returned + Ticket.includes_post_by.key('123').each {|t| t.destroy} testticket = Ticket.create :title => "test retrieving commented tickets" comment = TicketComment.new :body => "my email broke", :posted_by => "123" assert_equal 0, testticket.comments.count - assert_equal [], Ticket.by_commented_by.key('123').all; + assert_equal [], Ticket.includes_post_by.key('123').all testticket.comments << comment testticket.save assert_equal 1, testticket.reload.comments.count - assert_equal [testticket], Ticket.by_commented_by.key('123').all; + assert_equal [testticket], Ticket.includes_post_by.key('123').all comment = TicketComment.new :body => "another comment", :posted_by => "123" testticket.comments << comment testticket.save - #this will now fail, as Ticket.by_commented_by will return 2 copies of the same ticket as both of the ticket's comments match - assert_equal [testticket], Ticket.by_commented_by.key('123').all; + + # this will ensure that the ticket is only included once, even though the user has commented on the ticket twice: + assert_equal [testticket], Ticket.includes_post_by.key('123').all testticket.destroy - assert_equal [], Ticket.by_commented_by.key('123').all; + assert_equal [], Ticket.includes_post_by.key('123').all; end end -- cgit v1.2.3