3 class UserMailerTest < ActionMailer::TestCase
 
   4   def test_html_layout_is_used
 
   5     email = UserMailer.message_notification(create(:message))
 
   7     assert_match(/<html lang=/, email.html_part.body.to_s)
 
  10   def test_gpx_description_tags
 
  11     trace = create(:trace) do |t|
 
  12       create(:tracetag, :trace => t, :tag => "one")
 
  13       create(:tracetag, :trace => t, :tag => "two&three")
 
  14       create(:tracetag, :trace => t, :tag => "four<five")
 
  16     email = UserMailer.gpx_success(trace, 100)
 
  18     assert_match("one, two&three, four<five", email.html_part.body.to_s)
 
  19     assert_match("one, two&three, four<five", email.text_part.body.to_s)
 
  22   def test_gpx_success_all_traces_link
 
  23     trace = create(:trace)
 
  24     email = UserMailer.gpx_success(trace, 100)
 
  25     url = Rails.application.routes.url_helpers.url_for(:controller => "traces", :action => "mine", :host => Settings.server_url, :protocol => Settings.server_protocol)
 
  27     assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
 
  29     assert_includes email.text_part.body, url
 
  32   def test_gpx_success_trace_link
 
  33     trace = create(:trace)
 
  34     email = UserMailer.gpx_success(trace, 100)
 
  35     url = Rails.application.routes.url_helpers.show_trace_url(trace.user, trace, :host => Settings.server_url, :protocol => Settings.server_protocol)
 
  37     assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
 
  38                   "a[href='#{url}']", :text => trace.name
 
  39     assert_includes email.text_part.body, url
 
  42   def test_gpx_failure_no_trace_link
 
  43     trace = create(:trace)
 
  44     email = UserMailer.gpx_failure(trace, "some error")
 
  45     url = Rails.application.routes.url_helpers.show_trace_url(trace.user, trace, :host => Settings.server_url, :protocol => Settings.server_protocol)
 
  47     assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
 
  48                   "a[href='#{url}']", :count => 0
 
  49     assert_not_includes email.text_part.body, url
 
  52   def test_html_encoding
 
  53     user = create(:user, :display_name => "Jack & Jill <br>")
 
  54     message = create(:message, :sender => user)
 
  55     email = UserMailer.message_notification(message)
 
  57     assert_match("Jack & Jill <br>", email.text_part.body.to_s)
 
  58     assert_match("Jack & Jill <br>", email.html_part.body.to_s)
 
  61   def test_diary_comment_notification
 
  62     create(:language, :code => "en")
 
  64     other_user = create(:user)
 
  65     diary_entry = create(:diary_entry, :user => user)
 
  66     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
 
  67     email = UserMailer.diary_comment_notification(diary_comment, other_user)
 
  68     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
 
  70     url = Rails.application.routes.url_helpers.diary_entry_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
 
  71     unsubscribe_url = Rails.application.routes.url_helpers.diary_entry_unsubscribe_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
 
  72     assert_select body, "a[href^='#{url}']"
 
  73     assert_select body, "a[href='#{unsubscribe_url}']", :count => 1
 
  76   def test_changeset_comment_notification
 
  77     create(:language, :code => "en")
 
  79     other_user = create(:user)
 
  80     changeset = create(:changeset, :user => user)
 
  81     changeset_comment = create(:changeset_comment, :changeset => changeset)
 
  82     email = UserMailer.changeset_comment_notification(changeset_comment, other_user)
 
  83     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
 
  85     url = Rails.application.routes.url_helpers.changeset_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
 
  86     unsubscribe_url = Rails.application.routes.url_helpers.changeset_subscription_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
 
  87     assert_select body, "a[href^='#{url}']"
 
  88     assert_select body, "a[href='#{unsubscribe_url}']", :count => 1