From daf3656914f600d863f8c0b9046e0d5343152e80 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 14 Jul 2014 07:26:22 +0200 Subject: [PATCH] Fixed session backend of ticket overview list. --- app/models/user.rb | 2 +- lib/sessions/backend/ticket_overview_list.rb | 79 +++++++++++--------- test/unit/session_basic_test.rb | 42 +++-------- test/unit/session_basic_ticket_test.rb | 63 ++++++++++++++++ 4 files changed, 119 insertions(+), 67 deletions(-) create mode 100644 test/unit/session_basic_ticket_test.rb diff --git a/app/models/user.rb b/app/models/user.rb index d3a955612..b2030ed3d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -93,7 +93,7 @@ returns self.roles.each { |role| return role if role.name == role_name } - return false + false end =begin diff --git a/lib/sessions/backend/ticket_overview_list.rb b/lib/sessions/backend/ticket_overview_list.rb index 3432fced9..2119b428a 100644 --- a/lib/sessions/backend/ticket_overview_list.rb +++ b/lib/sessions/backend/ticket_overview_list.rb @@ -12,17 +12,27 @@ class Sessions::Backend::TicketOverviewList overviews = Ticket::Overviews.all( :current_user => @user, ) + result = [] + overviews.each { |overview| + overview_data = Ticket::Overviews.list( + :view => overview.link, + :current_user => @user, + :array => true, + ) + data = { :list => overview_data, :index => overview } + result.push data + } # no data exists - return if !overviews + return if !result || result.empty? # no change exists - return if @last_change == overviews + return if @last_change == result # remember last state - @last_change = overviews + @last_change = result - overviews + result end def client_key @@ -36,20 +46,17 @@ class Sessions::Backend::TicketOverviewList return if timeout # set new timeout - Sessions::CacheIn.set( self.client_key, true, { :expires_in => 5.seconds } ) + Sessions::CacheIn.set( self.client_key, true, { :expires_in => 6.seconds } ) - overviews = self.load + items = self.load - return if !overviews + return if !items # push overviews - overviews.each { |overview| + results = [] + items.each { |item| - overview_data = Ticket::Overviews.list( - :view => overview.link, - :current_user => @user, - :array => true, - ) + overview_data = item[:list] assets = {} overview_data[:ticket_ids].each {|ticket_id| @@ -82,33 +89,37 @@ class Sessions::Backend::TicketOverviewList } if !@client - return { + result = { :event => 'navupdate_ticket_overview', - :data => overview, + :data => item[:index], } - end + results.push result + else - @client.log 'notify', "push overview_list for user #{ @user.id }" + @client.log 'notify', "push overview_list for user #{ @user.id }" - # send update to browser - @client.send({ - :data => assets, - :event => [ 'loadAssets' ] - }) - @client.send({ - :data => { - :overview => overview_data[:overview], - :ticket_ids => overview_data[:ticket_ids], - :tickets_count => overview_data[:tickets_count], - :bulk => { - :group_id__owner_id => groups_users, - :owner_id => [], + # send update to browser + @client.send({ + :data => assets, + :event => [ 'loadAssets' ] + }) + @client.send({ + :data => { + :overview => overview_data[:overview], + :ticket_ids => overview_data[:ticket_ids], + :tickets_count => overview_data[:tickets_count], + :bulk => { + :group_id__owner_id => groups_users, + :owner_id => [], + }, }, - }, - :event => [ 'ticket_overview_rebuild' ], - :collection => 'ticket_overview_' + overview.link.to_s, - }) + :event => [ 'ticket_overview_rebuild' ], + :collection => 'ticket_overview_' + item[:index].link.to_s, + }) + end } + return results if !@client + nil end end \ No newline at end of file diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index af6cd0360..0705c2a50 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -47,6 +47,8 @@ class SessionBasicTest < ActiveSupport::TestCase test 'b collections group' do require 'sessions/backend/collections/group.rb' + + UserInfo.current_user_id = 1 user = User.lookup(:id => 1) collection_client1 = Sessions::Backend::Collections::Group.new(user, false, '123-1') collection_client2 = Sessions::Backend::Collections::Group.new(user, false, '234-2') @@ -88,7 +90,7 @@ class SessionBasicTest < ActiveSupport::TestCase assert_equal( result1, result2, "check collections" ) # change collection - group = Group.create( :name => 'SomeGroup::' + rand(999999).to_s, :active => true, :created_by_id => 1, :updated_by_id => 1 ) + group = Group.create( :name => 'SomeGroup::' + rand(999999).to_s, :active => true ) sleep 12 # get whole collections @@ -137,6 +139,7 @@ class SessionBasicTest < ActiveSupport::TestCase test 'b collections organization' do require 'sessions/backend/collections/organization.rb' + UserInfo.current_user_id = 1 Organization.destroy_all user = User.lookup(:id => 1) @@ -159,7 +162,7 @@ class SessionBasicTest < ActiveSupport::TestCase assert( !result2, "check collections - recall" ) # change collection - org = Organization.create( :name => 'SomeOrg::' + rand(999999).to_s, :active => true, :created_by_id => 1, :updated_by_id => 1 ) + org = Organization.create( :name => 'SomeOrg::' + rand(999999).to_s, :active => true ) sleep 16 # get whole collections @@ -209,6 +212,8 @@ class SessionBasicTest < ActiveSupport::TestCase test 'b activity stream' do + UserInfo.current_user_id = 1 + # create users roles = Role.where( :name => [ 'Agent', 'Admin'] ) groups = Group.all @@ -244,7 +249,7 @@ class SessionBasicTest < ActiveSupport::TestCase assert( !result1, "check as - recall 2" ) agent1.update_attribute( :email, 'activity-stream-agent11@example.com' ) - ticket = Ticket.create(:title => '12323', :updated_by_id => 1, :created_by_id => 1, :group_id => 1, :priority_id => 1, :state_id => 1, :customer_id => 1) + ticket = Ticket.create(:title => '12323', :group_id => 1, :priority_id => 1, :state_id => 1, :customer_id => 1 ) sleep 32 @@ -285,6 +290,7 @@ class SessionBasicTest < ActiveSupport::TestCase test 'b ticket_create' do + UserInfo.current_user_id = 1 user = User.lookup(:id => 1) ticket_create_client1 = Sessions::Backend::TicketCreate.new(user, false, '123-1') @@ -302,7 +308,7 @@ class SessionBasicTest < ActiveSupport::TestCase result1 = ticket_create_client1.push assert( !result1, "check ticket_create - recall 2" ) - Group.create( :name => 'SomeTicketCreateGroup::' + rand(999999).to_s, :active => true, :created_by_id => 1, :updated_by_id => 1 ) + Group.create( :name => 'SomeTicketCreateGroup::' + rand(999999).to_s, :active => true ) sleep 26 @@ -311,32 +317,4 @@ class SessionBasicTest < ActiveSupport::TestCase assert( result1, "check ticket_create - recall 3" ) end - test 'b ticket_overview_index' do - - user = User.lookup(:id => 1) - ticket_overview_index_client1 = Sessions::Backend::TicketOverviewIndex.new(user, false, '123-1') - - # get as stream - result1 = ticket_overview_index_client1.push - assert( result1, "check ticket_overview_index" ) - sleep 1 - - # next check should be empty - result1 = ticket_overview_index_client1.push - assert( !result1, "check ticket_overview_index - recall" ) - - # next check should be empty - sleep 10 - result1 = ticket_overview_index_client1.push - assert( !result1, "check ticket_overview_index - recall 2" ) - - ticket = Ticket.create( :title => '12323', :updated_by_id => 1, :created_by_id => 1, :group_id => 1, :priority_id => 1, :state_id => 1, :customer_id => 1) - - sleep 10 - - # get as stream - result1 = ticket_overview_index_client1.push - assert( result1, "check ticket_overview_index - recall 3" ) - end - end \ No newline at end of file diff --git a/test/unit/session_basic_ticket_test.rb b/test/unit/session_basic_ticket_test.rb new file mode 100644 index 000000000..df56f11d6 --- /dev/null +++ b/test/unit/session_basic_ticket_test.rb @@ -0,0 +1,63 @@ +# encoding: utf-8 +require 'test_helper' + +class SessionBasicTicketTest < ActiveSupport::TestCase + test 'b ticket_overview_index' do + + UserInfo.current_user_id = 1 + user = User.lookup(:id => 1) + client1 = Sessions::Backend::TicketOverviewIndex.new(user, false, '123-1') + + # get as stream + result1 = client1.push + assert( result1, "check ticket_overview_index" ) + sleep 1 + + # next check should be empty + result1 = client1.push + assert( !result1, "check ticket_overview_index - recall" ) + + # next check should be empty + sleep 10 + result1 = client1.push + assert( !result1, "check ticket_overview_index - recall 2" ) + + ticket = Ticket.create( :title => '12323', :group_id => 1, :priority_id => 1, :state_id => 1, :customer_id => 1 ) + + sleep 10 + + # get as stream + result1 = client1.push + assert( result1, "check ticket_overview_index - recall 3" ) + end + + test 'b ticket_overview_list' do + + UserInfo.current_user_id = 1 + user = User.lookup(:id => 1) + client1 = Sessions::Backend::TicketOverviewList.new(user, false, '123-1') + + # get as stream + result1 = client1.push + assert( result1, "check ticket_overview_list" ) + sleep 1 + + # next check should be empty + result1 = client1.push + assert( !result1, "check ticket_overview_list - recall" ) + + # next check should be empty + sleep 10 + result1 = client1.push + assert( !result1, "check ticket_overview_list - recall 2" ) + + ticket = Ticket.create( :title => '12323', :group_id => 1, :priority_id => 1, :state_id => 1, :customer_id => 1 ) + + sleep 10 + + # get as stream + result1 = client1.push + puts "RR: #{result1.inspect}" + assert( result1, "check ticket_overview_list - recall 3" ) + end +end \ No newline at end of file