Fixed activity stream feature.
This commit is contained in:
parent
e1455c6053
commit
417545adaa
3 changed files with 38 additions and 43 deletions
|
@ -49,10 +49,10 @@ add a new activity entry for an object
|
||||||
:role_id => role_id,
|
:role_id => role_id,
|
||||||
:activity_stream_object_id => object.id,
|
:activity_stream_object_id => object.id,
|
||||||
:created_by_id => data[:created_by_id]
|
:created_by_id => data[:created_by_id]
|
||||||
).last
|
).order('created_at DESC, id ASC').last
|
||||||
|
|
||||||
# resturn if old entry is really freash
|
# resturn if old entry is really fresh
|
||||||
return result if result && result.created_at >= (data[:created_at] - 10.seconds)
|
return result if result && result.created_at.to_i >= ( data[:created_at].to_i - 12 )
|
||||||
|
|
||||||
# create history
|
# create history
|
||||||
record = {
|
record = {
|
||||||
|
|
|
@ -424,7 +424,7 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('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 = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Sessions.broadcast(
|
Sessions.broadcast(
|
||||||
|
@ -452,7 +452,7 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('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 = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Sessions.broadcast(
|
Sessions.broadcast(
|
||||||
|
@ -479,7 +479,7 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('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 = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Sessions.broadcast(
|
Sessions.broadcast(
|
||||||
|
|
|
@ -77,35 +77,33 @@ class ActivityStreamTest < ActiveSupport::TestCase
|
||||||
ticket = nil
|
ticket = nil
|
||||||
article = 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
|
ticket = Ticket.create( test[:create][:ticket] )
|
||||||
article = Ticket::Article.create( test[:create][:article] )
|
test[:check][0][:o_id] = ticket.id
|
||||||
test[:check][1][:o_id] = article.id
|
test[:check][0][:created_at] = ticket.created_at
|
||||||
test[:check][1][:created_at] = article.created_at
|
test[:check][0][:created_by_id] = current_user.id
|
||||||
test[:check][1][:created_by_id] = current_user.id
|
sleep 2
|
||||||
|
|
||||||
assert_equal( ticket.class.to_s, 'Ticket' )
|
test[:create][:article][:ticket_id] = ticket.id
|
||||||
assert_equal( article.class.to_s, 'Ticket::Article' )
|
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
|
assert_equal( ticket.class.to_s, 'Ticket' )
|
||||||
if test[:update][:ticket]
|
assert_equal( article.class.to_s, 'Ticket::Article' )
|
||||||
ticket.update_attributes( test[:update][:ticket] )
|
|
||||||
|
|
||||||
# check updated user
|
# update ticket
|
||||||
test[:check][2][:o_id] = current_user.id
|
if test[:update][:ticket]
|
||||||
test[:check][2][:created_at] = ticket.created_at
|
ticket.update_attributes( test[:update][:ticket] )
|
||||||
test[:check][2][:created_by_id] = current_user.id
|
|
||||||
end
|
# check updated user
|
||||||
if test[:update][:article]
|
test[:check][2][:o_id] = current_user.id
|
||||||
article.update_attributes( test[:update][:article] )
|
test[:check][2][:created_at] = ticket.created_at
|
||||||
end
|
test[:check][2][:created_by_id] = current_user.id
|
||||||
|
end
|
||||||
|
if test[:update][:article]
|
||||||
|
article.update_attributes( test[:update][:article] )
|
||||||
end
|
end
|
||||||
|
|
||||||
# remember ticket
|
# remember ticket
|
||||||
|
@ -167,7 +165,7 @@ class ActivityStreamTest < ActiveSupport::TestCase
|
||||||
test[:check][0][:o_id] = organization.id
|
test[:check][0][:o_id] = organization.id
|
||||||
test[:check][0][:created_at] = organization.created_at
|
test[:check][0][:created_at] = organization.created_at
|
||||||
test[:check][0][:created_by_id] = current_user.id
|
test[:check][0][:created_by_id] = current_user.id
|
||||||
sleep 11
|
sleep 2
|
||||||
|
|
||||||
assert_equal( organization.class.to_s, 'Organization' )
|
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][:o_id] = organization.id
|
||||||
test[:check][1][:updated_at] = organization.updated_at
|
test[:check][1][:updated_at] = organization.updated_at
|
||||||
test[:check][1][:created_by_id] = current_user.id
|
test[:check][1][:created_by_id] = current_user.id
|
||||||
sleep 2
|
sleep 13
|
||||||
end
|
end
|
||||||
|
|
||||||
if test[:update2][:organization]
|
if test[:update2][:organization]
|
||||||
|
@ -266,8 +264,6 @@ class ActivityStreamTest < ActiveSupport::TestCase
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test 'user with update check true' do
|
test 'user with update check true' do
|
||||||
tests = [
|
tests = [
|
||||||
|
|
||||||
|
@ -347,25 +343,24 @@ class ActivityStreamTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity_stream_check( activity_stream_list, checks )
|
def activity_stream_check( activity_stream_list, checks )
|
||||||
puts 'AS ' + activity_stream_list.inspect
|
#puts 'AS ' + activity_stream_list.inspect
|
||||||
checks.each { |check_item|
|
checks.each { |check_item|
|
||||||
puts '+++++++++++'
|
#puts '+++++++++++'
|
||||||
puts check_item.inspect
|
#puts check_item.inspect
|
||||||
match = false
|
match = false
|
||||||
activity_stream_list.each { |item|
|
activity_stream_list.each { |item|
|
||||||
next if match
|
next if match
|
||||||
puts '--------'
|
#puts '--------'
|
||||||
puts item.inspect
|
#puts item.inspect
|
||||||
# puts item.object
|
|
||||||
next if item['object'] != check_item[:object]
|
next if item['object'] != check_item[:object]
|
||||||
next if item['type'] != check_item[:type]
|
next if item['type'] != check_item[:type]
|
||||||
next if item['o_id'] != check_item[:o_id]
|
next if item['o_id'] != check_item[:o_id]
|
||||||
match = true
|
match = true
|
||||||
}
|
}
|
||||||
if check_item[:result]
|
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
|
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
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue