To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 0a / 0a884b128ca03268f26234e1c96b240bce5a6e1b.svn-base @ 912:5e80956cc792
History | View | Annotate | Download (3.14 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 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_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 | |||
| 80 | def test_destroy_enumeration_not_in_use |
||
| 81 | post :destroy, :id => 7 |
||
| 82 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
||
| 83 | assert_nil Enumeration.find_by_id(7) |
||
| 84 | end |
||
| 85 | |||
| 86 | def test_destroy_enumeration_in_use |
||
| 87 | post :destroy, :id => 4 |
||
| 88 | assert_response :success |
||
| 89 | assert_template 'destroy' |
||
| 90 | assert_not_nil Enumeration.find_by_id(4) |
||
| 91 | end |
||
| 92 | |||
| 93 | def test_destroy_enumeration_in_use_with_reassignment |
||
| 94 | issue = Issue.find(:first, :conditions => {:priority_id => 4})
|
||
| 95 | post :destroy, :id => 4, :reassign_to_id => 6 |
||
| 96 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
||
| 97 | assert_nil Enumeration.find_by_id(4) |
||
| 98 | # check that the issue was reassign |
||
| 99 | assert_equal 6, issue.reload.priority_id |
||
| 100 | end |
||
| 101 | end |