* Initial pins work * Add pin box to profiles * Fix test snapshot spacing and optimize svg * Fix listings spacing
21 lines
838 B
Ruby
21 lines
838 B
Ruby
class ProfilePin < ApplicationRecord
|
|
belongs_to :pinnable, polymorphic: true
|
|
belongs_to :profile, polymorphic: true
|
|
|
|
validates :profile_id, presence: true
|
|
validates :profile_type, inclusion: { in: %w[User] } # Future could be organization, tag, etc.
|
|
validates :pinnable_id, presence: true, uniqueness: { scope: %i[profile_id profile_type pinnable_type]}
|
|
validates :pinnable_type, inclusion: { in: %w[Article] } # Future could be comments, etc.
|
|
validate :only_five_pins_per_profile
|
|
validate :pinnable_belongs_to_profile
|
|
|
|
private
|
|
|
|
def only_five_pins_per_profile
|
|
errors.add(:base, "cannot have more than five total pinned posts") if profile.profile_pins.size > 5
|
|
end
|
|
|
|
def pinnable_belongs_to_profile
|
|
errors.add(:pinnable_id, "must have proper premissions for pin") if pinnable.user_id != profile_id
|
|
end
|
|
end
|