-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
spending_proposal.rb
44 lines (33 loc) · 1.11 KB
/
spending_proposal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class SpendingProposal < ActiveRecord::Base
include Measurable
include Sanitizable
apply_simple_captcha
RESOLUTIONS = ["accepted", "rejected"]
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :geozone
validates :title, presence: true
validates :author, presence: true
validates :description, presence: true
validates :title, length: { in: 4..SpendingProposal.title_max_length }
validates :description, length: { maximum: SpendingProposal.description_max_length }
validates :resolution, inclusion: { in: RESOLUTIONS, allow_nil: true }
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
scope :accepted, -> { where(resolution: "accepted") }
scope :rejected, -> { where(resolution: "rejected") }
scope :unresolved, -> { where(resolution: nil) }
def accept
update_attribute(:resolution, "accepted")
end
def reject
update_attribute(:resolution, "rejected")
end
def accepted?
resolution == "accepted"
end
def rejected?
resolution == "rejected"
end
def unresolved?
resolution.blank?
end
end