From 232f0d0122018c376a1008cd64b406f42efb0306 Mon Sep 17 00:00:00 2001 From: sean-garwood Date: Fri, 29 Nov 2024 15:45:13 -0500 Subject: [PATCH] feat: action mailer * using gmail fix: remove unused follow request statuses * rejected * blocked might add these in later. --- app/mailers/application_mailer.rb | 2 +- app/models/follow_request.rb | 3 ++- app/models/user.rb | 2 ++ app/views/user_mailer/weclome_email.html.erb | 4 ++-- app/views/user_mailer/welcome_email.text.erb | 4 ++-- config/environments/production.rb | 16 ++++++++++++++++ config/routes.rb | 1 - .../follow_requests_controller_test.rb | 5 ----- test/models/follow_request_test.rb | 6 ------ 9 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index a99b964..f976fdb 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: "admin@matltc.com" + default from: "midatl.tc@gmail.com" layout "mailer" end diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb index 7ba270a..0c45242 100644 --- a/app/models/follow_request.rb +++ b/app/models/follow_request.rb @@ -2,7 +2,8 @@ class FollowRequest < ApplicationRecord belongs_to :sender, class_name: "User", foreign_key: "sender_id" belongs_to :recipient, class_name: "User", foreign_key: "recipient_id" - enum :status, { pending: 0, accepted: 1, rejected: 2, blocked: 3 } + # TODO: 'rejected', 'blocked' statuses would be fun... + enum :status, { pending: 0, accepted: 1 } validates :recipient_id, uniqueness: { scope: :sender_id, message: "Already requested" }, diff --git a/app/models/user.rb b/app/models/user.rb index 7b2d7e5..fead5d6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,6 +7,8 @@ class User < ApplicationRecord :recoverable, :rememberable, :validatable after_create -> { create_profile(name: simpsons_name, bio: simpsons_quote) } + # send a welcome email after a user is created + after_create -> { UserMailer.with(user: self).welcome_email.deliver_later } delegate :name, to: :profile, allow_nil: true has_many :comments, dependent: :destroy, inverse_of: :author diff --git a/app/views/user_mailer/weclome_email.html.erb b/app/views/user_mailer/weclome_email.html.erb index 73f4896..61a292e 100644 --- a/app/views/user_mailer/weclome_email.html.erb +++ b/app/views/user_mailer/weclome_email.html.erb @@ -1,6 +1,6 @@ -

Welcome to matltc.com, <%= @user.name %>

+

Welcome to top-odinbook.fly.dev, <%= @user.name %>

- You have successfully signed up to matltc.com. + You have successfully signed up to top-odinbook.fly.dev.

To login to the site, just follow <%= link_to "this link", @url %> diff --git a/app/views/user_mailer/welcome_email.text.erb b/app/views/user_mailer/welcome_email.text.erb index 36b8a4e..0a816c3 100644 --- a/app/views/user_mailer/welcome_email.text.erb +++ b/app/views/user_mailer/welcome_email.text.erb @@ -1,5 +1,5 @@ -Welcome to matltc.com<%= @user.name ? ", #{@user.name}" : nil %>. +Welcome to top-odinbook.fly.dev<%= @user.name ? ", #{@user.name}" : nil %>. ================================================================================ -You have successfully signed up to matltc.com. +You have successfully signed up to top-odinbook.fly.dev. To login to the site, just follow this link: <%= @url %> Thanks for joining and have a great day! diff --git a/config/environments/production.rb b/config/environments/production.rb index d068493..e1afe6b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -82,6 +82,22 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false + # Set default url options for action mailer. + config.action_mailer.default_url_options = { host: "top-odinbook.fly.dev" } + + # Enable using Gmail to send emails. + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "top-odinbook.fly.dev", + user_name: Rails.application.credentials.dig(:smtp, :user_name), + password: Rails.application.credentials.dig(:smtp, :password), + authentication: "plain", + enable_starttls: true, + open_timeout: 5, + read_timeout: 5 } + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true diff --git a/config/routes.rb b/config/routes.rb index 41684f9..86c5f92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,7 +13,6 @@ end member do patch :accept - patch :reject end end diff --git a/test/controllers/follow_requests_controller_test.rb b/test/controllers/follow_requests_controller_test.rb index 5cee70e..d8346e1 100644 --- a/test/controllers/follow_requests_controller_test.rb +++ b/test/controllers/follow_requests_controller_test.rb @@ -29,9 +29,4 @@ class FollowRequestsControllerTest < ActionDispatch::IntegrationTest delete follow_request_path(@follow_request) assert_equal "Follow request cancelled.", flash[:notice] end - test "should reject follow request" do - @follow_request = follow_requests(:three) - patch reject_follow_request_path(@follow_request) - assert_equal "Follow request rejected.", flash[:notice] - end end diff --git a/test/models/follow_request_test.rb b/test/models/follow_request_test.rb index d7c34f7..f15c61b 100644 --- a/test/models/follow_request_test.rb +++ b/test/models/follow_request_test.rb @@ -19,12 +19,6 @@ class FollowRequestTest < ActiveSupport::TestCase assert follow_request.accepted? end - test "rejected request has status rejected" do - follow_request = follow_requests(:three) - follow_request.rejected! - assert follow_request.rejected? - end - test "can't follow self" do assert_not follow_requests(:self_request).valid?, "Can follow self" end