adds as_moderator/administrator methods to comment
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
acts_as_nested_set scope: [:commentable_id, :commentable_type], counter_cache: :children_count
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
acts_as_votable
|
||||
|
||||
attr_accessor :comment_as_moderator, :comment_as_administrator
|
||||
|
||||
validates :body, presence: true
|
||||
validates :user, presence: true
|
||||
|
||||
@@ -59,6 +60,14 @@ class Comment < ActiveRecord::Base
|
||||
reviewed_at.present?
|
||||
end
|
||||
|
||||
def as_administrator?
|
||||
administrator_id.present?
|
||||
end
|
||||
|
||||
def as_moderator?
|
||||
moderator_id.present?
|
||||
end
|
||||
|
||||
def mark_as_reviewed
|
||||
update(reviewed_at: Time.now)
|
||||
end
|
||||
|
||||
@@ -38,4 +38,24 @@ describe Comment do
|
||||
expect { new_comment.destroy }.to change { comment.children_count }.from(1).to(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#as_administrator?" do
|
||||
it "should be true if comment has administrator_id, false otherway" do
|
||||
expect(comment).not_to be_as_administrator
|
||||
|
||||
comment.administrator_id = 33
|
||||
|
||||
expect(comment).to be_as_administrator
|
||||
end
|
||||
end
|
||||
|
||||
describe "#as_moderator?" do
|
||||
it "should be true if comment has moderator_id, false otherway" do
|
||||
expect(comment).not_to be_as_moderator
|
||||
|
||||
comment.moderator_id = 21
|
||||
|
||||
expect(comment).to be_as_moderator
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user