Compare commits
1 Commits
72f2894b06
...
8836532664
Author | SHA1 | Date |
---|---|---|
Trevor Vallender | 8836532664 |
|
@ -20,9 +20,6 @@ class UserMailer < ApplicationMailer
|
|||
@user = params[:user]
|
||||
@token = params[:token]
|
||||
|
||||
return if @user.password_reset_last_sent_at&.after?(10.minutes.ago)
|
||||
|
||||
@user.update(password_reset_last_sent_at: Time.zone.now)
|
||||
mail(to: @user.email, subject: t(".password_reset.subject"))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPasswordResetLastSentAtToUser < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :users, :password_reset_last_sent_at, :datetime
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_06_05_132327) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_05_30_073852) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -221,7 +221,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_05_132327) do
|
|||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "verified", default: false, null: false
|
||||
t.datetime "password_reset_last_sent_at"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["username"], name: "index_users_on_username", unique: true
|
||||
t.index ["verified"], name: "index_users_on_verified"
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UserMailerTest < ActionMailer::TestCase
|
||||
test "password resets can’t be resent within 10 minutes" do
|
||||
user = users(:trevor)
|
||||
assert_emails(+1) do
|
||||
UserMailer.with(user: user, token: user.generate_token_for(:password_reset)).password_reset.deliver_now
|
||||
end
|
||||
assert_emails(0) do
|
||||
UserMailer.with(user: user, token: user.generate_token_for(:password_reset)).password_reset.deliver_now
|
||||
end
|
||||
travel 11.minutes
|
||||
assert_emails(+1) do
|
||||
UserMailer.with(user: user, token: user.generate_token_for(:password_reset)).password_reset.deliver_now
|
||||
end
|
||||
end
|
||||
end
|
|
@ -55,15 +55,4 @@ class UserTest < ActiveSupport::TestCase
|
|||
user.update(password: "new_password")
|
||||
assert_nil User.find_by_token_for(:password_reset, token)
|
||||
end
|
||||
|
||||
test "avatar is automatically deleted when flag set" do
|
||||
user = users(:trevor)
|
||||
assert user.avatar.attached?
|
||||
user.first_name = "Newname"
|
||||
user.save
|
||||
assert user.avatar.attached?
|
||||
user.delete_avatar = true
|
||||
user.save
|
||||
assert_not user.avatar.attached?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue