email_address_test.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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