From fdd2e657ee3db5bb82bc60241e467d60e6950f3a Mon Sep 17 00:00:00 2001 From: Alexey Sologub Date: Tue, 13 Sep 2022 19:58:07 -0400 Subject: [PATCH] mailer for Operation entity added, feature of sending notifications added to users#update and destroy services --- app/jobs/application_job.rb | 0 app/mailers/action_notification_mailer.rb | 10 ++++++++++ app/mailers/application_mailer.rb | 0 app/models/operation.rb | 9 +++++++++ .../action_notification_email.html.erb | 14 ++++++++++++++ app/views/layouts/mailer.html.erb | 0 app/views/layouts/mailer.text.erb | 0 spec/mailers/action_notification_spec.rb | 5 +++++ .../previews/action_notification_preview.rb | 4 ++++ 9 files changed, 42 insertions(+) mode change 100644 => 100755 app/jobs/application_job.rb create mode 100755 app/mailers/action_notification_mailer.rb mode change 100644 => 100755 app/mailers/application_mailer.rb mode change 100644 => 100755 app/models/operation.rb create mode 100644 app/views/action_notification_mailer/action_notification_email.html.erb mode change 100644 => 100755 app/views/layouts/mailer.html.erb mode change 100644 => 100755 app/views/layouts/mailer.text.erb create mode 100644 spec/mailers/action_notification_spec.rb create mode 100644 spec/mailers/previews/action_notification_preview.rb diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb old mode 100644 new mode 100755 diff --git a/app/mailers/action_notification_mailer.rb b/app/mailers/action_notification_mailer.rb new file mode 100755 index 0000000..70e9644 --- /dev/null +++ b/app/mailers/action_notification_mailer.rb @@ -0,0 +1,10 @@ +class ActionNotificationMailer < ApplicationMailer + default from: "mytestgmailemail@gmail.com" + + def action_notification_email + @operation = params[:operation] + mail(to: @operation.user, subject: "Action has been taken") + end + + +end \ No newline at end of file diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb old mode 100644 new mode 100755 diff --git a/app/models/operation.rb b/app/models/operation.rb old mode 100644 new mode 100755 index 572f14c..78daa06 --- a/app/models/operation.rb +++ b/app/models/operation.rb @@ -1,2 +1,11 @@ class Operation < ApplicationRecord + + after_commit :notify, on: :create + + def notify + ActionNotificationMailer.with({operation: self}) + .action_notification_email + .deliver_now + end + end diff --git a/app/views/action_notification_mailer/action_notification_email.html.erb b/app/views/action_notification_mailer/action_notification_email.html.erb new file mode 100644 index 0000000..6400585 --- /dev/null +++ b/app/views/action_notification_mailer/action_notification_email.html.erb @@ -0,0 +1,14 @@ + + + + + + +

Hello <%= @operation.user %>

+

+ This is a message that action '<%= @operation.action %>' has been taken. +

+

Have a good day!

+ + + \ No newline at end of file diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb old mode 100644 new mode 100755 diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb old mode 100644 new mode 100755 diff --git a/spec/mailers/action_notification_spec.rb b/spec/mailers/action_notification_spec.rb new file mode 100644 index 0000000..9c92460 --- /dev/null +++ b/spec/mailers/action_notification_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +RSpec.describe ActionNotificationMailer, type: :mailer do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/mailers/previews/action_notification_preview.rb b/spec/mailers/previews/action_notification_preview.rb new file mode 100644 index 0000000..db89b24 --- /dev/null +++ b/spec/mailers/previews/action_notification_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/action_notification +class ActionNotificationPreview < ActionMailer::Preview + +end