Fixed activity log bug, added unit tests.

This commit is contained in:
Martin Edenhofer 2014-06-27 00:42:27 +02:00
parent 3d2619672a
commit 67c77ae88d
2 changed files with 56 additions and 27 deletions

View file

@ -42,14 +42,14 @@ add a new activity entry for an object
role_id = role.id
end
# check if entry is needed
# check newest entry - is needed
result = ActivityStream.where(
:o_id => data[:o_id],
# :activity_stream_type_id => type.id,
:role_id => role_id,
:activity_stream_object_id => object.id,
:created_by_id => data[:created_by_id]
).order('created_at DESC, id ASC').last
).order('created_at DESC, id DESC').first
# resturn if old entry is really fresh
return result if result && result.created_at.to_i >= ( data[:created_at].to_i - 12 )

View file

@ -51,17 +51,28 @@ class ActivityStreamTest < ActiveSupport::TestCase
:priority_id => Ticket::Priority.lookup( :name => '1 low' ).id,
},
},
:update2 => {
:ticket => {
:title => 'Unit Test 2 (äöüß) - update!',
:priority_id => Ticket::Priority.lookup( :name => '2 normal' ).id,
},
},
:check => [
{
:result => true,
:object => 'Ticket',
:type => 'created',
:type => 'updated',
},
{
:result => true,
:object => 'Ticket::Article',
:type => 'created',
},
{
:result => true,
:object => 'Ticket',
:type => 'created',
},
{
:result => false,
:object => 'User',
@ -80,8 +91,9 @@ class ActivityStreamTest < ActiveSupport::TestCase
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
test[:check][2][:o_id] = ticket.id
test[:check][2][:created_at] = ticket.created_at
test[:check][2][:created_by_id] = current_user.id
sleep 2
test[:create][:article][:ticket_id] = ticket.id
@ -98,14 +110,26 @@ class ActivityStreamTest < ActiveSupport::TestCase
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
test[:check][3][:o_id] = current_user.id
test[:check][3][:created_at] = ticket.created_at
test[:check][3][:created_by_id] = current_user.id
end
if test[:update2][:ticket]
ticket = Ticket.find( ticket.id )
ticket.update_attributes( test[:update2][:ticket] )
end
if test[:update][:article]
article.update_attributes( test[:update][:article] )
end
sleep 15
if test[:update][:ticket]
ticket.update_attributes( test[:update][:ticket] )
end
if test[:update2][:ticket]
ticket.update_attributes( test[:update2][:ticket] )
end
# remember ticket
tickets.push ticket
@ -148,12 +172,12 @@ class ActivityStreamTest < ActiveSupport::TestCase
{
:result => true,
:object => 'Organization',
:type => 'created',
:type => 'updated',
},
{
:result => true,
:object => 'Organization',
:type => 'updated',
:type => 'created',
},
]
},
@ -252,7 +276,7 @@ class ActivityStreamTest < ActiveSupport::TestCase
users.push user
# check activity_stream
activity_stream_check( admin_user.activity_stream(2), test[:check] )
activity_stream_check( admin_user.activity_stream(3), test[:check] )
}
# delete tickets
@ -293,12 +317,12 @@ class ActivityStreamTest < ActiveSupport::TestCase
{
:result => true,
:object => 'User',
:type => 'created',
:type => 'updated',
},
{
:result => true,
:object => 'User',
:type => 'updated',
:type => 'created',
},
]
},
@ -344,26 +368,31 @@ class ActivityStreamTest < ActiveSupport::TestCase
end
def activity_stream_check( activity_stream_list, checks )
#activity_stream_list = activity_stream_list.reverse
#puts 'AS ' + activity_stream_list.inspect
check_count = 0
checks.each { |check_item|
check_count += 1
#puts '+++++++++++'
#puts check_item.inspect
match = false
check_list = 0
activity_stream_list.each { |item|
next if match
check_list += 1
next if check_list != check_count
# next if match
#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
}
#puts check_item.inspect
if check_item[:result]
assert( match, "activity stream check not matched! #{ check_item.inspect } not in #{ activity_stream_list.inspect }")
assert_equal( check_item[:object], item['object'] )
assert_equal( check_item[:type], item['type'] )
assert_equal( check_item[:o_id], item['o_id'] )
else
assert( !match, "activity stream check matched but should not! #{ check_item.inspect } not in #{ activity_stream_list.inspect }")
assert_not_equal( check_item[:object], item['object'] )
end
}
}
end
end