added post flag test

This commit is contained in:
albert
2011-03-30 14:13:42 -04:00
parent 5856b105f5
commit a871b425f6
36 changed files with 214 additions and 128 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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) %>