Skip to content

Commit

Permalink
feat: action mailer
Browse files Browse the repository at this point in the history
* using gmail

fix: remove unused follow request statuses

* rejected
* blocked

might add these in later.
  • Loading branch information
sean-garwood committed Nov 29, 2024
1 parent 6140f9c commit 232f0d0
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "admin@matltc.com"
default from: "midatl.tc@gmail.com"
layout "mailer"
end
3 changes: 2 additions & 1 deletion app/models/follow_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/user_mailer/weclome_email.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Welcome to matltc.com, <%= @user.name %></h1>
<h1>Welcome to top-odinbook.fly.dev, <%= @user.name %></h1>
<p>
You have successfully signed up to matltc.com.
You have successfully signed up to top-odinbook.fly.dev.
</p>
<p>
To login to the site, just follow <%= link_to "this link", @url %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/user_mailer/welcome_email.text.erb
Original file line number Diff line number Diff line change
@@ -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!
16 changes: 16 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
end
member do
patch :accept
patch :reject
end
end

Expand Down
5 changes: 0 additions & 5 deletions test/controllers/follow_requests_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions test/models/follow_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 232f0d0

Please sign in to comment.