Mercurial > hg > soundsoftware-site
comparison test/functional/enumerations_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 | 433d4f72a19b |
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__) |
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 class EnumerationsControllerTest < ActionController::TestCase | 20 class EnumerationsControllerTest < ActionController::TestCase |
25 fixtures :enumerations, :issues, :users | 21 fixtures :enumerations, :issues, :users |
26 | 22 |
27 def setup | 23 def setup |
28 @controller = EnumerationsController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 @request.session[:user_id] = 1 # admin | 24 @request.session[:user_id] = 1 # admin |
32 end | 25 end |
33 | 26 |
34 def test_index | 27 def test_index |
35 get :index | 28 get :index |
36 assert_response :success | 29 assert_response :success |
37 assert_template 'list' | 30 assert_template 'index' |
38 end | 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 def test_destroy_enumeration_not_in_use | 80 def test_destroy_enumeration_not_in_use |
41 post :destroy, :id => 7 | 81 post :destroy, :id => 7 |
42 assert_redirected_to :controller => 'enumerations', :action => 'index' | 82 assert_redirected_to :controller => 'enumerations', :action => 'index' |
43 assert_nil Enumeration.find_by_id(7) | 83 assert_nil Enumeration.find_by_id(7) |
44 end | 84 end |
45 | 85 |
46 def test_destroy_enumeration_in_use | 86 def test_destroy_enumeration_in_use |
47 post :destroy, :id => 4 | 87 post :destroy, :id => 4 |
48 assert_response :success | 88 assert_response :success |
49 assert_template 'destroy' | 89 assert_template 'destroy' |
50 assert_not_nil Enumeration.find_by_id(4) | 90 assert_not_nil Enumeration.find_by_id(4) |
51 end | 91 end |
52 | 92 |
53 def test_destroy_enumeration_in_use_with_reassignment | 93 def test_destroy_enumeration_in_use_with_reassignment |
54 issue = Issue.find(:first, :conditions => {:priority_id => 4}) | 94 issue = Issue.find(:first, :conditions => {:priority_id => 4}) |
55 post :destroy, :id => 4, :reassign_to_id => 6 | 95 post :destroy, :id => 4, :reassign_to_id => 6 |
56 assert_redirected_to :controller => 'enumerations', :action => 'index' | 96 assert_redirected_to :controller => 'enumerations', :action => 'index' |
57 assert_nil Enumeration.find_by_id(4) | 97 assert_nil Enumeration.find_by_id(4) |