tests: fix post approval tests.

This commit is contained in:
evazion
2017-04-03 15:18:42 -05:00
parent 7c8135609b
commit 5db39f308a
2 changed files with 14 additions and 27 deletions

View File

@@ -23,7 +23,7 @@ class PostApprovalTest < ActiveSupport::TestCase
end end
should "allow approval" do should "allow approval" do
assert_equal(false, PostApproval.approved?(@approver.id, @post.id)) assert_equal(false, @post.approved_by?(@approver))
end end
context "That is approved" do context "That is approved" do
@@ -43,19 +43,16 @@ class PostApprovalTest < ActiveSupport::TestCase
end end
should "prevent the first approver from approving again" do should "prevent the first approver from approving again" do
@post.approve! @post.approve!(@approver)
CurrentUser.user = @user2 CurrentUser.user = @user2
@post.flag!("blah") @post.flag!("blah")
CurrentUser.user = @approver2 @post.approve!(@approver2)
@post.approve!
assert_not_equal(@approver.id, @post.approver_id) assert_not_equal(@approver.id, @post.approver_id)
CurrentUser.user = @user3 CurrentUser.user = @user3
@post.flag!("blah blah") @post.flag!("blah blah")
CurrentUser.user = @approver
assert_raises(Post::ApprovalError) do approval = @post.approve!(@approver)
@post.approve! assert_includes(approval.errors.full_messages, "You have previously approved this post and cannot approve it again")
end
end end
end end
end end

View File

@@ -412,13 +412,10 @@ class PostTest < ActiveSupport::TestCase
end end
should "not allow person X to approve that post" do should "not allow person X to approve that post" do
assert_raises(Post::ApprovalError) do approval = @post.approve!(@post.uploader)
CurrentUser.scoped(@post.uploader, "127.0.0.1") do
@post.approve!
end
end
assert_equal(["You cannot approve a post you uploaded"], @post.errors.full_messages) assert(@post.invalid?)
assert_includes(approval.errors.full_messages, "You cannot approve a post you uploaded")
end end
end end
@@ -431,19 +428,13 @@ class PostTest < ActiveSupport::TestCase
end end
should "not allow person X to reapprove that post" do should "not allow person X to reapprove that post" do
CurrentUser.scoped(@user, "127.0.0.1") do approval = @post.approve!(@user)
assert_raises(Post::ApprovalError) do assert_includes(approval.errors.full_messages, "You have previously approved this post and cannot approve it again")
@post.approve!
end
end
end end
should "allow person Y to approve the post" do should "allow person Y to approve the post" do
CurrentUser.scoped(@user2, "127.0.0.1") do @post.approve!(@user2)
assert_nothing_raised do assert(@post.valid?)
@post.approve!
end
end
end end
end end
@@ -479,9 +470,8 @@ class PostTest < ActiveSupport::TestCase
end end
should "not allow approval" do should "not allow approval" do
assert_raises(Post::ApprovalError) do approval = @post.approve!
@post.approve! assert_includes(approval.errors.full_messages, "Post is locked and cannot be approved")
end
end end
end end
end end