added post flag test
This commit is contained in:
@@ -216,7 +216,7 @@ class Post < ActiveRecord::Base
|
||||
|
||||
module ApprovalMethods
|
||||
def is_approvable?
|
||||
(is_pending? || is_flagged?) && approver_string != "approver:#{CurrentUser.name}"
|
||||
(is_pending? || is_flagged? || is_deleted?) && approver_string != "approver:#{CurrentUser.name}"
|
||||
end
|
||||
|
||||
def flag!(reason)
|
||||
@@ -240,8 +240,10 @@ class Post < ActiveRecord::Base
|
||||
def approve!
|
||||
raise ApprovalError.new("You have previously approved this post and cannot approve it again") if approver_string == "approver:#{CurrentUser.name}"
|
||||
|
||||
flags.each {|x| x.resolve!}
|
||||
self.is_flagged = false
|
||||
self.is_pending = false
|
||||
self.is_deleted = false
|
||||
self.approver_string = "approver:#{CurrentUser.name}"
|
||||
save!
|
||||
end
|
||||
|
||||
@@ -7,15 +7,17 @@ class PostFlag < ActiveRecord::Base
|
||||
validate :validate_creator_is_not_limited
|
||||
validate :validate_post_is_active
|
||||
before_validation :initialize_creator, :on => :create
|
||||
validates_uniqueness_of :creator_id, :scope => :post_id
|
||||
validates_uniqueness_of :creator_id, :scope => :post_id, :message => "has already flagged this post"
|
||||
before_save :update_post
|
||||
scope :resolved, where(["is_resolved = ?", true])
|
||||
scope :unresolved, where(["is_resolved = ?", false])
|
||||
|
||||
def update_post
|
||||
post.update_attribute(:is_flagged, true)
|
||||
end
|
||||
|
||||
def validate_creator_is_not_limited
|
||||
if PostAppeal.for_user(creator_id).recent.count >= 10
|
||||
if flag_count_for_creator >= 10
|
||||
errors[:creator] << "can flag 10 posts a day"
|
||||
false
|
||||
else
|
||||
@@ -36,4 +38,12 @@ class PostFlag < ActiveRecord::Base
|
||||
self.creator_id = CurrentUser.id
|
||||
self.creator_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def resolve!
|
||||
update_attribute(:is_resolved, true)
|
||||
end
|
||||
|
||||
def flag_count_for_creator
|
||||
PostAppeal.for_user(creator_id).recent.count
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% if post.is_flagged? %>
|
||||
<% if (post.is_flagged? || post.is_deleted?) && post.flags.any? %>
|
||||
<div class="ui-corner-all ui-state-error notice">
|
||||
<span class="ui-icon ui-icon-alert"></span>
|
||||
This post has been flagged for deletion: <%= post_flag_reasons(post) %>
|
||||
|
||||
Reference in New Issue
Block a user