email_address_test.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. require 'test_helper'
  2. class EmailAddressTest < ActiveSupport::TestCase
  3. test 'basic tests' do
  4. email_address1 = EmailAddress.create_or_update(
  5. realname: 'address #1',
  6. email: 'address1@example.com',
  7. active: true,
  8. updated_by_id: 1,
  9. created_by_id: 1,
  10. )
  11. assert_not(email_address1.active)
  12. email_address1.channel_id = Channel.first.id
  13. email_address1.save
  14. assert(email_address1.active)
  15. end
  16. test 'group tests' do
  17. email_address1 = EmailAddress.create_or_update(
  18. realname: 'address #1',
  19. email: 'address1@example.com',
  20. active: true,
  21. updated_by_id: 1,
  22. created_by_id: 1,
  23. )
  24. group1 = Group.create_or_update(
  25. name: 'group email address 1',
  26. email_address_id: email_address1.id,
  27. active: true,
  28. updated_by_id: 1,
  29. created_by_id: 1,
  30. )
  31. assert(group1.email_address_id)
  32. email_address1.destroy
  33. group1 = Group.find(group1.id)
  34. assert_nil(group1.email_address_id, 'References to groups are deleted')
  35. end
  36. test 'channel tests' do
  37. channel1 = Channel.create(
  38. area: 'Email::Account',
  39. options: {},
  40. active: true,
  41. updated_by_id: 1,
  42. created_by_id: 1,
  43. )
  44. email_address1 = EmailAddress.create_or_update(
  45. realname: 'address #1',
  46. email: 'address1@example.com',
  47. active: true,
  48. channel_id: channel1.id,
  49. updated_by_id: 1,
  50. created_by_id: 1,
  51. )
  52. email_address2 = EmailAddress.create_or_update(
  53. realname: 'address #2',
  54. email: 'address2@example.com',
  55. active: true,
  56. channel_id: channel1.id,
  57. updated_by_id: 1,
  58. created_by_id: 1,
  59. )
  60. channel1.destroy
  61. email_address1 = EmailAddress.find(email_address1.id)
  62. assert_not(email_address1.channel_id)
  63. email_address2 = EmailAddress.find(email_address2.id)
  64. assert_not(email_address2.channel_id)
  65. channel1 = Channel.create(
  66. area: 'Email::Account',
  67. options: {},
  68. active: true,
  69. updated_by_id: 1,
  70. created_by_id: 1,
  71. )
  72. email_address1 = EmailAddress.find(email_address1.id)
  73. assert_not(email_address1.channel_id)
  74. email_address2 = EmailAddress.find(email_address2.id)
  75. assert_not(email_address2.channel_id)
  76. end
  77. end