comparison .svn/pristine/dd/dd3fc580b46d142a6812688ff323c2b6855b5a85.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../test_helper', __FILE__)
19
20 class EnumerationsControllerTest < ActionController::TestCase
21 fixtures :enumerations, :issues, :users
22
23 def setup
24 @request.session[:user_id] = 1 # admin
25 end
26
27 def test_index
28 get :index
29 assert_response :success
30 assert_template 'index'
31 end
32
33 def test_index_should_require_admin
34 @request.session[:user_id] = nil
35 get :index
36 assert_response 302
37 end
38
39 def test_new
40 get :new, :type => 'IssuePriority'
41 assert_response :success
42 assert_template 'new'
43 assert_kind_of IssuePriority, assigns(:enumeration)
44 assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'}
45 assert_tag 'input', :attributes => {:name => 'enumeration[name]'}
46 end
47
48 def test_new_with_invalid_type_should_respond_with_404
49 get :new, :type => 'UnknownType'
50 assert_response 404
51 end
52
53 def test_create
54 assert_difference 'IssuePriority.count' do
55 post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'}
56 end
57 assert_redirected_to '/enumerations'
58 e = IssuePriority.find_by_name('Lowest')
59 assert_not_nil e
60 end
61
62 def test_create_with_failure
63 assert_no_difference 'IssuePriority.count' do
64 post :create, :enumeration => {:type => 'IssuePriority', :name => ''}
65 end
66 assert_response :success
67 assert_template 'new'
68 end
69
70 def test_edit
71 get :edit, :id => 6
72 assert_response :success
73 assert_template 'edit'
74 assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'}
75 end
76
77 def test_edit_invalid_should_respond_with_404
78 get :edit, :id => 999
79 assert_response 404
80 end
81
82 def test_update
83 assert_no_difference 'IssuePriority.count' do
84 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
85 end
86 assert_redirected_to '/enumerations'
87 e = IssuePriority.find(6)
88 assert_equal 'New name', e.name
89 end
90
91 def test_update_with_failure
92 assert_no_difference 'IssuePriority.count' do
93 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
94 end
95 assert_response :success
96 assert_template 'edit'
97 end
98
99 def test_destroy_enumeration_not_in_use
100 assert_difference 'IssuePriority.count', -1 do
101 delete :destroy, :id => 7
102 end
103 assert_redirected_to :controller => 'enumerations', :action => 'index'
104 assert_nil Enumeration.find_by_id(7)
105 end
106
107 def test_destroy_enumeration_in_use
108 assert_no_difference 'IssuePriority.count' do
109 delete :destroy, :id => 4
110 end
111 assert_response :success
112 assert_template 'destroy'
113 assert_not_nil Enumeration.find_by_id(4)
114 assert_select 'select[name=reassign_to_id]' do
115 assert_select 'option[value=6]', :text => 'High'
116 end
117 end
118
119 def test_destroy_enumeration_in_use_with_reassignment
120 issue = Issue.where(:priority_id => 4).first
121 assert_difference 'IssuePriority.count', -1 do
122 delete :destroy, :id => 4, :reassign_to_id => 6
123 end
124 assert_redirected_to :controller => 'enumerations', :action => 'index'
125 assert_nil Enumeration.find_by_id(4)
126 # check that the issue was reassign
127 assert_equal 6, issue.reload.priority_id
128 end
129 end