Merge branch 'master' into next
[rails.git] / test / models / issue_test.rb
index 7ee700124c7448a84a6bc02fa08a59f66069a6cd..25721295302e28ebdb74e3e1e916ba9b7cc92a8b 100644 (file)
@@ -1,8 +1,17 @@
 require "test_helper"
 
 class IssueTest < ActiveSupport::TestCase
+  def test_assigned_role
+    issue = create(:issue)
+
+    assert issue.valid?
+    issue.assigned_role = "bogus"
+    assert_not issue.valid?
+  end
+
   def test_reported_user
     note = create(:note_comment, :author => create(:user)).note
+    anonymous_note = create(:note_comment, :author => nil).note
     user = create(:user)
     create(:language, :code => "en")
     diary_entry = create(:diary_entry)
@@ -12,13 +21,38 @@ class IssueTest < ActiveSupport::TestCase
     issue.save!
     assert_equal issue.reported_user, user
 
-    # FIXME: doesn't handle anonymous notes
     issue.reportable = note
     issue.save!
     assert_equal issue.reported_user, note.author
 
+    issue.reportable = anonymous_note
+    issue.save!
+    assert_nil issue.reported_user
+
     issue.reportable = diary_entry
     issue.save!
     assert_equal issue.reported_user, diary_entry.user
   end
+
+  def test_default_assigned_role
+    create(:language, :code => "en")
+    diary_entry = create(:diary_entry)
+    note = create(:note_with_comments)
+
+    issue = Issue.new
+    issue.reportable = diary_entry
+    issue.save!
+    assert_equal "administrator", issue.assigned_role
+
+    issue = Issue.new
+    issue.reportable = note
+    issue.save!
+    assert_equal "moderator", issue.assigned_role
+
+    # check the callback doesn't override an explicitly set role
+    issue.assigned_role = "administrator"
+    issue.save!
+    issue.reload
+    assert_equal "administrator", issue.assigned_role
+  end
 end