Improve model tests for issues
[rails.git] / test / models / issue_test.rb
1 require "test_helper"
2
3 class IssueTest < ActiveSupport::TestCase
4   def test_assigned_role
5     issue = create(:issue)
6
7     assert issue.valid?
8     issue.assigned_role = "bogus"
9     assert_not issue.valid?
10   end
11
12   def test_reported_user
13     create(:language, :code => "en")
14     user = create(:user)
15     note = create(:note_comment, :author => create(:user)).note
16     anonymous_note = create(:note_comment, :author => nil).note
17     diary_entry = create(:diary_entry)
18     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
19
20     issue = Issue.new(:reportable => user)
21     issue.save!
22     assert_equal issue.reported_user, user
23
24     issue = Issue.new(:reportable => note)
25     issue.save!
26     assert_equal issue.reported_user, note.author
27
28     issue = Issue.new(:reportable => anonymous_note)
29     issue.save!
30     assert_nil issue.reported_user
31
32     issue = Issue.new(:reportable => diary_entry)
33     issue.save!
34     assert_equal issue.reported_user, diary_entry.user
35
36     issue = Issue.new(:reportable => diary_comment)
37     issue.save!
38     assert_equal issue.reported_user, diary_comment.user
39   end
40
41   def test_default_assigned_role
42     create(:language, :code => "en")
43     user = create(:user)
44     note = create(:note_with_comments)
45     diary_entry = create(:diary_entry)
46     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
47
48     issue = Issue.new(:reportable => user)
49     issue.save!
50     assert_equal "administrator", issue.assigned_role
51
52     issue = Issue.new(:reportable => note)
53     issue.save!
54     assert_equal "moderator", issue.assigned_role
55
56     issue = Issue.new(:reportable => diary_entry)
57     issue.save!
58     assert_equal "administrator", issue.assigned_role
59
60     issue = Issue.new(:reportable => diary_comment)
61     issue.save!
62     assert_equal "administrator", issue.assigned_role
63   end
64
65   def test_no_default_explicit_role
66     create(:language, :code => "en")
67     user = create(:user)
68     note = create(:note_with_comments)
69     diary_entry = create(:diary_entry)
70     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
71
72     issue = Issue.new(:reportable => user, :assigned_role => "moderator")
73     issue.save!
74     assert_equal "moderator", issue.reload.assigned_role
75
76     issue = Issue.new(:reportable => note, :assigned_role => "administrator")
77     issue.save!
78     assert_equal "administrator", issue.reload.assigned_role
79
80     issue = Issue.new(:reportable => diary_entry, :assigned_role => "moderator")
81     issue.save!
82     assert_equal "moderator", issue.reload.assigned_role
83
84     issue = Issue.new(:reportable => diary_comment, :assigned_role => "moderator")
85     issue.save!
86     assert_equal "moderator", issue.reload.assigned_role
87   end
88 end