summaryrefslogtreecommitdiff
path: root/help/test/unit/ticket_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'help/test/unit/ticket_test.rb')
-rw-r--r--help/test/unit/ticket_test.rb38
1 files changed, 35 insertions, 3 deletions
diff --git a/help/test/unit/ticket_test.rb b/help/test/unit/ticket_test.rb
index 6b63a23..e93a121 100644
--- a/help/test/unit/ticket_test.rb
+++ b/help/test/unit/ticket_test.rb
@@ -23,7 +23,7 @@ class TicketTest < ActiveSupport::TestCase
#user = LeapWebUsers::User.create
#t.user = user
-
+
#t.email = '' #invalid
#assert !t.valid?
#t.email = 'blah@blah.com, bb@jjj.org'
@@ -40,7 +40,7 @@ class TicketTest < ActiveSupport::TestCase
@sample.created_by = 22 #current_user
assert @sample.is_creator_validated?
end
-
+
=begin
# TODO: do once have current_user stuff in order
test "code if & only if not creator-validated" do
@@ -56,6 +56,38 @@ class TicketTest < ActiveSupport::TestCase
end
=end
-end
+ test "finds open tickets sorted by created_at" do
+ tickets = Ticket.by_is_open_and_created_at.
+ startkey([true, 0]).
+ endkey([true, Time.now + 10.hours]) # some tickets were created in the future
+ assert_equal Ticket.by_is_open.key(true).count, tickets.count
+ end
+
+ test "find tickets user commented on" do
+
+ # clear old tickets just in case
+ # 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.includes_post_by.key('123').all
+ testticket.comments << comment
+ testticket.save
+ assert_equal 1, testticket.reload.comments.count
+ 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 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.includes_post_by.key('123').all;
+ end
+
+end