Browse Source

Improved notification tests.

Martin Edenhofer 10 years ago
parent
commit
e5a9dc8b78

+ 1 - 1
app/models/object_manager.rb

@@ -177,7 +177,7 @@ returns:
         }
       end
       if item.data_option
-        data = data.merge( item.data_option )
+        data = data.merge( item.data_option.symbolize_keys )
       end
       attributes.push data
     }

+ 13 - 7
app/models/observer/ticket/notification/background_job.rb

@@ -136,10 +136,16 @@ class Observer::Ticket::Notification::BackgroundJob
 
     # only show allowed attributes
     attribute_list = ObjectManager::Attribute.by_object_as_hash('Ticket', user)
+    #puts "AL #{attribute_list.inspect}"
     user_related_changes = {}
-    @changes.each {|key,value|
-      #user_related_changes[key] = value
-      if attribute_list[key.to_s]
+    @changes.each {|key, value|
+
+      # if no config exists, use all attributes
+      if !attribute_list || attribute_list.empty?
+        user_related_changes[key] = value
+
+      # if config exists, just use existing attributes for user
+      elsif attribute_list[key.to_s]
         user_related_changes[key] = value
       end
     }
@@ -212,7 +218,7 @@ class Observer::Ticket::Notification::BackgroundJob
       subject = 'Neues Ticket (#{ticket.title})'
       body    = 'Hallo #{recipient.firstname},
 
-es wurde ein neues Ticket (#{ticket.title}) von #{ticket.updated_by.fullname} erstellt.
+es wurde ein neues Ticket (#{ticket.title}) von "#{ticket.updated_by.fullname}" erstellt.
 
 Gruppe: #{ticket.group.name}
 Besitzer: #{ticket.owner.fullname}
@@ -226,7 +232,7 @@ Status: i18n(#{ticket.state.name})
       subject = 'New Ticket (#{ticket.title})'
       body    = 'Hi #{recipient.firstname},
 
-a new Ticket (#{ticket.title}) has been created by #{ticket.updated_by.fullname}.
+a new Ticket (#{ticket.title}) has been created by "#{ticket.updated_by.fullname}".
 
 Group: #{ticket.group.name}
 Owner: #{ticket.owner.fullname}
@@ -263,7 +269,7 @@ State: i18n(#{ticket.state.name})
       subject = 'Ticket aktualisiert (#{ticket.title})'
       body    = 'Hallo #{recipient.firstname},
 
-Ticket (#{ticket.title}) wurde von #{ticket.updated_by.fullname} aktualisiert.
+Ticket (#{ticket.title}) wurde von "#{ticket.updated_by.fullname}" aktualisiert.
 
 Änderungen:
 ' + changes + '
@@ -275,7 +281,7 @@ Ticket (#{ticket.title}) wurde von #{ticket.updated_by.fullname} aktualisiert.
       subject = 'Updated Ticket (#{ticket.title})'
       body    = 'Hi #{recipient.firstname},
 
-Ticket (#{ticket.title}) has been updated by #{ticket.updated_by.fullname}.
+Ticket (#{ticket.title}) has been updated by "#{ticket.updated_by.fullname}".
 
 Changes:
 ' + changes + '

+ 42 - 6
test/unit/ticket_notification_test.rb

@@ -365,22 +365,58 @@ class TicketNotificationTest < ActiveSupport::TestCase
         :priority_id => [1, 2],
       },
     )
+
+    # check changed attributes
     human_changes = bg.human_changes(agent1,ticket1)
-    assert_equal( '1 low', human_changes['priority'][0] )
-    assert_equal( '2 normal', human_changes['priority'][1] )
+    assert( human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute' )
+    assert_equal( '1 low', human_changes['Priority'][0] )
+    assert_equal( '2 normal', human_changes['Priority'][1] )
     assert_not( human_changes['priority_id'] )
 
-    # en notification
+    # en template
     template = bg.template_update(agent1, ticket1, article, human_changes)
     assert( template[:subject] )
     assert( template[:body] )
-    puts template.inspect
+    assert_match( /Priority/, template[:body] )
+    assert_match( /1 low/, template[:body] )
+    assert_match( /3 normal/, template[:body] )
 
-    # de notification
+    # en notification
+    body = NotificationFactory.build(
+      :locale  => agent1.preferences[:locale],
+      :string  => template[:body],
+      :objects => {
+        :ticket    => ticket1,
+        :article   => article,
+        :recipient => agent1,
+      }
+    )
+    assert_match( /Priority/, body )
+    assert_match( /1 low/, body )
+    assert_match( /3 normal/, body )
+
+    # de template
     template = bg.template_update(agent2, ticket1, article, human_changes)
     assert( template[:subject] )
     assert( template[:body] )
-    puts template.inspect
+    assert_match( /Priority/, template[:body] )
+    assert_match( /1 low/, template[:body] )
+    assert_match( /3 normal/, template[:body] )
+
+    # de notification
+    body = NotificationFactory.build(
+      :locale  => agent2.preferences[:locale],
+      :string  => template[:body],
+      :objects => {
+        :ticket    => ticket1,
+        :article   => article,
+        :recipient => agent2,
+      }
+    )
+
+    assert_match( /Priorität/, body )
+    assert_match( /1 gering/, body )
+    assert_match( /3 normal/, body )
 
   end