@@ -1,120 +1,120 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 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__) | |
19 |
|
19 | |||
20 | class EnumerationsControllerTest < ActionController::TestCase |
|
20 | class EnumerationsControllerTest < ActionController::TestCase | |
21 | fixtures :enumerations, :issues, :users |
|
21 | fixtures :enumerations, :issues, :users | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | @request.session[:user_id] = 1 # admin |
|
24 | @request.session[:user_id] = 1 # admin | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def test_index |
|
27 | def test_index | |
28 | get :index |
|
28 | get :index | |
29 | assert_response :success |
|
29 | assert_response :success | |
30 | assert_template 'index' |
|
30 | assert_template 'index' | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_new |
|
33 | def test_new | |
34 | get :new, :type => 'IssuePriority' |
|
34 | get :new, :type => 'IssuePriority' | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'new' |
|
36 | assert_template 'new' | |
37 | assert_kind_of IssuePriority, assigns(:enumeration) |
|
37 | assert_kind_of IssuePriority, assigns(:enumeration) | |
38 | assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'} |
|
38 | assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'} | |
39 | assert_tag 'input', :attributes => {:name => 'enumeration[name]'} |
|
39 | assert_tag 'input', :attributes => {:name => 'enumeration[name]'} | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def test_new_with_invalid_type_should_respond_with_404 |
|
42 | def test_new_with_invalid_type_should_respond_with_404 | |
43 | get :new, :type => 'UnknownType' |
|
43 | get :new, :type => 'UnknownType' | |
44 | assert_response 404 |
|
44 | assert_response 404 | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_create |
|
47 | def test_create | |
48 | assert_difference 'IssuePriority.count' do |
|
48 | assert_difference 'IssuePriority.count' do | |
49 | post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'} |
|
49 | post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'} | |
50 | end |
|
50 | end | |
51 | assert_redirected_to '/enumerations?type=IssuePriority' |
|
51 | assert_redirected_to '/enumerations?type=IssuePriority' | |
52 |
e = IssuePriority.fi |
|
52 | e = IssuePriority.find_by_name('Lowest') | |
53 | assert_equal 'Lowest', e.name |
|
53 | assert_not_nil e | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_create_with_failure |
|
56 | def test_create_with_failure | |
57 | assert_no_difference 'IssuePriority.count' do |
|
57 | assert_no_difference 'IssuePriority.count' do | |
58 | post :create, :enumeration => {:type => 'IssuePriority', :name => ''} |
|
58 | post :create, :enumeration => {:type => 'IssuePriority', :name => ''} | |
59 | end |
|
59 | end | |
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'new' |
|
61 | assert_template 'new' | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_edit |
|
64 | def test_edit | |
65 | get :edit, :id => 6 |
|
65 | get :edit, :id => 6 | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'edit' |
|
67 | assert_template 'edit' | |
68 | assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'} |
|
68 | assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'} | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | def test_edit_invalid_should_respond_with_404 |
|
71 | def test_edit_invalid_should_respond_with_404 | |
72 | get :edit, :id => 999 |
|
72 | get :edit, :id => 999 | |
73 | assert_response 404 |
|
73 | assert_response 404 | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def test_update |
|
76 | def test_update | |
77 | assert_no_difference 'IssuePriority.count' do |
|
77 | assert_no_difference 'IssuePriority.count' do | |
78 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'} |
|
78 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'} | |
79 | end |
|
79 | end | |
80 | assert_redirected_to '/enumerations?type=IssuePriority' |
|
80 | assert_redirected_to '/enumerations?type=IssuePriority' | |
81 | e = IssuePriority.find(6) |
|
81 | e = IssuePriority.find(6) | |
82 | assert_equal 'New name', e.name |
|
82 | assert_equal 'New name', e.name | |
83 | end |
|
83 | end | |
84 |
|
84 | |||
85 | def test_update_with_failure |
|
85 | def test_update_with_failure | |
86 | assert_no_difference 'IssuePriority.count' do |
|
86 | assert_no_difference 'IssuePriority.count' do | |
87 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''} |
|
87 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''} | |
88 | end |
|
88 | end | |
89 | assert_response :success |
|
89 | assert_response :success | |
90 | assert_template 'edit' |
|
90 | assert_template 'edit' | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_destroy_enumeration_not_in_use |
|
93 | def test_destroy_enumeration_not_in_use | |
94 | assert_difference 'IssuePriority.count', -1 do |
|
94 | assert_difference 'IssuePriority.count', -1 do | |
95 | delete :destroy, :id => 7 |
|
95 | delete :destroy, :id => 7 | |
96 | end |
|
96 | end | |
97 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
97 | assert_redirected_to :controller => 'enumerations', :action => 'index' | |
98 | assert_nil Enumeration.find_by_id(7) |
|
98 | assert_nil Enumeration.find_by_id(7) | |
99 | end |
|
99 | end | |
100 |
|
100 | |||
101 | def test_destroy_enumeration_in_use |
|
101 | def test_destroy_enumeration_in_use | |
102 | assert_no_difference 'IssuePriority.count' do |
|
102 | assert_no_difference 'IssuePriority.count' do | |
103 | delete :destroy, :id => 4 |
|
103 | delete :destroy, :id => 4 | |
104 | end |
|
104 | end | |
105 | assert_response :success |
|
105 | assert_response :success | |
106 | assert_template 'destroy' |
|
106 | assert_template 'destroy' | |
107 | assert_not_nil Enumeration.find_by_id(4) |
|
107 | assert_not_nil Enumeration.find_by_id(4) | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_destroy_enumeration_in_use_with_reassignment |
|
110 | def test_destroy_enumeration_in_use_with_reassignment | |
111 | issue = Issue.find(:first, :conditions => {:priority_id => 4}) |
|
111 | issue = Issue.find(:first, :conditions => {:priority_id => 4}) | |
112 | assert_difference 'IssuePriority.count', -1 do |
|
112 | assert_difference 'IssuePriority.count', -1 do | |
113 | delete :destroy, :id => 4, :reassign_to_id => 6 |
|
113 | delete :destroy, :id => 4, :reassign_to_id => 6 | |
114 | end |
|
114 | end | |
115 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
115 | assert_redirected_to :controller => 'enumerations', :action => 'index' | |
116 | assert_nil Enumeration.find_by_id(4) |
|
116 | assert_nil Enumeration.find_by_id(4) | |
117 | # check that the issue was reassign |
|
117 | # check that the issue was reassign | |
118 | assert_equal 6, issue.reload.priority_id |
|
118 | assert_equal 6, issue.reload.priority_id | |
119 | end |
|
119 | end | |
120 | end |
|
120 | end |
General Comments 0
You need to be logged in to leave comments.
Login now