To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 9a / 9a6d307936e0e3f18679eabcd2eab7934463b58c.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (3.9 KB)

1
# 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
require 'issue_categories_controller'
20

    
21
# Re-raise errors caught by the controller.
22
class IssueCategoriesController; def rescue_action(e) raise e end; end
23

    
24
class IssueCategoriesControllerTest < ActionController::TestCase
25
  fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories
26

    
27
  def setup
28
    @controller = IssueCategoriesController.new
29
    @request    = ActionController::TestRequest.new
30
    @response   = ActionController::TestResponse.new
31
    User.current = nil
32
    @request.session[:user_id] = 2
33
  end
34

    
35
  def test_new
36
    @request.session[:user_id] = 2 # manager
37
    get :new, :project_id => '1'
38
    assert_response :success
39
    assert_template 'new'
40
  end
41

    
42
  def test_create
43
    @request.session[:user_id] = 2 # manager
44
    assert_difference 'IssueCategory.count' do
45
      post :create, :project_id => '1', :issue_category => {:name => 'New category'}
46
    end
47
    assert_redirected_to '/projects/ecookbook/settings/categories'
48
    category = IssueCategory.find_by_name('New category')
49
    assert_not_nil category
50
    assert_equal 1, category.project_id
51
  end
52

    
53
  def test_create_failure
54
    @request.session[:user_id] = 2
55
    post :create, :project_id => '1', :issue_category => {:name => ''}
56
    assert_response :success
57
    assert_template 'new'
58
  end
59

    
60
  def test_edit
61
    @request.session[:user_id] = 2
62
    get :edit, :id => 2
63
    assert_response :success
64
    assert_template 'edit'
65
  end
66

    
67
  def test_update
68
    assert_no_difference 'IssueCategory.count' do
69
      put :update, :id => 2, :issue_category => { :name => 'Testing' }
70
    end
71
    assert_redirected_to '/projects/ecookbook/settings/categories'
72
    assert_equal 'Testing', IssueCategory.find(2).name
73
  end
74

    
75
  def test_update_failure
76
    put :update, :id => 2, :issue_category => { :name => '' }
77
    assert_response :success
78
    assert_template 'edit'
79
  end
80

    
81
  def test_update_not_found
82
    put :update, :id => 97, :issue_category => { :name => 'Testing' }
83
    assert_response 404
84
  end
85

    
86
  def test_destroy_category_not_in_use
87
    delete :destroy, :id => 2
88
    assert_redirected_to '/projects/ecookbook/settings/categories'
89
    assert_nil IssueCategory.find_by_id(2)
90
  end
91

    
92
  def test_destroy_category_in_use
93
    delete :destroy, :id => 1
94
    assert_response :success
95
    assert_template 'destroy'
96
    assert_not_nil IssueCategory.find_by_id(1)
97
  end
98

    
99
  def test_destroy_category_in_use_with_reassignment
100
    issue = Issue.find(:first, :conditions => {:category_id => 1})
101
    delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
102
    assert_redirected_to '/projects/ecookbook/settings/categories'
103
    assert_nil IssueCategory.find_by_id(1)
104
    # check that the issue was reassign
105
    assert_equal 2, issue.reload.category_id
106
  end
107

    
108
  def test_destroy_category_in_use_without_reassignment
109
    issue = Issue.find(:first, :conditions => {:category_id => 1})
110
    delete :destroy, :id => 1, :todo => 'nullify'
111
    assert_redirected_to '/projects/ecookbook/settings/categories'
112
    assert_nil IssueCategory.find_by_id(1)
113
    # check that the issue category was nullified
114
    assert_nil issue.reload.category_id
115
  end
116
end