From 2401d860cd815b65c47699c7ee734d5e0437c3da Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 23 Aug 2014 15:42:25 +0200 Subject: [PATCH] Added unit tests. --- test/unit/recent_view_test.rb | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/unit/recent_view_test.rb diff --git a/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb new file mode 100644 index 000000000..2778aaec6 --- /dev/null +++ b/test/unit/recent_view_test.rb @@ -0,0 +1,59 @@ +# encoding: utf-8 +require 'test_helper' + +class RecentViewTest < ActiveSupport::TestCase + + test 'simple tests' do + + ticket1 = Ticket.create( + :title => 'RecentViewTest 1 some title äöüß', + :group => Group.lookup( :name => 'Users'), + :customer_id => 2, + :state => Ticket::State.lookup( :name => 'new' ), + :priority => Ticket::Priority.lookup( :name => '2 normal' ), + :updated_by_id => 1, + :created_by_id => 1, + ) + assert( ticket1, "ticket created" ) + ticket2 = Ticket.create( + :title => 'RecentViewTest 2 some title äöüß', + :group => Group.lookup( :name => 'Users'), + :customer_id => 2, + :state => Ticket::State.lookup( :name => 'new' ), + :priority => Ticket::Priority.lookup( :name => '2 normal' ), + :updated_by_id => 1, + :created_by_id => 1, + ) + assert( ticket2, "ticket created" ) + user1 = User.find(2) + #RecentView.user_log_destroy(user1) + + + RecentView.log( ticket1, user1 ) + sleep 1 + RecentView.log( ticket2, user1 ) + sleep 1 + RecentView.log( ticket1, user1 ) + sleep 1 + RecentView.log( ticket1, user1 ) + + list = RecentView.list( user1 ) + assert( list[0]['o_id'], ticket1.id ) + assert( list[0]['recent_view_object'], 'Ticket' ) + + assert( list[1]['o_id'], ticket1.id ) + assert( list[1]['recent_view_object'], 'Ticket' ) + + assert( list[2]['o_id'], ticket2.id ) + assert( list[2]['recent_view_object'], 'Ticket' ) + + assert( list[3]['o_id'], ticket1.id ) + assert( list[3]['recent_view_object'], 'Ticket' ) + + ticket1.destroy + ticket2.destroy + + #list = RecentView.list( user1 ) + #assert( !list[0], 'check if recent view list is empty' ) + end +end