diff options
author | ThibG <thib@sitedethib.com> | 2019-03-13 16:55:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 16:55:07 +0100 |
commit | 3005e473a0df4d2ea942dcc33e01c5e4c15b81fa (patch) | |
tree | 8d0b0e635bf12a56ae99278ab206684da2a9aad1 /app/models | |
parent | c2857c976c7d4a8bbd02c3c18569913f2bf8a034 (diff) | |
parent | 387f253f3100317ae247928aa9168f431879ecb6 (diff) |
Merge pull request #957 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 5 | ||||
-rw-r--r-- | app/models/concerns/expireable.rb | 6 | ||||
-rw-r--r-- | app/models/tag.rb | 8 |
3 files changed, 18 insertions, 1 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 79eecc306..0bb20b2f2 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -474,6 +474,7 @@ class Account < ApplicationRecord before_create :generate_keys before_validation :prepare_contents, if: :local? + before_validation :prepare_username, on: :create before_destroy :clean_feed_manager private @@ -483,6 +484,10 @@ class Account < ApplicationRecord note&.strip! end + def prepare_username + username&.squish! + end + def generate_keys return unless local? && !Rails.env.test? diff --git a/app/models/concerns/expireable.rb b/app/models/concerns/expireable.rb index 2c0631476..f7d2bab49 100644 --- a/app/models/concerns/expireable.rb +++ b/app/models/concerns/expireable.rb @@ -18,7 +18,11 @@ module Expireable end def expired? - !expires_at.nil? && expires_at < Time.now.utc + expires? && expires_at < Time.now.utc + end + + def expires? + !expires_at.nil? end end end diff --git a/app/models/tag.rb b/app/models/tag.rb index 788a678bd..7db76d157 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -72,6 +72,14 @@ class Tag < ApplicationRecord .limit(limit) .offset(offset) end + + def find_normalized(name) + find_by(name: name.mb_chars.downcase.to_s) + end + + def find_normalized!(name) + find_normalized(name) || raise(ActiveRecord::RecordNotFound) + end end private |