Skip to content

Commit

Permalink
Ensure user validations are run for new records
Browse files Browse the repository at this point in the history
This works around an issue with rails failing to preserve attribute
change flags when we save a user record in the session.

rails/rails#49826
rails/rails#49827
  • Loading branch information
tomhughes committed Oct 28, 2023
1 parent 6f60111 commit c45792a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ class User < ApplicationRecord

validates :display_name, :presence => true, :length => 3..255,
:exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
validates :display_name, :if => proc { |u| u.display_name_changed? },
validates :display_name, :if => proc { |u| u.new_record? || u.display_name_changed? },
:uniqueness => { :case_sensitive => false }
validates :display_name, :if => proc { |u| u.display_name_changed? },
validates :display_name, :if => proc { |u| u.new_record? || u.display_name_changed? },
:characters => { :url_safe => true },
:whitespace => { :leading => false, :trailing => false }
validates :email, :presence => true, :confirmation => true, :characters => true
validates :email, :if => proc { |u| u.email_changed? },
validates :email, :if => proc { |u| u.new_record? || u.email_changed? },
:uniqueness => { :case_sensitive => false }
validates :email, :if => proc { |u| u.email_changed? },
validates :email, :if => proc { |u| u.new_record? || u.email_changed? },
:whitespace => { :leading => false, :trailing => false }
validates :pass_crypt, :confirmation => true, :length => 8..255
validates :home_lat, :allow_nil => true, :numericality => true, :inclusion => { :in => -90..90 }
Expand All @@ -110,8 +110,8 @@ class User < ApplicationRecord
validates :avatar, :if => proc { |u| u.attachment_changes["avatar"] },
:image => true

validates_email_format_of :email, :if => proc { |u| u.email_changed? }
validates_email_format_of :new_email, :allow_blank => true, :if => proc { |u| u.new_email_changed? }
validates_email_format_of :email, :if => proc { |u| u.new_record? || u.email_changed? }
validates_email_format_of :new_email, :allow_blank => true, :if => proc { |u| u.new_record? || u.new_email_changed? }

alias_attribute :created_at, :creation_time

Expand Down

0 comments on commit c45792a

Please sign in to comment.