Created
February 27, 2013 23:01
-
-
Save dreamr/5052652 to your computer and use it in GitHub Desktop.
Without the self[:attr] form of referencing the attribute the tests fail because the values cant be found after being set ie: disapproved_by = user.id # or @disapproved_by = user.id # or self.disapproved_by = user.id # or
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires on the model that mixes this concern in: | |
# => approved_by integer | |
# => approved_at DateTime | |
# => disapproved_by integer | |
# => disapproved_at DateTime | |
module Moderation | |
extend ActiveSupport::Concern | |
included do | |
belongs_to :approved_by, class_name: "User", foreign_key: :approved_by | |
belongs_to :disapproved_by, class_name: "User", foreign_key: :disapproved_by | |
scope :approved, where("approved_at IS NOT NULL") | |
scope :disapproved, where("disapproved_at IS NOT NULL") | |
end | |
def published? | |
self[:disapproved_at].blank? | |
end | |
def approve!(user) | |
self[:disapproved_by] = self[:disapproved_at] = nil | |
self[:approved_by] = user.id | |
self[:approved_at] = DateTime.now.utc | |
save | |
end | |
def dissaprove!(user) | |
self[:approved_by] = self[:approved_at] = nil | |
self[:disapproved_by] = user.id | |
self[:disapproved_at] = DateTime.now.utc | |
save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment