summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2011-09-04 22:22:40 +0200
committerAlex Legler <alex@a3li.li>2011-09-04 22:22:40 +0200
commit52a0052598a0e2f8cfa6f977d44f94963009344c (patch)
tree129b2cb42999069320a4b91d2bcd7a85b39377a0 /test/unit/comment_test.rb
parentCommentsController: Apply permissions (diff)
downloadglsamaker-52a0052598a0e2f8cfa6f977d44f94963009344c.tar.gz
glsamaker-52a0052598a0e2f8cfa6f977d44f94963009344c.tar.bz2
glsamaker-52a0052598a0e2f8cfa6f977d44f94963009344c.zip
Test comment permission handling
Diffstat (limited to 'test/unit/comment_test.rb')
-rw-r--r--test/unit/comment_test.rb54
1 files changed, 50 insertions, 4 deletions
diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb
index 47dee99..f3e02dd 100644
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -1,8 +1,54 @@
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+ fixtures :all
+
+ test "padawans should not be able to make approvals" do
+ c = Comment.new
+ c.glsa_id = 1
+ c.user = users(:test_padawan)
+ c.text = "test"
+ c.rating = "approval"
+ c.save
+
+ assert c.errors.any?
+ assert_equal ["You may not approve or reject drafts"], c.errors[:rating]
+ end
+
+ test "padawans should not be able to make rejections" do
+ c = Comment.new
+ c.glsa_id = 1
+ c.user = users(:test_padawan)
+ c.text = "test"
+ c.rating = "rejection"
+ c.save
+
+ assert c.errors.any?
+ assert_equal ["You may not approve or reject drafts"], c.errors[:rating]
+ end
+
+ test "advisory owners should not be able to approve their own drafts" do
+ c = Comment.new
+ c.user_id = 1
+ c.text = "test"
+ c.rating = "approval"
+ c.glsa_id = 2
+ c.save
+
+ assert c.errors.any?
+ assert_equal ["The owner of a draft cannot make approvals or rejections"], c.errors[:rating]
+ end
+
+ test "users should not be able to approve a draft twice" do
+ # second comment loaded from fixtures
+ c = Comment.new
+ c.user_id = 7
+ c.text = "test"
+ c.rating = "approval"
+ c.glsa_id = 2
+ c.save
+
+ assert c.errors.any?
+ assert_equal ["You have already approved or rejected this draft"], c.errors[:rating]
end
-end
+end \ No newline at end of file