* Approvers can no longer approve an unapproved post if they previously approved it
This commit is contained in:
@@ -34,6 +34,10 @@ class CurrentUser
|
|||||||
user.id
|
user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.name
|
||||||
|
user.name
|
||||||
|
end
|
||||||
|
|
||||||
def self.method_missing(method, *params, &block)
|
def self.method_missing(method, *params, &block)
|
||||||
if user.respond_to?(method)
|
if user.respond_to?(method)
|
||||||
user.__send__(method, *params, &block)
|
user.__send__(method, *params, &block)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
class Post < ActiveRecord::Base
|
class Post < ActiveRecord::Base
|
||||||
|
class ApprovalError < Exception ; end
|
||||||
|
|
||||||
attr_accessor :old_tag_string, :old_parent_id
|
attr_accessor :old_tag_string, :old_parent_id
|
||||||
after_destroy :delete_files
|
after_destroy :delete_files
|
||||||
after_save :update_history
|
after_save :update_history
|
||||||
@@ -211,9 +213,11 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def approve!
|
def approve!
|
||||||
|
raise ApprovalError.new("You have already approved this post previously") if approver_string == "approver:#{CurrentUser.name}"
|
||||||
|
|
||||||
self.is_flagged = false
|
self.is_flagged = false
|
||||||
self.is_pending = false
|
self.is_pending = false
|
||||||
self.approver_string = "approver:#{CurrentUser.user.name}"
|
self.approver_string = "approver:#{CurrentUser.name}"
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -192,6 +192,19 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_equal("bad", removed_post.unapproval.reason)
|
assert_equal("bad", removed_post.unapproval.reason)
|
||||||
end
|
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
|
context "that has been reapproved" do
|
||||||
should "no longer be flagged or pending" do
|
should "no longer be flagged or pending" do
|
||||||
post = Factory.create(:post)
|
post = Factory.create(:post)
|
||||||
@@ -213,41 +226,6 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
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 "Tagging:" do
|
||||||
context "A post" do
|
context "A post" do
|
||||||
should "have an array representation of its tags" do
|
should "have an array representation of its tags" do
|
||||||
|
|||||||
Reference in New Issue
Block a user