Mercurial > hg > soundsoftware-site
comparison test/functional/enumerations_controller_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 261b3d9a4903 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
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_index_should_require_admin | |
34 @request.session[:user_id] = nil | |
35 get :index | |
36 assert_response 302 | |
37 end | |
38 | |
33 def test_new | 39 def test_new |
34 get :new, :type => 'IssuePriority' | 40 get :new, :type => 'IssuePriority' |
35 assert_response :success | 41 assert_response :success |
36 assert_template 'new' | 42 assert_template 'new' |
37 assert_kind_of IssuePriority, assigns(:enumeration) | 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 | |
38 end | 51 end |
39 | 52 |
40 def test_create | 53 def test_create |
41 assert_difference 'IssuePriority.count' do | 54 assert_difference 'IssuePriority.count' do |
42 post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'} | 55 post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'} |
43 end | 56 end |
44 assert_redirected_to '/enumerations?type=IssuePriority' | 57 assert_redirected_to '/enumerations' |
45 e = IssuePriority.first(:order => 'id DESC') | 58 e = IssuePriority.find_by_name('Lowest') |
46 assert_equal 'Lowest', e.name | 59 assert_not_nil e |
47 end | 60 end |
48 | 61 |
49 def test_create_with_failure | 62 def test_create_with_failure |
50 assert_no_difference 'IssuePriority.count' do | 63 assert_no_difference 'IssuePriority.count' do |
51 post :create, :enumeration => {:type => 'IssuePriority', :name => ''} | 64 post :create, :enumeration => {:type => 'IssuePriority', :name => ''} |
56 | 69 |
57 def test_edit | 70 def test_edit |
58 get :edit, :id => 6 | 71 get :edit, :id => 6 |
59 assert_response :success | 72 assert_response :success |
60 assert_template 'edit' | 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 | |
61 end | 80 end |
62 | 81 |
63 def test_update | 82 def test_update |
64 assert_no_difference 'IssuePriority.count' do | 83 assert_no_difference 'IssuePriority.count' do |
65 post :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'} | 84 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'} |
66 end | 85 end |
67 assert_redirected_to '/enumerations?type=IssuePriority' | 86 assert_redirected_to '/enumerations' |
68 e = IssuePriority.find(6) | 87 e = IssuePriority.find(6) |
69 assert_equal 'New name', e.name | 88 assert_equal 'New name', e.name |
70 end | 89 end |
71 | 90 |
72 def test_update_with_failure | 91 def test_update_with_failure |
73 assert_no_difference 'IssuePriority.count' do | 92 assert_no_difference 'IssuePriority.count' do |
74 post :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''} | 93 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''} |
75 end | 94 end |
76 assert_response :success | 95 assert_response :success |
77 assert_template 'edit' | 96 assert_template 'edit' |
78 end | 97 end |
79 | 98 |
80 def test_destroy_enumeration_not_in_use | 99 def test_destroy_enumeration_not_in_use |
81 post :destroy, :id => 7 | 100 assert_difference 'IssuePriority.count', -1 do |
101 delete :destroy, :id => 7 | |
102 end | |
82 assert_redirected_to :controller => 'enumerations', :action => 'index' | 103 assert_redirected_to :controller => 'enumerations', :action => 'index' |
83 assert_nil Enumeration.find_by_id(7) | 104 assert_nil Enumeration.find_by_id(7) |
84 end | 105 end |
85 | 106 |
86 def test_destroy_enumeration_in_use | 107 def test_destroy_enumeration_in_use |
87 post :destroy, :id => 4 | 108 assert_no_difference 'IssuePriority.count' do |
109 delete :destroy, :id => 4 | |
110 end | |
88 assert_response :success | 111 assert_response :success |
89 assert_template 'destroy' | 112 assert_template 'destroy' |
90 assert_not_nil Enumeration.find_by_id(4) | 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 | |
91 end | 117 end |
92 | 118 |
93 def test_destroy_enumeration_in_use_with_reassignment | 119 def test_destroy_enumeration_in_use_with_reassignment |
94 issue = Issue.find(:first, :conditions => {:priority_id => 4}) | 120 issue = Issue.find(:first, :conditions => {:priority_id => 4}) |
95 post :destroy, :id => 4, :reassign_to_id => 6 | 121 assert_difference 'IssuePriority.count', -1 do |
122 delete :destroy, :id => 4, :reassign_to_id => 6 | |
123 end | |
96 assert_redirected_to :controller => 'enumerations', :action => 'index' | 124 assert_redirected_to :controller => 'enumerations', :action => 'index' |
97 assert_nil Enumeration.find_by_id(4) | 125 assert_nil Enumeration.find_by_id(4) |
98 # check that the issue was reassign | 126 # check that the issue was reassign |
99 assert_equal 6, issue.reload.priority_id | 127 assert_equal 6, issue.reload.priority_id |
100 end | 128 end |