3 class IssuesControllerTest < ActionController::TestCase
4 test "should get index" do
6 assert_response :success
10 # Test creation of a new issue and a new report
11 get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
12 assert_response :success
13 assert_difference "Issue.count",1 do
14 details = "Details of a report"
15 post :create, { :report => { :deatils => details},
16 :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
18 assert_response :redirect
22 # Test creation of a new report for an existing issue
23 get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
24 assert_response :success
25 assert_difference "Issue.count",1 do
26 details = "Details of a report"
27 post :create, { :report => { :details => details},
28 :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
30 assert_response :redirect
32 get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
33 assert_response :success
34 assert_no_difference "Issue.count" do
35 details = "Details of another report under the same issue"
36 post :create, { :report => { :details => details},
37 :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
39 assert_response :redirect
40 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").reports.count,2
43 def test_change_status
45 get :new, {reportable_id: 1, reportable_type: "IssueOne", user: 1}
46 assert_response :success
47 assert_difference "Issue.count",1 do
48 details = "Details of a report"
49 post :create, { :report => { :deatils => details},
50 :issue => { reportable_id: 1, reportable_type: "IssueOne", user: 1} }
52 assert_response :redirect
55 get :resolve, id: Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").id
56 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").resolved?, true
57 assert_response :redirect
60 get :reopen, id: Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").id
61 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").open?, true
62 assert_response :redirect
65 get :ignore, id: Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").id
66 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").ignored?, true
67 assert_response :redirect