]> git.openstreetmap.org Git - rails.git/blob - test/mailers/user_mailer_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / mailers / user_mailer_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class UserMailerTest < ActionMailer::TestCase
6   def test_html_layout_is_used
7     email = UserMailer.message_notification(create(:message))
8
9     assert_match(/<html lang=/, email.html_part.body.to_s)
10   end
11
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")
17     end
18     email = UserMailer.gpx_success(trace, 100)
19
20     assert_match("one, two&amp;three, four&lt;five", email.html_part.body.to_s)
21     assert_match("one, two&three, four<five", email.text_part.body.to_s)
22   end
23
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)
28
29     assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
30                   "a[href='#{url}']"
31     assert_includes email.text_part.body, url
32   end
33
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)
38
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
42   end
43
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)
48
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
52   end
53
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)
58
59     assert_match("Jack & Jill <br>", email.text_part.body.to_s)
60     assert_match("Jack &amp; Jill &lt;br&gt;", email.html_part.body.to_s)
61   end
62
63   def test_diary_comment_notification
64     create(:language, :code => "en")
65     user = create(:user)
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)
71
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
76   end
77
78   def test_changeset_comment_notification
79     create(:language, :code => "en")
80     user = create(:user)
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)
86
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
91   end
92 end