From 417545adaa6bdadeea17266389c20ba439226064 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 30 May 2014 09:57:35 +0200 Subject: [PATCH] Fixed activity stream feature. --- app/models/activity_stream.rb | 6 +-- app/models/application_model.rb | 6 +-- test/unit/activity_stream_test.rb | 69 ++++++++++++++----------------- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index b1ebeb87d..9bc64eeb2 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -49,10 +49,10 @@ add a new activity entry for an object :role_id => role_id, :activity_stream_object_id => object.id, :created_by_id => data[:created_by_id] - ).last + ).order('created_at DESC, id ASC').last - # resturn if old entry is really freash - return result if result && result.created_at >= (data[:created_at] - 10.seconds) + # resturn if old entry is really fresh + return result if result && result.created_at.to_i >= ( data[:created_at].to_i - 12 ) # create history record = { diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 447faf05e..1fc31cf78 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -424,7 +424,7 @@ class OwnModel < ApplicationModel # return if we run import mode return if Setting.get('import_mode') - + puts "#{ self.class.name }.find(#{ self.id }) notify created " + self.created_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( @@ -452,7 +452,7 @@ class OwnModel < ApplicationModel # return if we run import mode return if Setting.get('import_mode') - puts "#{self.class.name.downcase} UPDATED " + self.updated_at.to_s + puts "#{ self.class.name }.find(#{ self.id }) notify UPDATED " + self.updated_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( @@ -479,7 +479,7 @@ class OwnModel < ApplicationModel # return if we run import mode return if Setting.get('import_mode') - puts "#{self.class.name.downcase} DESTOY " + self.updated_at.to_s + puts "#{ self.class.name }.find(#{ self.id }) notify DESTOY " + self.updated_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( diff --git a/test/unit/activity_stream_test.rb b/test/unit/activity_stream_test.rb index 405f20324..007b2bd94 100644 --- a/test/unit/activity_stream_test.rb +++ b/test/unit/activity_stream_test.rb @@ -77,35 +77,33 @@ class ActivityStreamTest < ActiveSupport::TestCase ticket = nil article = nil - # use transaction - ActiveRecord::Base.transaction do - ticket = Ticket.create( test[:create][:ticket] ) - test[:check][0][:o_id] = ticket.id - test[:check][0][:created_at] = ticket.created_at - test[:check][0][:created_by_id] = current_user.id - sleep 2 - test[:create][:article][:ticket_id] = ticket.id - article = Ticket::Article.create( test[:create][:article] ) - test[:check][1][:o_id] = article.id - test[:check][1][:created_at] = article.created_at - test[:check][1][:created_by_id] = current_user.id + ticket = Ticket.create( test[:create][:ticket] ) + test[:check][0][:o_id] = ticket.id + test[:check][0][:created_at] = ticket.created_at + test[:check][0][:created_by_id] = current_user.id + sleep 2 - assert_equal( ticket.class.to_s, 'Ticket' ) - assert_equal( article.class.to_s, 'Ticket::Article' ) + test[:create][:article][:ticket_id] = ticket.id + article = Ticket::Article.create( test[:create][:article] ) + test[:check][1][:o_id] = article.id + test[:check][1][:created_at] = article.created_at + test[:check][1][:created_by_id] = current_user.id - # update ticket - if test[:update][:ticket] - ticket.update_attributes( test[:update][:ticket] ) + assert_equal( ticket.class.to_s, 'Ticket' ) + assert_equal( article.class.to_s, 'Ticket::Article' ) - # check updated user - test[:check][2][:o_id] = current_user.id - test[:check][2][:created_at] = ticket.created_at - test[:check][2][:created_by_id] = current_user.id - end - if test[:update][:article] - article.update_attributes( test[:update][:article] ) - end + # update ticket + if test[:update][:ticket] + ticket.update_attributes( test[:update][:ticket] ) + + # check updated user + test[:check][2][:o_id] = current_user.id + test[:check][2][:created_at] = ticket.created_at + test[:check][2][:created_by_id] = current_user.id + end + if test[:update][:article] + article.update_attributes( test[:update][:article] ) end # remember ticket @@ -167,7 +165,7 @@ class ActivityStreamTest < ActiveSupport::TestCase test[:check][0][:o_id] = organization.id test[:check][0][:created_at] = organization.created_at test[:check][0][:created_by_id] = current_user.id - sleep 11 + sleep 2 assert_equal( organization.class.to_s, 'Organization' ) @@ -176,7 +174,7 @@ class ActivityStreamTest < ActiveSupport::TestCase test[:check][1][:o_id] = organization.id test[:check][1][:updated_at] = organization.updated_at test[:check][1][:created_by_id] = current_user.id - sleep 2 + sleep 13 end if test[:update2][:organization] @@ -266,8 +264,6 @@ class ActivityStreamTest < ActiveSupport::TestCase } end - - test 'user with update check true' do tests = [ @@ -347,25 +343,24 @@ class ActivityStreamTest < ActiveSupport::TestCase end def activity_stream_check( activity_stream_list, checks ) - puts 'AS ' + activity_stream_list.inspect + #puts 'AS ' + activity_stream_list.inspect checks.each { |check_item| - puts '+++++++++++' - puts check_item.inspect + #puts '+++++++++++' + #puts check_item.inspect match = false activity_stream_list.each { |item| next if match - puts '--------' - puts item.inspect - # puts item.object + #puts '--------' + #puts item.inspect next if item['object'] != check_item[:object] next if item['type'] != check_item[:type] next if item['o_id'] != check_item[:o_id] match = true } if check_item[:result] - assert( match, "activity stream check not matched! #{check_item.inspect}") + assert( match, "activity stream check not matched! #{ check_item.inspect } not in #{ activity_stream_list.inspect }") else - assert( !match, "activity stream check matched but should not! #{check_item.inspect}") + assert( !match, "activity stream check matched but should not! #{ check_item.inspect } not in #{ activity_stream_list.inspect }") end } end