3 class IssuesControllerTest < ActionController::TestCase
5 # cleanup any emails set off by the test
6 ActionMailer::Base.deliveries.clear
9 def test_view_dashboard_without_auth
10 # Access issues_path without login
12 assert_response :redirect
13 assert_redirected_to login_path(:referer => issues_path)
15 # Access issues_path as normal user
16 session[:user] = create(:user).id
18 assert_response :redirect
19 assert_redirected_to root_path
21 # Access issues_path by admin
22 session[:user] = create(:administrator_user).id
24 assert_response :success
26 # Access issues_path by moderator
27 session[:user] = create(:moderator_user).id
29 assert_response :success
32 def test_change_status_by_normal_user
33 target_user = create(:user)
34 issue = create(:issue, :reportable => target_user, :reported_user => target_user)
36 # Login as normal user
37 session[:user] = create(:user).id
39 assert_equal 1, Issue.count
41 get :resolve, :params => { :id => issue.id }
43 assert_response :redirect
44 assert_redirected_to root_path
47 def test_change_status_by_admin
48 target_user = create(:user)
49 issue = create(:issue, :reportable => target_user, :reported_user => target_user)
51 # Login as administrator
52 session[:user] = create(:administrator_user).id
55 get :resolve, :params => { :id => issue.id }
56 assert_equal true, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").resolved?
57 assert_response :redirect
60 get :reopen, :params => { :id => issue.id }
61 assert_equal true, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").open?
62 assert_response :redirect
65 get :ignore, :params => { :id => issue.id }
66 assert_equal true, Issue.find_by(:reportable_id => target_user, :reportable_type => "User").ignored?
67 assert_response :redirect
70 def test_search_issues
71 good_user = create(:user)
72 bad_user = create(:user)
73 create(:issue, :reportable => bad_user, :reported_user => bad_user, :issue_type => "administrator")
74 # Login as administrator
75 session[:user] = create(:administrator_user).id
77 # No issues against the user
78 get :index, :params => { :search_by_user => good_user.display_name }
79 assert_response :redirect
80 assert_redirected_to issues_path
83 get :index, :params => { :search_by_user => "test1000" }
84 assert_response :redirect
85 assert_redirected_to issues_path
87 # Find Issue against bad_user
88 get :index, :params => { :search_by_user => bad_user.display_name }
89 assert_response :success