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