Allow reporting of anonymous notes
[rails.git] / test / system / issues_test.rb
1 require "application_system_test_case"
2
3 class IssuesTest < ApplicationSystemTestCase
4   include IssuesHelper
5
6   def test_view_issues_normal_user
7     sign_in_as(create(:user))
8
9     visit issues_path
10     assert page.has_content?(I18n.t("application.require_admin.not_an_admin"))
11   end
12
13   def test_view_no_issues
14     sign_in_as(create(:moderator_user))
15
16     visit issues_path
17     assert page.has_content?(I18n.t(".issues.index.issues_not_found"))
18   end
19
20   def test_view_issues
21     sign_in_as(create(:moderator_user))
22     issues = create_list(:issue, 3, :assigned_role => "moderator")
23
24     visit issues_path
25     assert page.has_content?(issues.first.reported_user.display_name)
26   end
27
28   def test_view_issues_with_no_reported_user
29     sign_in_as(create(:moderator_user))
30     anonymous_note = create(:note_with_comments)
31     issue = create(:issue, :reportable => anonymous_note)
32
33     visit issues_path
34     assert page.has_content?(reportable_title(anonymous_note))
35
36     visit issue_path(issue)
37     assert page.has_content?(reportable_title(anonymous_note))
38   end
39
40   def test_search_issues_by_user
41     good_user = create(:user)
42     bad_user = create(:user)
43     create(:issue, :reportable => bad_user, :reported_user => bad_user, :assigned_role => "administrator")
44
45     sign_in_as(create(:administrator_user))
46
47     # No issues against the user
48     visit issues_path
49     fill_in "search_by_user", :with => good_user.display_name
50     click_on "Search"
51     assert page.has_content?(I18n.t(".issues.index.issues_not_found"))
52
53     # User doesn't exist
54     visit issues_path
55     fill_in "search_by_user", :with => "Nonexistant User"
56     click_on "Search"
57     assert page.has_content?(I18n.t(".issues.index.user_not_found"))
58
59     # Find Issue against bad_user
60     visit issues_path
61     fill_in "search_by_user", :with => bad_user.display_name
62     click_on "Search"
63     assert !page.has_content?(I18n.t(".issues.index.issues_not_found"))
64   end
65
66   def test_commenting
67     issue = create(:issue)
68     sign_in_as(create(:moderator_user))
69
70     visit issue_path(issue)
71
72     fill_in :issue_comment_body, :with => "test comment"
73     click_on "Submit"
74     assert page.has_content?(I18n.t(".issues.comment.comment_created"))
75     assert page.has_content?("test comment")
76
77     issue.reload
78     assert_equal issue.comments.first.body, "test comment"
79   end
80
81   def test_reassign_issue
82     issue = create(:issue)
83     assert_equal "administrator", issue.assigned_role
84     sign_in_as(create(:administrator_user))
85
86     visit issue_path(issue)
87
88     fill_in :issue_comment_body, :with => "reassigning to moderators"
89     check :reassign
90     click_on "Submit"
91
92     issue.reload
93     assert_equal "moderator", issue.assigned_role
94   end
95
96   def test_issue_index_with_multiple_roles
97     user1 = create(:user)
98     user2 = create(:user)
99     issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator")
100     issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator")
101
102     user = create(:administrator_user)
103     create(:user_role, :user => user, :role => "moderator")
104     sign_in_as(user)
105
106     visit issues_path
107
108     assert page.has_link?(user1.display_name, :href => issue_path(issue1))
109     assert page.has_link?(user2.display_name, :href => issue_path(issue2))
110   end
111 end