Mercurial > hg > soundsoftware-site
comparison test/functional/trackers_controller_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 8661b858af72 |
children | 5f33065ddc4b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2009 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
21 # Re-raise errors caught by the controller. | 21 # Re-raise errors caught by the controller. |
22 class TrackersController; def rescue_action(e) raise e end; end | 22 class TrackersController; def rescue_action(e) raise e end; end |
23 | 23 |
24 class TrackersControllerTest < ActionController::TestCase | 24 class TrackersControllerTest < ActionController::TestCase |
25 fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields | 25 fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields |
26 | 26 |
27 def setup | 27 def setup |
28 @controller = TrackersController.new | 28 @controller = TrackersController.new |
29 @request = ActionController::TestRequest.new | 29 @request = ActionController::TestRequest.new |
30 @response = ActionController::TestResponse.new | 30 @response = ActionController::TestResponse.new |
31 User.current = nil | 31 User.current = nil |
32 @request.session[:user_id] = 1 # admin | 32 @request.session[:user_id] = 1 # admin |
33 end | 33 end |
34 | 34 |
35 def test_index | 35 def test_index |
36 get :index | 36 get :index |
37 assert_response :success | 37 assert_response :success |
38 assert_template 'index' | 38 assert_template 'index' |
39 end | 39 end |
40 | 40 |
41 def test_get_new | 41 def test_index_by_anonymous_should_redirect_to_login_form |
42 @request.session[:user_id] = nil | |
43 get :index | |
44 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftrackers' | |
45 end | |
46 | |
47 def test_index_by_user_should_respond_with_406 | |
48 @request.session[:user_id] = 2 | |
49 get :index | |
50 assert_response 406 | |
51 end | |
52 | |
53 def test_new | |
42 get :new | 54 get :new |
43 assert_response :success | 55 assert_response :success |
44 assert_template 'new' | 56 assert_template 'new' |
45 end | 57 end |
46 | 58 |
47 def test_post_new | 59 def test_create |
48 post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } | 60 assert_difference 'Tracker.count' do |
61 post :create, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } | |
62 end | |
49 assert_redirected_to :action => 'index' | 63 assert_redirected_to :action => 'index' |
50 tracker = Tracker.find_by_name('New tracker') | 64 tracker = Tracker.first(:order => 'id DESC') |
65 assert_equal 'New tracker', tracker.name | |
51 assert_equal [1], tracker.project_ids.sort | 66 assert_equal [1], tracker.project_ids.sort |
52 assert_equal [1, 6], tracker.custom_field_ids | 67 assert_equal [1, 6], tracker.custom_field_ids |
53 assert_equal 0, tracker.workflows.count | 68 assert_equal 0, tracker.workflows.count |
54 end | 69 end |
55 | 70 |
56 def test_post_new_with_workflow_copy | 71 def test_create_new_with_workflow_copy |
57 post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 | 72 assert_difference 'Tracker.count' do |
73 post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 | |
74 end | |
58 assert_redirected_to :action => 'index' | 75 assert_redirected_to :action => 'index' |
59 tracker = Tracker.find_by_name('New tracker') | 76 tracker = Tracker.find_by_name('New tracker') |
60 assert_equal 0, tracker.projects.count | 77 assert_equal 0, tracker.projects.count |
61 assert_equal Tracker.find(1).workflows.count, tracker.workflows.count | 78 assert_equal Tracker.find(1).workflows.count, tracker.workflows.count |
62 end | 79 end |
63 | 80 |
64 def test_get_edit | 81 def test_create_new_failure |
82 assert_no_difference 'Tracker.count' do | |
83 post :create, :tracker => { :name => '', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } | |
84 end | |
85 assert_response :success | |
86 assert_template 'new' | |
87 end | |
88 | |
89 def test_edit | |
65 Tracker.find(1).project_ids = [1, 3] | 90 Tracker.find(1).project_ids = [1, 3] |
66 | 91 |
67 get :edit, :id => 1 | 92 get :edit, :id => 1 |
68 assert_response :success | 93 assert_response :success |
69 assert_template 'edit' | 94 assert_template 'edit' |
70 | 95 |
71 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', | 96 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
72 :value => '1', | 97 :value => '1', |
73 :checked => 'checked' } | 98 :checked => 'checked' } |
74 | 99 |
75 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', | 100 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
76 :value => '2', | 101 :value => '2', |
77 :checked => nil } | 102 :checked => nil } |
78 | 103 |
79 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', | 104 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
80 :value => '', | 105 :value => '', |
81 :type => 'hidden'} | 106 :type => 'hidden'} |
82 end | 107 end |
83 | 108 |
84 def test_post_edit | 109 def test_update |
85 post :edit, :id => 1, :tracker => { :name => 'Renamed', | 110 put :update, :id => 1, :tracker => { :name => 'Renamed', |
86 :project_ids => ['1', '2', ''] } | 111 :project_ids => ['1', '2', ''] } |
87 assert_redirected_to :action => 'index' | 112 assert_redirected_to :action => 'index' |
88 assert_equal [1, 2], Tracker.find(1).project_ids.sort | 113 assert_equal [1, 2], Tracker.find(1).project_ids.sort |
89 end | 114 end |
90 | 115 |
91 def test_post_edit_without_projects | 116 def test_update_without_projects |
92 post :edit, :id => 1, :tracker => { :name => 'Renamed', | 117 put :update, :id => 1, :tracker => { :name => 'Renamed', |
93 :project_ids => [''] } | 118 :project_ids => [''] } |
94 assert_redirected_to :action => 'index' | 119 assert_redirected_to :action => 'index' |
95 assert Tracker.find(1).project_ids.empty? | 120 assert Tracker.find(1).project_ids.empty? |
96 end | 121 end |
97 | 122 |
98 def test_move_lower | 123 def test_move_lower |
99 tracker = Tracker.find_by_position(1) | 124 tracker = Tracker.find_by_position(1) |
100 post :edit, :id => 1, :tracker => { :move_to => 'lower' } | 125 put :update, :id => 1, :tracker => { :move_to => 'lower' } |
101 assert_equal 2, tracker.reload.position | 126 assert_equal 2, tracker.reload.position |
102 end | 127 end |
103 | 128 |
104 def test_destroy | 129 def test_destroy |
105 tracker = Tracker.create!(:name => 'Destroyable') | 130 tracker = Tracker.create!(:name => 'Destroyable') |
106 assert_difference 'Tracker.count', -1 do | 131 assert_difference 'Tracker.count', -1 do |
107 post :destroy, :id => tracker.id | 132 delete :destroy, :id => tracker.id |
108 end | 133 end |
109 assert_redirected_to :action => 'index' | 134 assert_redirected_to :action => 'index' |
110 assert_nil flash[:error] | 135 assert_nil flash[:error] |
111 end | 136 end |
112 | 137 |
113 def test_destroy_tracker_in_use | 138 def test_destroy_tracker_in_use |
114 assert_no_difference 'Tracker.count' do | 139 assert_no_difference 'Tracker.count' do |
115 post :destroy, :id => 1 | 140 delete :destroy, :id => 1 |
116 end | 141 end |
117 assert_redirected_to :action => 'index' | 142 assert_redirected_to :action => 'index' |
118 assert_not_nil flash[:error] | 143 assert_not_nil flash[:error] |
119 end | 144 end |
120 end | 145 end |