Няма описание http://j1x-huginn.herokuapp.com

email_concern.rb 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. require 'rails_helper'
  2. shared_examples_for EmailConcern do
  3. let(:valid_options) {
  4. {
  5. :subject => "hello!",
  6. :expected_receive_period_in_days => "2"
  7. }
  8. }
  9. let(:agent) do
  10. _agent = described_class.new(:name => "some email agent", :options => valid_options)
  11. _agent.user = users(:jane)
  12. _agent
  13. end
  14. describe "validations" do
  15. it "should be valid" do
  16. expect(agent).to be_valid
  17. end
  18. it "should validate the presence of 'subject'" do
  19. agent.options['subject'] = ''
  20. expect(agent).not_to be_valid
  21. agent.options['subject'] = nil
  22. expect(agent).not_to be_valid
  23. end
  24. it "should validate the presence of 'expected_receive_period_in_days'" do
  25. agent.options['expected_receive_period_in_days'] = ''
  26. expect(agent).not_to be_valid
  27. agent.options['expected_receive_period_in_days'] = nil
  28. expect(agent).not_to be_valid
  29. end
  30. it "should validate that recipients, when provided, is one or more valid email addresses or Liquid commands" do
  31. agent.options['recipients'] = ''
  32. expect(agent).to be_valid
  33. agent.options['recipients'] = nil
  34. expect(agent).to be_valid
  35. agent.options['recipients'] = 'bob@example.com'
  36. expect(agent).to be_valid
  37. agent.options['recipients'] = ['bob@example.com']
  38. expect(agent).to be_valid
  39. agent.options['recipients'] = '{{ email }}'
  40. expect(agent).to be_valid
  41. agent.options['recipients'] = ['bob@example.com', 'jane@example.com']
  42. expect(agent).to be_valid
  43. agent.options['recipients'] = ['bob@example.com', 'example.com']
  44. expect(agent).not_to be_valid
  45. agent.options['recipients'] = ['hi!']
  46. expect(agent).not_to be_valid
  47. agent.options['recipients'] = { :foo => "bar" }
  48. expect(agent).not_to be_valid
  49. agent.options['recipients'] = "wut"
  50. expect(agent).not_to be_valid
  51. end
  52. end
  53. describe "#recipients" do
  54. it "defaults to the user's email address" do
  55. expect(agent.recipients).to eq([users(:jane).email])
  56. end
  57. it "wraps a string with an array" do
  58. agent.options['recipients'] = 'bob@bob.com'
  59. expect(agent.recipients).to eq(['bob@bob.com'])
  60. end
  61. it "handles an array" do
  62. agent.options['recipients'] = ['bob@bob.com', 'jane@jane.com']
  63. expect(agent.recipients).to eq(['bob@bob.com', 'jane@jane.com'])
  64. end
  65. it "interpolates" do
  66. agent.options['recipients'] = "{{ username }}@{{ domain }}"
  67. expect(agent.recipients('username' => 'bob', 'domain' => 'example.com')).to eq(["bob@example.com"])
  68. end
  69. end
  70. end