notification_factory_test.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class NotificationFactoryTest < ActiveSupport::TestCase
  4. test 'notifications' do
  5. ticket = Ticket.create(
  6. :title => 'some title äöüß',
  7. :group => Group.lookup( :name => 'Users'),
  8. :customer_id => 2,
  9. :state => Ticket::State.lookup( :name => 'new' ),
  10. :priority => Ticket::Priority.lookup( :name => '2 normal' ),
  11. :updated_by_id => 1,
  12. :created_by_id => 1,
  13. )
  14. tests = [
  15. {
  16. :locale => 'en',
  17. :string => 'Hi #{recipient.firstname},',
  18. :result => 'Hi Nicole,',
  19. },
  20. {
  21. :locale => 'de',
  22. :string => 'Hi #{recipient.firstname},',
  23. :result => 'Hi Nicole,',
  24. },
  25. {
  26. :locale => 'de',
  27. :string => 'Hi #{recipient.firstname}, Group: #{ticket.group.name}',
  28. :result => 'Hi Nicole, Group: Users',
  29. },
  30. {
  31. :locale => 'de',
  32. :string => '#{config.http_type} some text',
  33. :result => 'http some text',
  34. },
  35. {
  36. :locale => 'de',
  37. :string => 'i18n(New) some text',
  38. :result => 'Neu some text',
  39. },
  40. {
  41. :locale => 'de',
  42. :string => '\'i18n(#{ticket.state.name})\' ticket state',
  43. :result => '\'neu\' ticket state',
  44. },
  45. {
  46. :locale => 'de',
  47. :string => '\#{puts `ls`}',
  48. :result => '\#{puts `ls`}',
  49. },
  50. ]
  51. tests.each { |test|
  52. result = NotificationFactory.build(
  53. :string => test[:string],
  54. :objects => {
  55. :ticket => ticket,
  56. :recipient => User.find(2),
  57. },
  58. :locale => test[:locale]
  59. )
  60. assert_equal( result, test[:result], "verify result" )
  61. }
  62. ticket.destroy
  63. end
  64. end