Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Account < ApplicationRecord
validate :email_is_valid, on: :create
validates :name, presence: true
validates :accent_color, format: { with: /\A#[0-9a-fA-F]{6}\z/ }, allow_nil: true
validate :pinned_post_belongs_to_account
VALID_SLUG_REGEX = /\A[a-z0-9]+(-[a-z0-9]+)*\z/
validates :slug, presence: true, length: { minimum: 2, maximum: 255 },
format: { with: VALID_SLUG_REGEX, message: "can only contain letters, numbers and '-'" },
Expand Down Expand Up @@ -293,6 +294,14 @@ def email_is_valid
errors.add(email, "can't receive email") unless Truemail.valid?(email)
end

def pinned_post_belongs_to_account
return if pinned_post_id.blank?

unless posts.exists?(id: pinned_post_id)
errors.add(:pinned_post, 'must belong to this account')
end
end

def downcase_slug
self.slug = slug.downcase
end
Expand Down