]> git.openstreetmap.org Git - rails.git/blob - test/mailers/user_mailer_test.rb
Move html_safe declaration for user_mailer from layout to helper
[rails.git] / test / mailers / user_mailer_test.rb
1 require "test_helper"
2
3 class UserMailerTest < ActionMailer::TestCase
4   def test_html_layout_is_used
5     email = UserMailer.message_notification(create(:message))
6
7     assert_match(/<html lang=/, email.html_part.body.to_s)
8   end
9
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")
15     end
16     email = UserMailer.gpx_success(trace, 100)
17
18     assert_match("<em>one</em>, <em>two&amp;three</em>, <em>four&lt;five</em>", email.html_part.body.to_s)
19     assert_match("one, two&three, four<five", email.text_part.body.to_s)
20   end
21
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)
26
27     assert_select Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body),
28                   "a[href='#{url}']"
29     assert_includes email.text_part.body, url
30   end
31
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)
36
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
40   end
41
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)
46
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
50   end
51
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)
56
57     assert_match("Jack & Jill <br>", email.text_part.body.to_s)
58     assert_match("Jack &amp; Jill &lt;br&gt;", email.html_part.body.to_s)
59   end
60
61   def test_diary_comment_notification
62     create(:language, :code => "en")
63     user = create(:user)
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)
69
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
74   end
75
76   def test_changeset_comment_notification
77     create(:language, :code => "en")
78     user = create(:user)
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)
84
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.unsubscribe_changeset_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
89   end
90 end