Rename 'issue_type' to 'assigned_role', set defaults in the model and test.
[rails.git] / test / models / issue_test.rb
index 7ee700124c7448a84a6bc02fa08a59f66069a6cd..49649eede79c5279f9dad1e1d0afdf39d7d1d920 100644 (file)
@@ -21,4 +21,26 @@ class IssueTest < ActiveSupport::TestCase
     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)
+    changeset = create(:changeset)
+
+    issue = Issue.new
+    issue.reportable = diary_entry
+    issue.save!
+    assert_equal "administrator", issue.assigned_role
+
+    issue = Issue.new
+    issue.reportable = changeset
+    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