@@ -1,61 +1,101 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | require 'enumerations_controller' | |
|
20 | ||
|
21 | # Re-raise errors caught by the controller. | |
|
22 | class EnumerationsController; def rescue_action(e) raise e end; end | |
|
23 | 19 | |
|
24 | 20 | class EnumerationsControllerTest < ActionController::TestCase |
|
25 | 21 | fixtures :enumerations, :issues, :users |
|
26 | 22 | |
|
27 | 23 | def setup |
|
28 | @controller = EnumerationsController.new | |
|
29 | @request = ActionController::TestRequest.new | |
|
30 | @response = ActionController::TestResponse.new | |
|
31 | 24 | @request.session[:user_id] = 1 # admin |
|
32 | 25 | end |
|
33 | 26 | |
|
34 | 27 | def test_index |
|
35 | 28 | get :index |
|
36 | 29 | assert_response :success |
|
37 | 30 | assert_template 'index' |
|
38 | 31 | end |
|
39 | 32 | |
|
33 | def test_new | |
|
34 | get :new, :type => 'IssuePriority' | |
|
35 | assert_response :success | |
|
36 | assert_template 'new' | |
|
37 | assert_kind_of IssuePriority, assigns(:enumeration) | |
|
38 | end | |
|
39 | ||
|
40 | def test_create | |
|
41 | assert_difference 'IssuePriority.count' do | |
|
42 | post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'} | |
|
43 | end | |
|
44 | assert_redirected_to '/enumerations?type=IssuePriority' | |
|
45 | e = IssuePriority.first(:order => 'id DESC') | |
|
46 | assert_equal 'Lowest', e.name | |
|
47 | end | |
|
48 | ||
|
49 | def test_create_with_failure | |
|
50 | assert_no_difference 'IssuePriority.count' do | |
|
51 | post :create, :enumeration => {:type => 'IssuePriority', :name => ''} | |
|
52 | end | |
|
53 | assert_response :success | |
|
54 | assert_template 'new' | |
|
55 | end | |
|
56 | ||
|
57 | def test_edit | |
|
58 | get :edit, :id => 6 | |
|
59 | assert_response :success | |
|
60 | assert_template 'edit' | |
|
61 | end | |
|
62 | ||
|
63 | def test_update | |
|
64 | assert_no_difference 'IssuePriority.count' do | |
|
65 | post :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'} | |
|
66 | end | |
|
67 | assert_redirected_to '/enumerations?type=IssuePriority' | |
|
68 | e = IssuePriority.find(6) | |
|
69 | assert_equal 'New name', e.name | |
|
70 | end | |
|
71 | ||
|
72 | def test_update_with_failure | |
|
73 | assert_no_difference 'IssuePriority.count' do | |
|
74 | post :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''} | |
|
75 | end | |
|
76 | assert_response :success | |
|
77 | assert_template 'edit' | |
|
78 | end | |
|
79 | ||
|
40 | 80 | def test_destroy_enumeration_not_in_use |
|
41 | 81 | post :destroy, :id => 7 |
|
42 | 82 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
43 | 83 | assert_nil Enumeration.find_by_id(7) |
|
44 | 84 | end |
|
45 | 85 | |
|
46 | 86 | def test_destroy_enumeration_in_use |
|
47 | 87 | post :destroy, :id => 4 |
|
48 | 88 | assert_response :success |
|
49 | 89 | assert_template 'destroy' |
|
50 | 90 | assert_not_nil Enumeration.find_by_id(4) |
|
51 | 91 | end |
|
52 | 92 | |
|
53 | 93 | def test_destroy_enumeration_in_use_with_reassignment |
|
54 | 94 | issue = Issue.find(:first, :conditions => {:priority_id => 4}) |
|
55 | 95 | post :destroy, :id => 4, :reassign_to_id => 6 |
|
56 | 96 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
57 | 97 | assert_nil Enumeration.find_by_id(4) |
|
58 | 98 | # check that the issue was reassign |
|
59 | 99 | assert_equal 6, issue.reload.priority_id |
|
60 | 100 | end |
|
61 | 101 | end |
General Comments 0
You need to be logged in to leave comments.
Login now