2015-04-17 02:01:28 +03:00
|
|
|
class Proposition < ActiveRecord::Base
|
|
|
|
belongs_to :proposer, class_name: 'User'
|
2016-10-07 02:53:20 +03:00
|
|
|
belongs_to :proposable, polymorphic: true, dependent: :destroy
|
2015-04-20 18:34:17 +03:00
|
|
|
enum status: [:undecided, :approved, :rejected, :backup]
|
2015-08-20 01:42:35 +03:00
|
|
|
delegate :proposable_title, :proposable_type, :proposable_description, to: :proposable
|
|
|
|
|
2015-08-20 01:45:57 +03:00
|
|
|
after_create :send_creation_notification
|
2015-09-02 00:07:50 +03:00
|
|
|
before_destroy :send_withdrawal_notification
|
2015-08-20 01:45:57 +03:00
|
|
|
|
2015-10-19 00:47:39 +03:00
|
|
|
def confirm!
|
|
|
|
update(confirmed_at: Time.now)
|
|
|
|
end
|
|
|
|
|
2015-08-20 01:42:35 +03:00
|
|
|
def send_creation_notification
|
|
|
|
PropositionMailer.new_proposition_notification(self).deliver_later
|
|
|
|
end
|
2015-09-02 00:07:50 +03:00
|
|
|
|
|
|
|
def send_withdrawal_notification
|
|
|
|
PropositionMailer.proposition_withdrawal_notification(self).deliver_later
|
|
|
|
end
|
2015-04-17 02:01:28 +03:00
|
|
|
end
|