From c83381938aafe6d5e7da8890150ba285a2533665 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 6 Jul 2018 20:17:54 +0800 Subject: Move spec/mailers/previews to app/mailers/previews --- app/mailers/previews/devise_mailer_preview.rb | 30 ++++ .../previews/email_rejection_mailer_preview.rb | 5 + app/mailers/previews/notify_preview.rb | 170 +++++++++++++++++++++ .../previews/repository_check_mailer_preview.rb | 5 + config/environments/development.rb | 2 +- doc/development/emails.md | 4 +- spec/mailers/previews/devise_mailer_preview.rb | 30 ---- .../previews/email_rejection_mailer_preview.rb | 5 - spec/mailers/previews/notify_preview.rb | 170 --------------------- .../previews/repository_check_mailer_preview.rb | 5 - 10 files changed, 213 insertions(+), 213 deletions(-) create mode 100644 app/mailers/previews/devise_mailer_preview.rb create mode 100644 app/mailers/previews/email_rejection_mailer_preview.rb create mode 100644 app/mailers/previews/notify_preview.rb create mode 100644 app/mailers/previews/repository_check_mailer_preview.rb delete mode 100644 spec/mailers/previews/devise_mailer_preview.rb delete mode 100644 spec/mailers/previews/email_rejection_mailer_preview.rb delete mode 100644 spec/mailers/previews/notify_preview.rb delete mode 100644 spec/mailers/previews/repository_check_mailer_preview.rb diff --git a/app/mailers/previews/devise_mailer_preview.rb b/app/mailers/previews/devise_mailer_preview.rb new file mode 100644 index 00000000000..d6588efc486 --- /dev/null +++ b/app/mailers/previews/devise_mailer_preview.rb @@ -0,0 +1,30 @@ +class DeviseMailerPreview < ActionMailer::Preview + def confirmation_instructions_for_signup + DeviseMailer.confirmation_instructions(unsaved_user, 'faketoken', {}) + end + + def confirmation_instructions_for_new_email + user = User.last + user.unconfirmed_email = 'unconfirmed@example.com' + + DeviseMailer.confirmation_instructions(user, 'faketoken', {}) + end + + def reset_password_instructions + DeviseMailer.reset_password_instructions(unsaved_user, 'faketoken', {}) + end + + def unlock_instructions + DeviseMailer.unlock_instructions(unsaved_user, 'faketoken', {}) + end + + def password_change + DeviseMailer.password_change(unsaved_user, {}) + end + + private + + def unsaved_user + User.new(name: 'Jane Doe', email: 'jdoe@example.com') + end +end diff --git a/app/mailers/previews/email_rejection_mailer_preview.rb b/app/mailers/previews/email_rejection_mailer_preview.rb new file mode 100644 index 00000000000..639e8471232 --- /dev/null +++ b/app/mailers/previews/email_rejection_mailer_preview.rb @@ -0,0 +1,5 @@ +class EmailRejectionMailerPreview < ActionMailer::Preview + def rejection + EmailRejectionMailer.rejection("some rejection reason", "From: someone@example.com\nraw email here").message + end +end diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb new file mode 100644 index 00000000000..e32fd0bd120 --- /dev/null +++ b/app/mailers/previews/notify_preview.rb @@ -0,0 +1,170 @@ +class NotifyPreview < ActionMailer::Preview + def note_merge_request_email_for_individual_note + note_email(:note_merge_request_email) do + note = <<-MD.strip_heredoc + This is an individual note on a merge request :smiley: + + In this notification email, we expect to see: + + - The note contents (that's what you're looking at) + - A link to view this note on Gitlab + - An explanation for why the user is receiving this notification + MD + + create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, note: note) + end + end + + def note_merge_request_email_for_discussion + note_email(:note_merge_request_email) do + note = <<-MD.strip_heredoc + This is a new discussion on a merge request :smiley: + + In this notification email, we expect to see: + + - A line saying who started this discussion + - The note contents (that's what you're looking at) + - A link to view this discussion on Gitlab + - An explanation for why the user is receiving this notification + MD + + create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiscussionNote', note: note) + end + end + + def note_merge_request_email_for_diff_discussion + note_email(:note_merge_request_email) do + note = <<-MD.strip_heredoc + This is a new discussion on a merge request :smiley: + + In this notification email, we expect to see: + + - A line saying who started this discussion and on what file + - The diff + - The note contents (that's what you're looking at) + - A link to view this discussion on Gitlab + - An explanation for why the user is receiving this notification + MD + + position = Gitlab::Diff::Position.new( + old_path: "files/ruby/popen.rb", + new_path: "files/ruby/popen.rb", + old_line: nil, + new_line: 14, + diff_refs: merge_request.diff_refs + ) + + create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiffNote', position: position, note: note) + end + end + + def closed_issue_email + Notify.closed_issue_email(user.id, issue.id, user.id).message + end + + def issue_status_changed_email + Notify.issue_status_changed_email(user.id, issue.id, 'closed', user.id).message + end + + def closed_merge_request_email + Notify.closed_merge_request_email(user.id, issue.id, user.id).message + end + + def merge_request_status_email + Notify.merge_request_status_email(user.id, merge_request.id, 'closed', user.id).message + end + + def merged_merge_request_email + Notify.merged_merge_request_email(user.id, merge_request.id, user.id).message + end + + def member_access_denied_email + Notify.member_access_denied_email('project', project.id, user.id).message + end + + def member_access_granted_email + Notify.member_access_granted_email('project', user.id).message + end + + def member_access_requested_email + Notify.member_access_requested_email('group', user.id, 'some@example.com').message + end + + def member_invite_accepted_email + Notify.member_invite_accepted_email('project', user.id).message + end + + def member_invite_declined_email + Notify.member_invite_declined_email( + 'project', + project.id, + 'invite@example.com', + user.id + ).message + end + + def member_invited_email + Notify.member_invited_email('project', user.id, '1234').message + end + + def pages_domain_enabled_email + cleanup do + pages_domain = PagesDomain.new(domain: 'my.example.com', project: project, verified_at: Time.now, enabled_until: 1.week.from_now) + + Notify.pages_domain_enabled_email(pages_domain, user).message + end + end + + def pipeline_success_email + Notify.pipeline_success_email(pipeline, pipeline.user.try(:email)) + end + + def pipeline_failed_email + Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email)) + end + + private + + def project + @project ||= Project.find_by_full_path('gitlab-org/gitlab-test') + end + + def issue + @merge_request ||= project.issues.first + end + + def merge_request + @merge_request ||= project.merge_requests.first + end + + def pipeline + @pipeline = Ci::Pipeline.last + end + + def user + @user ||= User.last + end + + def create_note(params) + Notes::CreateService.new(project, user, params).execute + end + + def note_email(method) + cleanup do + note = yield + + Notify.public_send(method, user.id, note) + end + end + + def cleanup + email = nil + + ActiveRecord::Base.transaction do + email = yield + raise ActiveRecord::Rollback + end + + email + end +end diff --git a/app/mailers/previews/repository_check_mailer_preview.rb b/app/mailers/previews/repository_check_mailer_preview.rb new file mode 100644 index 00000000000..19d4eab1805 --- /dev/null +++ b/app/mailers/previews/repository_check_mailer_preview.rb @@ -0,0 +1,5 @@ +class RepositoryCheckMailerPreview < ActionMailer::Preview + def notify + RepositoryCheckMailer.notify(3).message + end +end diff --git a/config/environments/development.rb b/config/environments/development.rb index 45a8c1add3e..23790b84e3c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -39,7 +39,7 @@ Rails.application.configure do config.action_mailer.delivery_method = :letter_opener_web # Don't make a mess when bootstrapping a development environment config.action_mailer.perform_deliveries = (ENV['BOOTSTRAP'] != '1') - config.action_mailer.preview_path = 'spec/mailers/previews' + config.action_mailer.preview_path = 'app/mailers/previews' config.eager_load = false diff --git a/doc/development/emails.md b/doc/development/emails.md index 73cac82caf0..35ada35babe 100644 --- a/doc/development/emails.md +++ b/doc/development/emails.md @@ -10,12 +10,12 @@ To view rendered emails "sent" in your development instance, visit Rails provides a way to preview our mailer templates in HTML and plaintext using dummy data. -The previews live in [`spec/mailers/previews`][previews] and can be viewed at +The previews live in [`app/mailers/previews`][previews] and can be viewed at [`/rails/mailers`](http://localhost:3000/rails/mailers). See the [Rails guides] for more info. -[previews]: https://gitlab.com/gitlab-org/gitlab-ce/tree/master/spec/mailers/previews +[previews]: https://gitlab.com/gitlab-org/gitlab-ce/tree/master/app/mailers/previews [Rails guides]: http://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails ## Incoming email diff --git a/spec/mailers/previews/devise_mailer_preview.rb b/spec/mailers/previews/devise_mailer_preview.rb deleted file mode 100644 index d6588efc486..00000000000 --- a/spec/mailers/previews/devise_mailer_preview.rb +++ /dev/null @@ -1,30 +0,0 @@ -class DeviseMailerPreview < ActionMailer::Preview - def confirmation_instructions_for_signup - DeviseMailer.confirmation_instructions(unsaved_user, 'faketoken', {}) - end - - def confirmation_instructions_for_new_email - user = User.last - user.unconfirmed_email = 'unconfirmed@example.com' - - DeviseMailer.confirmation_instructions(user, 'faketoken', {}) - end - - def reset_password_instructions - DeviseMailer.reset_password_instructions(unsaved_user, 'faketoken', {}) - end - - def unlock_instructions - DeviseMailer.unlock_instructions(unsaved_user, 'faketoken', {}) - end - - def password_change - DeviseMailer.password_change(unsaved_user, {}) - end - - private - - def unsaved_user - User.new(name: 'Jane Doe', email: 'jdoe@example.com') - end -end diff --git a/spec/mailers/previews/email_rejection_mailer_preview.rb b/spec/mailers/previews/email_rejection_mailer_preview.rb deleted file mode 100644 index 639e8471232..00000000000 --- a/spec/mailers/previews/email_rejection_mailer_preview.rb +++ /dev/null @@ -1,5 +0,0 @@ -class EmailRejectionMailerPreview < ActionMailer::Preview - def rejection - EmailRejectionMailer.rejection("some rejection reason", "From: someone@example.com\nraw email here").message - end -end diff --git a/spec/mailers/previews/notify_preview.rb b/spec/mailers/previews/notify_preview.rb deleted file mode 100644 index e32fd0bd120..00000000000 --- a/spec/mailers/previews/notify_preview.rb +++ /dev/null @@ -1,170 +0,0 @@ -class NotifyPreview < ActionMailer::Preview - def note_merge_request_email_for_individual_note - note_email(:note_merge_request_email) do - note = <<-MD.strip_heredoc - This is an individual note on a merge request :smiley: - - In this notification email, we expect to see: - - - The note contents (that's what you're looking at) - - A link to view this note on Gitlab - - An explanation for why the user is receiving this notification - MD - - create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, note: note) - end - end - - def note_merge_request_email_for_discussion - note_email(:note_merge_request_email) do - note = <<-MD.strip_heredoc - This is a new discussion on a merge request :smiley: - - In this notification email, we expect to see: - - - A line saying who started this discussion - - The note contents (that's what you're looking at) - - A link to view this discussion on Gitlab - - An explanation for why the user is receiving this notification - MD - - create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiscussionNote', note: note) - end - end - - def note_merge_request_email_for_diff_discussion - note_email(:note_merge_request_email) do - note = <<-MD.strip_heredoc - This is a new discussion on a merge request :smiley: - - In this notification email, we expect to see: - - - A line saying who started this discussion and on what file - - The diff - - The note contents (that's what you're looking at) - - A link to view this discussion on Gitlab - - An explanation for why the user is receiving this notification - MD - - position = Gitlab::Diff::Position.new( - old_path: "files/ruby/popen.rb", - new_path: "files/ruby/popen.rb", - old_line: nil, - new_line: 14, - diff_refs: merge_request.diff_refs - ) - - create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiffNote', position: position, note: note) - end - end - - def closed_issue_email - Notify.closed_issue_email(user.id, issue.id, user.id).message - end - - def issue_status_changed_email - Notify.issue_status_changed_email(user.id, issue.id, 'closed', user.id).message - end - - def closed_merge_request_email - Notify.closed_merge_request_email(user.id, issue.id, user.id).message - end - - def merge_request_status_email - Notify.merge_request_status_email(user.id, merge_request.id, 'closed', user.id).message - end - - def merged_merge_request_email - Notify.merged_merge_request_email(user.id, merge_request.id, user.id).message - end - - def member_access_denied_email - Notify.member_access_denied_email('project', project.id, user.id).message - end - - def member_access_granted_email - Notify.member_access_granted_email('project', user.id).message - end - - def member_access_requested_email - Notify.member_access_requested_email('group', user.id, 'some@example.com').message - end - - def member_invite_accepted_email - Notify.member_invite_accepted_email('project', user.id).message - end - - def member_invite_declined_email - Notify.member_invite_declined_email( - 'project', - project.id, - 'invite@example.com', - user.id - ).message - end - - def member_invited_email - Notify.member_invited_email('project', user.id, '1234').message - end - - def pages_domain_enabled_email - cleanup do - pages_domain = PagesDomain.new(domain: 'my.example.com', project: project, verified_at: Time.now, enabled_until: 1.week.from_now) - - Notify.pages_domain_enabled_email(pages_domain, user).message - end - end - - def pipeline_success_email - Notify.pipeline_success_email(pipeline, pipeline.user.try(:email)) - end - - def pipeline_failed_email - Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email)) - end - - private - - def project - @project ||= Project.find_by_full_path('gitlab-org/gitlab-test') - end - - def issue - @merge_request ||= project.issues.first - end - - def merge_request - @merge_request ||= project.merge_requests.first - end - - def pipeline - @pipeline = Ci::Pipeline.last - end - - def user - @user ||= User.last - end - - def create_note(params) - Notes::CreateService.new(project, user, params).execute - end - - def note_email(method) - cleanup do - note = yield - - Notify.public_send(method, user.id, note) - end - end - - def cleanup - email = nil - - ActiveRecord::Base.transaction do - email = yield - raise ActiveRecord::Rollback - end - - email - end -end diff --git a/spec/mailers/previews/repository_check_mailer_preview.rb b/spec/mailers/previews/repository_check_mailer_preview.rb deleted file mode 100644 index 19d4eab1805..00000000000 --- a/spec/mailers/previews/repository_check_mailer_preview.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RepositoryCheckMailerPreview < ActionMailer::Preview - def notify - RepositoryCheckMailer.notify(3).message - end -end -- cgit v1.2.1 From 66db55319054d6988bc8efd8fab9b59377907ef5 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 6 Jul 2018 21:38:05 +0800 Subject: Disable public_send for our preview mailers --- app/mailers/previews/notify_preview.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb index e32fd0bd120..3615cde8026 100644 --- a/app/mailers/previews/notify_preview.rb +++ b/app/mailers/previews/notify_preview.rb @@ -153,7 +153,7 @@ class NotifyPreview < ActionMailer::Preview cleanup do note = yield - Notify.public_send(method, user.id, note) + Notify.public_send(method, user.id, note) # rubocop:disable GitlabSecurity/PublicSend end end -- cgit v1.2.1