25721295302e28ebdb74e3e1e916ba9b7cc92a8b
[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     note = create(:note_comment, :author => create(:user)).note
14     anonymous_note = create(:note_comment, :author => nil).note
15     user = create(:user)
16     create(:language, :code => "en")
17     diary_entry = create(:diary_entry)
18     issue = Issue.new
19
20     issue.reportable = user
21     issue.save!
22     assert_equal issue.reported_user, user
23
24     issue.reportable = note
25     issue.save!
26     assert_equal issue.reported_user, note.author
27
28     issue.reportable = anonymous_note
29     issue.save!
30     assert_nil issue.reported_user
31
32     issue.reportable = diary_entry
33     issue.save!
34     assert_equal issue.reported_user, diary_entry.user
35   end
36
37   def test_default_assigned_role
38     create(:language, :code => "en")
39     diary_entry = create(:diary_entry)
40     note = create(:note_with_comments)
41
42     issue = Issue.new
43     issue.reportable = diary_entry
44     issue.save!
45     assert_equal "administrator", issue.assigned_role
46
47     issue = Issue.new
48     issue.reportable = note
49     issue.save!
50     assert_equal "moderator", issue.assigned_role
51
52     # check the callback doesn't override an explicitly set role
53     issue.assigned_role = "administrator"
54     issue.save!
55     issue.reload
56     assert_equal "administrator", issue.assigned_role
57   end
58 end