diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 2d1a940fb..d10ca9ee7 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -153,42 +153,13 @@ class TicketsController < ApplicationController users = {} users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id ) users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id ) - - # get only needed data to send to browser - history_list = [] history.each do |item| - users[ item[:created_by_id] ] = User.user_data_full( item[:created_by_id] ) - item_tmp = item.attributes + users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] ) if item['history_object'] == 'Ticket::Article' - item_temp['type'] = 'Article ' + item['type'].to_s + item['type'] = 'Article ' + item['type'].to_s else - item_tmp['type'] = 'Ticket ' + item['type'].to_s + item['type'] = 'Ticket ' + item['type'].to_s end - item_tmp['history_type'] = item.history_type.name - item_tmp['history_object'] = item.history_object.name - if item.history_attribute - item_tmp['history_attribute'] = item.history_attribute.name - end - item_tmp.delete( 'history_attribute_id' ) - item_tmp.delete( 'history_object_id' ) - item_tmp.delete( 'history_type_id' ) - item_tmp.delete( 'o_id' ) - item_tmp.delete( 'updated_at' ) - if item_tmp['id_to'] == nil && item_tmp['id_from'] == nil - item_tmp.delete( 'id_to' ) - item_tmp.delete( 'id_from' ) - end - if item_tmp['value_to'] == nil && item_tmp['value_from'] == nil - item_tmp.delete( 'value_to' ) - item_tmp.delete( 'value_from' ) - end - if item_tmp['related_history_object_id'] == nil - item_tmp.delete( 'related_history_object_id' ) - end - if item_tmp['related_o_id'] == nil - item_tmp.delete( 'related_o_id' ) - end - history_list.push item_tmp end # fetch meta relations @@ -200,7 +171,7 @@ class TicketsController < ApplicationController render :json => { :ticket => ticket, :users => users, - :history => history_list, + :history => history, :history_objects => history_objects, :history_types => history_types, :history_attributes => history_attributes diff --git a/app/models/history.rb b/app/models/history.rb index 9463da672..ce6381ee9 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -90,7 +90,36 @@ class History < ApplicationModel order('created_at ASC, id ASC') end - return history + list = [] + history.each { |item| + item_tmp = item.attributes + item_tmp['history_type'] = item.history_type.name + item_tmp['history_object'] = item.history_object.name + if item.history_attribute + item_tmp['history_attribute'] = item.history_attribute.name + end + item_tmp.delete( 'history_attribute_id' ) + item_tmp.delete( 'history_object_id' ) + item_tmp.delete( 'history_type_id' ) + item_tmp.delete( 'o_id' ) + item_tmp.delete( 'updated_at' ) + if item_tmp['id_to'] == nil && item_tmp['id_from'] == nil + item_tmp.delete( 'id_to' ) + item_tmp.delete( 'id_from' ) + end + if item_tmp['value_to'] == nil && item_tmp['value_from'] == nil + item_tmp.delete( 'value_to' ) + item_tmp.delete( 'value_from' ) + end + if item_tmp['related_history_object_id'] == nil + item_tmp.delete( 'related_history_object_id' ) + end + if item_tmp['related_o_id'] == nil + item_tmp.delete( 'related_o_id' ) + end + list.push item_tmp + } + return list end def self.activity_stream( user, limit = 10 ) diff --git a/test/unit/history_test.rb b/test/unit/history_test.rb index e3298afe9..35f2ce47a 100644 --- a/test/unit/history_test.rb +++ b/test/unit/history_test.rb @@ -163,34 +163,39 @@ class HistoryTest < ActiveSupport::TestCase # get history history_list = History.list( 'Ticket', ticket.id, 'Ticket::Article' ) - test[:history_check].each { |check| + puts history_list.inspect + test[:history_check].each { |check_item| +# puts '+++++++++++' +# puts check_item.inspect match = false - history_list.each { |history| + history_list.each { |history_item| next if match - next if history.history_object.name != check[:history_object] - next if history.history_type.name != check[:history_type] - next if check[:history_attribute] && history.history_attribute.name != check[:history_attribute] +# puts '--------' +# puts history_item.inspect + next if history_item['history_object'] != check_item[:history_object] + next if history_item['history_type'] != check_item[:history_type] + next if check_item[:history_attribute] != history_item['history_attribute'] match = true - if history.history_type.name == check[:history_type] - assert( true, "History type #{history.history_type.name} found!") + if history_item['history_type'] == check_item[:history_type] + assert( true, "History type #{history_item['history_type']} found!") end - if check[:history_attribute] - assert_equal( check[:history_attribute], history.history_attribute.name, "check history attribute #{check[:history_attribute]}") + if check_item[:history_attribute] + assert_equal( check_item[:history_attribute], history_item['history_attribute'], "check history attribute #{check_item[:history_attribute]}") end - if check[:value_from] - assert_equal( check[:value_from], history.value_from, "check history :value_from #{history.value_from} ok") + if check_item[:value_from] + assert_equal( check_item[:value_from], history_item['value_from'], "check history :value_from #{history_item['value_from']} ok") end - if check[:value_to] - assert_equal( check[:value_to], history.value_to, "check history :value_to #{history.value_to} ok") + if check_item[:value_to] + assert_equal( check_item[:value_to], history_item['value_to'], "check history :value_to #{history_item['value_to']} ok") end - if check[:id_from] - assert_equal( check[:id_from], history.id_from, "check history :id_from #{history.id_from} ok") + if check_item[:id_from] + assert_equal( check_item[:id_from], history_item['id_from'], "check history :id_from #{history_item['id_from']} ok") end - if check[:id_to] - assert_equal( check[:id_to], history.id_to, "check history :id_to #{history.id_to} ok") + if check_item[:id_to] + assert_equal( check_item[:id_to], history_item['id_to'], "check history :id_to #{history_item['id_to']} ok") end } - assert( match, "history check not matched! #{check.inspect}") + assert( match, "history check not matched! #{check_item.inspect}") } } @@ -199,7 +204,7 @@ class HistoryTest < ActiveSupport::TestCase ticket_id = ticket.id ticket.destroy found = Ticket.where( :id => ticket_id ).first - assert( !found, 'Ticket destroyed') + assert( !found, "Ticket destroyed") } end end