Merge branch 'master' into next
[rails.git] / test / models / issue_test.rb
index 49649eede79c5279f9dad1e1d0afdf39d7d1d920..25721295302e28ebdb74e3e1e916ba9b7cc92a8b 100644 (file)
@@ -1,8 +1,17 @@
 require "test_helper"
 
 class IssueTest < ActiveSupport::TestCase
 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
   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)
     user = create(:user)
     create(:language, :code => "en")
     diary_entry = create(:diary_entry)
@@ -12,11 +21,14 @@ class IssueTest < ActiveSupport::TestCase
     issue.save!
     assert_equal issue.reported_user, user
 
     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 = 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
     issue.reportable = diary_entry
     issue.save!
     assert_equal issue.reported_user, diary_entry.user
@@ -25,7 +37,7 @@ class IssueTest < ActiveSupport::TestCase
   def test_default_assigned_role
     create(:language, :code => "en")
     diary_entry = create(:diary_entry)
   def test_default_assigned_role
     create(:language, :code => "en")
     diary_entry = create(:diary_entry)
-    changeset = create(:changeset)
+    note = create(:note_with_comments)
 
     issue = Issue.new
     issue.reportable = diary_entry
 
     issue = Issue.new
     issue.reportable = diary_entry
@@ -33,7 +45,7 @@ class IssueTest < ActiveSupport::TestCase
     assert_equal "administrator", issue.assigned_role
 
     issue = Issue.new
     assert_equal "administrator", issue.assigned_role
 
     issue = Issue.new
-    issue.reportable = changeset
+    issue.reportable = note
     issue.save!
     assert_equal "moderator", issue.assigned_role
 
     issue.save!
     assert_equal "moderator", issue.assigned_role