about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-06-08 19:10:48 +0200
committerGitHub <noreply@github.com>2017-06-08 19:10:48 +0200
commit177dd8bb535523db88c24805397faebd27fba829 (patch)
tree53c5061e6d7b87bb30b608cdcd5771f722e1334a
parent380b20eed6b2b916fe35366725243d7c256f0783 (diff)
Fix regression from #3592 - validation condition nesting (#3644)
-rw-r--r--app/models/account.rb12
1 files changed, 4 insertions, 8 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 214d3b9fd..ac5137131 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -54,16 +54,12 @@ class Account < ApplicationRecord
   validates :username, presence: true
 
   # Remote user validations
-  with_options unless: :local? do
-    validates :username, uniqueness: { scope: :domain, case_sensitive: true }, if: :username_changed?
-  end
+  validates :username, uniqueness: { scope: :domain, case_sensitive: true }, if: -> { !local? && username_changed? }
 
   # Local user validations
-  with_options if: :local? do
-    validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }, unreserved: true, if: :username_changed?
-    validates :display_name, length: { maximum: 30 }, if: :display_name_changed?
-    validates :note, length: { maximum: 160 }, if: :note_changed?
-  end
+  validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }, unreserved: true, if: -> { local? && username_changed? }
+  validates :display_name, length: { maximum: 30 }, if: -> { local? && display_name_changed? }
+  validates :note, length: { maximum: 160 }, if: -> { local? && note_changed? }
 
   # Timelines
   has_many :stream_entries, inverse_of: :account, dependent: :destroy