]> git.openstreetmap.org Git - rails.git/blob - test/controllers/issues_controller_test.rb
DB changes + Related issues added
[rails.git] / test / controllers / issues_controller_test.rb
1 require 'test_helper'
2
3 class IssuesControllerTest < ActionController::TestCase
4   test "should get index" do
5     get :index
6     assert_response :success
7   end
8
9   def test_new_issue
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} }
17     end
18     assert_response :redirect
19   end
20
21   def test_new_report
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} }
29     end
30     assert_response :redirect
31     
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} }
38     end
39     assert_response :redirect
40     assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"IssueOne").reports.count,2
41   end
42
43   def test_change_status
44     # Create Issue
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} }
51     end
52     assert_response :redirect
53
54     # Test 'Resolved'
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
58
59     # Test 'Reopen'
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
63
64     # Test 'Ignored'
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
68   end
69
70 end