1 # frozen_string_literal: true
5 class UserMailerTest < ActionMailer::TestCase
6 def test_html_layout_is_used
7 email = UserMailer.message_notification(create(:message))
9 assert_match(/<html lang=/, email.html_part.body.to_s)
12 def test_gpx_description_tags
13 trace = create(:trace) do |t|
14 create(:tracetag, :trace => t, :tag => "one")
15 create(:tracetag, :trace => t, :tag => "two&three")
16 create(:tracetag, :trace => t, :tag => "four<five")
18 email = UserMailer.gpx_success(trace, 100)
20 assert_match("one, two&three, four<five", email.html_part.body.to_s)
21 assert_match("one, two&three, four<five", email.text_part.body.to_s)
24 def test_gpx_success_all_traces_link
25 trace = create(:trace)
26 email = UserMailer.gpx_success(trace, 100)
27 url = Rails.application.routes.url_helpers.url_for(:controller => "traces", :action => "mine", :host => Settings.server_url, :protocol => Settings.server_protocol)
29 assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
31 assert_includes email.text_part.body, url
34 def test_gpx_success_trace_link
35 trace = create(:trace)
36 email = UserMailer.gpx_success(trace, 100)
37 url = Rails.application.routes.url_helpers.show_trace_url(trace.user, trace, :host => Settings.server_url, :protocol => Settings.server_protocol)
39 assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
40 "a[href='#{url}']", :text => trace.name
41 assert_includes email.text_part.body, url
44 def test_gpx_failure_no_trace_link
45 trace = create(:trace)
46 email = UserMailer.gpx_failure(trace, "some error")
47 url = Rails.application.routes.url_helpers.show_trace_url(trace.user, trace, :host => Settings.server_url, :protocol => Settings.server_protocol)
49 assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
50 "a[href='#{url}']", :count => 0
51 assert_not_includes email.text_part.body, url
54 def test_html_encoding
55 user = create(:user, :display_name => "Jack & Jill <br>")
56 message = create(:message, :sender => user)
57 email = UserMailer.message_notification(message)
59 assert_match("Jack & Jill <br>", email.text_part.body.to_s)
60 assert_match("Jack & Jill <br>", email.html_part.body.to_s)
63 def test_diary_comment_notification
64 create(:language, :code => "en")
66 other_user = create(:user)
67 diary_entry = create(:diary_entry, :user => user)
68 diary_comment = create(:diary_comment, :diary_entry => diary_entry)
69 email = UserMailer.diary_comment_notification(diary_comment, other_user)
70 body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
72 url = Rails.application.routes.url_helpers.diary_entry_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
73 unsubscribe_url = Rails.application.routes.url_helpers.diary_entry_unsubscribe_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
74 assert_select body, "a[href^='#{url}']"
75 assert_select body, "a[href='#{unsubscribe_url}']", :count => 1
78 def test_changeset_comment_notification
79 create(:language, :code => "en")
81 other_user = create(:user)
82 changeset = create(:changeset, :user => user)
83 changeset_comment = create(:changeset_comment, :changeset => changeset)
84 email = UserMailer.changeset_comment_notification(changeset_comment, other_user)
85 body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
87 url = Rails.application.routes.url_helpers.changeset_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
88 unsubscribe_url = Rails.application.routes.url_helpers.changeset_subscription_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
89 assert_select body, "a[href^='#{url}']"
90 assert_select body, "a[href='#{unsubscribe_url}']", :count => 1