]> git.openstreetmap.org Git - rails.git/blob - test/mailers/user_mailer_test.rb
Simplify links on trace pages
[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")
14       create(:tracetag, :trace => t, :tag => "three")
15     end
16     email = UserMailer.gpx_success(trace, 100)
17
18     assert_match("<em>one</em>, <em>two</em>, <em>three</em>", email.html_part.body.to_s)
19   end
20
21   def test_gpx_success_all_traces_link
22     trace = create(:trace)
23     email = UserMailer.gpx_success(trace, 100)
24     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
25
26     url = Rails.application.routes.url_helpers.url_for(:controller => "traces", :action => "mine", :host => Settings.server_url, :protocol => Settings.server_protocol)
27     assert_select body, "a[href='#{url}']"
28   end
29
30   def test_gpx_success_trace_link
31     trace = create(:trace)
32     email = UserMailer.gpx_success(trace, 100)
33     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
34
35     url = Rails.application.routes.url_helpers.show_trace_url(trace.user, trace, :host => Settings.server_url, :protocol => Settings.server_protocol)
36     assert_select body, "a[href='#{url}']", :text => trace.name
37   end
38
39   def test_gpx_failure_no_trace_link
40     trace = create(:trace)
41     email = UserMailer.gpx_failure(trace, "some error")
42     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
43
44     url = Rails.application.routes.url_helpers.show_trace_url(trace.user, trace, :host => Settings.server_url, :protocol => Settings.server_protocol)
45     assert_select body, "a[href='#{url}']", :count => 0
46   end
47
48   def test_html_encoding
49     user = create(:user, :display_name => "Jack & Jill <br>")
50     message = create(:message, :sender => user)
51     email = UserMailer.message_notification(message)
52
53     assert_match("Jack & Jill <br>", email.text_part.body.to_s)
54     assert_match("Jack &amp; Jill &lt;br&gt;", email.html_part.body.to_s)
55   end
56
57   def test_diary_comment_notification
58     create(:language, :code => "en")
59     user = create(:user)
60     other_user = create(:user)
61     diary_entry = create(:diary_entry, :user => user)
62     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
63     email = UserMailer.diary_comment_notification(diary_comment, other_user)
64     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
65
66     url = Rails.application.routes.url_helpers.diary_entry_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
67     unsubscribe_url = Rails.application.routes.url_helpers.diary_entry_unsubscribe_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
68     assert_select body, "a[href^='#{url}']"
69     assert_select body, "a[href='#{unsubscribe_url}']", :count => 1
70   end
71
72   def test_changeset_comment_notification
73     create(:language, :code => "en")
74     user = create(:user)
75     other_user = create(:user)
76     changeset = create(:changeset, :user => user)
77     changeset_comment = create(:changeset_comment, :changeset => changeset)
78     email = UserMailer.changeset_comment_notification(changeset_comment, other_user)
79     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
80
81     url = Rails.application.routes.url_helpers.changeset_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
82     unsubscribe_url = Rails.application.routes.url_helpers.unsubscribe_changeset_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
83     assert_select body, "a[href^='#{url}']"
84     assert_select body, "a[href='#{unsubscribe_url}']", :count => 1
85   end
86 end