* Approvers can no longer approve an unapproved post if they previously approved it

This commit is contained in:
albert
2010-11-04 18:31:36 -04:00
parent 551c25909c
commit 6076788d60
3 changed files with 22 additions and 36 deletions

View File

@@ -34,6 +34,10 @@ class CurrentUser
user.id
end
def self.name
user.name
end
def self.method_missing(method, *params, &block)
if user.respond_to?(method)
user.__send__(method, *params, &block)

View File

@@ -1,4 +1,6 @@
class Post < ActiveRecord::Base
class ApprovalError < Exception ; end
attr_accessor :old_tag_string, :old_parent_id
after_destroy :delete_files
after_save :update_history
@@ -211,9 +213,11 @@ class Post < ActiveRecord::Base
end
def approve!
raise ApprovalError.new("You have already approved this post previously") if approver_string == "approver:#{CurrentUser.name}"
self.is_flagged = false
self.is_pending = false
self.approver_string = "approver:#{CurrentUser.user.name}"
self.approver_string = "approver:#{CurrentUser.name}"
save!
end
end

View File

@@ -192,6 +192,19 @@ class PostTest < ActiveSupport::TestCase
assert_equal("bad", removed_post.unapproval.reason)
end
context "that was previously approved by person X" do
should "not allow person X to reapprove that post" do
user = Factory.create(:janitor_user, :name => "xxx")
post = Factory.create(:post, :approver_string => "approver:xxx")
post.unapprove!("bad")
CurrentUser.scoped(user, "127.0.0.1") do
assert_raises(Post::ApprovalError) do
post.approve!
end
end
end
end
context "that has been reapproved" do
should "no longer be flagged or pending" do
post = Factory.create(:post)
@@ -213,41 +226,6 @@ class PostTest < ActiveSupport::TestCase
end
end
context "Versioning:" do
context "Saving a post" do
should "create a new version" do
post = Factory.create(:post)
assert_equal(1, post.versions.size)
post.rating = "e"
post.save
assert_equal(2, post.versions.size)
assert_equal(CurrentUser.user.id, post.versions.last.updater_id)
assert_equal(CurrentUser.ip_addr, post.versions.last.updater_ip_addr)
post.revert_to!(PostVersion.first)
assert_equal("tag1 tag2", post.tag_string)
assert_equal("q", post.rating)
end
end
context "Reverting a post" do
should "identify the person who reverted the post" do
post = Factory.create(:post)
reverter = Factory.create(:user)
post.rating = "e"
post.save
post.rating = "q"
post.save
CurrentUser.user = Factory.create(:user)
post.revert_to!(PostVersion.first)
post.reload
assert_equal(CurrentUser.user.id, post.versions.last.updater_id)
end
end
end
context "Tagging:" do
context "A post" do
should "have an array representation of its tags" do