recent_view_test.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class RecentViewTest < ActiveSupport::TestCase
  4. test 'simple tests' do
  5. ticket1 = Ticket.create(
  6. :title => 'RecentViewTest 1 some title äöüß',
  7. :group => Group.lookup( :name => 'Users'),
  8. :customer_id => 2,
  9. :state => Ticket::State.lookup( :name => 'new' ),
  10. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  11. :updated_by_id => 1,
  12. :created_by_id => 1,
  13. )
  14. assert( ticket1, "ticket created" )
  15. ticket2 = Ticket.create(
  16. :title => 'RecentViewTest 2 some title äöüß',
  17. :group => Group.lookup( :name => 'Users'),
  18. :customer_id => 2,
  19. :state => Ticket::State.lookup( :name => 'new' ),
  20. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  21. :updated_by_id => 1,
  22. :created_by_id => 1,
  23. )
  24. assert( ticket2, "ticket created" )
  25. user1 = User.find(2)
  26. RecentView.user_log_destroy(user1)
  27. RecentView.log( ticket1.class.to_s, ticket1.id, user1 )
  28. sleep 1
  29. RecentView.log( ticket2.class.to_s, ticket2.id, user1 )
  30. sleep 1
  31. RecentView.log( ticket1.class.to_s, ticket1.id, user1 )
  32. sleep 1
  33. RecentView.log( ticket1.class.to_s, ticket1.id, user1 )
  34. list = RecentView.list( user1 )
  35. assert( list[0]['o_id'], ticket1.id )
  36. assert( list[0]['object'], 'Ticket' )
  37. assert( list[1]['o_id'], ticket1.id )
  38. assert( list[1]['object'], 'Ticket' )
  39. assert( list[2]['o_id'], ticket2.id )
  40. assert( list[2]['object'], 'Ticket' )
  41. assert( list[3]['o_id'], ticket1.id )
  42. assert( list[3]['object'], 'Ticket' )
  43. ticket1.destroy
  44. ticket2.destroy
  45. list = RecentView.list( user1 )
  46. assert( !list[0], 'check if recent view list is empty' )
  47. end
  48. end