about summary refs log tree commit diff
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-06-08 15:22:01 +0200
committerMatt Jankowski <mjankowski@thoughtbot.com>2017-06-08 09:22:01 -0400
commitc207b4bb330463c39c202d1c66e2447b55332093 (patch)
tree932150591bd43dc2c4b3490f9be29132911b1bf6 /app/models/account.rb
parentb87eb8ea146a54fcfd2533f47622070d0f30a9fa (diff)
Fix db:seed - only run some validations when the field was changed (#3592)
* Fix db:seed - only run some validations when the field was changed

* Add tests
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 918d5b0f1..214d3b9fd 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -52,13 +52,17 @@ class Account < ApplicationRecord
   has_one :user, inverse_of: :account
 
   validates :username, presence: true
-  validates :username, uniqueness: { scope: :domain, case_sensitive: true }, unless: :local?
+
+  # Remote user validations
+  with_options unless: :local? do
+    validates :username, uniqueness: { scope: :domain, case_sensitive: true }, if: :username_changed?
+  end
 
   # 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
-    validates :display_name, length: { maximum: 30 }
-    validates :note, length: { maximum: 160 }
+    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
 
   # Timelines