]> git.openstreetmap.org Git - rails.git/blob - test/mailers/previews/user_mailer_preview.rb
Add previews for remaining notifications
[rails.git] / test / mailers / previews / user_mailer_preview.rb
1 # frozen_string_literal: true
2
3 require "factory_bot_rails"
4
5 class UserMailerPreview < ActionMailer::Preview
6   include FactoryBot::Syntax::Methods
7
8   # Wraps the preview in a transaction, so that no changes
9   # are persisted to the development db
10   def self.call(...)
11     preview = nil
12     ActiveRecord::Base.transaction do
13       preview = super(...)
14       raise ActiveRecord::Rollback
15     end
16     preview
17   end
18
19   def signup_confirm
20     user = create(:user, :languages => [I18n.locale])
21     token = "token-123456"
22     UserMailer.signup_confirm(user, token)
23   end
24
25   def email_confirm
26     user = create(:user, :languages => [I18n.locale], :new_email => "newemail@example.com")
27     token = "token-123456"
28     UserMailer.email_confirm(user, token)
29   end
30
31   def lost_password
32     user = create(:user, :languages => [I18n.locale])
33     token = "token-123456"
34     UserMailer.lost_password(user, token)
35   end
36
37   def gpx_success
38     user = create(:user, :languages => [I18n.locale])
39     trace = create(:trace, :user => user)
40     UserMailer.gpx_success(trace, trace.size + 2)
41   end
42
43   def gpx_failure
44     user = create(:user, :languages => [I18n.locale])
45     trace = create(:trace, :user => user)
46     error = begin
47       LibXML::XML::Parser.string("<gpx>").parse
48     rescue LibXML::XML::Error => e
49       e.message
50     end
51     UserMailer.gpx_failure(trace, error)
52   end
53
54   def message_notification
55     recipient = create(:user, :languages => [I18n.locale])
56     message = create(:message, :recipient => recipient)
57     UserMailer.message_notification(message)
58   end
59
60   def diary_comment_notification
61     recipient = create(:user, :languages => [I18n.locale])
62     diary_entry = create(:diary_entry)
63     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
64     UserMailer.diary_comment_notification(diary_comment, recipient)
65   end
66
67   def follow_notification
68     following = create(:user, :languages => [I18n.locale])
69     follow = create(:follow, :following => following)
70     UserMailer.follow_notification(follow)
71   end
72
73   def note_comment_notification
74     recipient = create(:user, :languages => [I18n.locale])
75     commenter = create(:user)
76     comment = create(:note_comment, :author => commenter)
77     UserMailer.note_comment_notification(comment, recipient)
78   end
79
80   def changeset_comment_notification
81     recipient = create(:user, :languages => [I18n.locale])
82     comment = create(:changeset_comment)
83     UserMailer.changeset_comment_notification(comment, recipient)
84   end
85 end