Chris@0
|
1 # Redmine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 require File.dirname(__FILE__) + '/../test_helper'
|
Chris@0
|
19 require 'trackers_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class TrackersController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class TrackersControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields
|
Chris@0
|
26
|
Chris@0
|
27 def setup
|
Chris@0
|
28 @controller = TrackersController.new
|
Chris@0
|
29 @request = ActionController::TestRequest.new
|
Chris@0
|
30 @response = ActionController::TestResponse.new
|
Chris@0
|
31 User.current = nil
|
Chris@0
|
32 @request.session[:user_id] = 1 # admin
|
Chris@0
|
33 end
|
Chris@0
|
34
|
Chris@0
|
35 def test_index
|
Chris@0
|
36 get :index
|
Chris@0
|
37 assert_response :success
|
Chris@0
|
38 assert_template 'index'
|
Chris@0
|
39 end
|
Chris@0
|
40
|
Chris@0
|
41 def test_get_new
|
Chris@0
|
42 get :new
|
Chris@0
|
43 assert_response :success
|
Chris@0
|
44 assert_template 'new'
|
Chris@0
|
45 end
|
Chris@0
|
46
|
Chris@0
|
47 def test_post_new
|
Chris@0
|
48 post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
|
Chris@0
|
49 assert_redirected_to :action => 'index'
|
Chris@0
|
50 tracker = Tracker.find_by_name('New tracker')
|
Chris@0
|
51 assert_equal [1], tracker.project_ids.sort
|
Chris@0
|
52 assert_equal [1, 6], tracker.custom_field_ids
|
Chris@0
|
53 assert_equal 0, tracker.workflows.count
|
Chris@0
|
54 end
|
Chris@0
|
55
|
Chris@0
|
56 def test_post_new_with_workflow_copy
|
Chris@0
|
57 post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
|
Chris@0
|
58 assert_redirected_to :action => 'index'
|
Chris@0
|
59 tracker = Tracker.find_by_name('New tracker')
|
Chris@0
|
60 assert_equal 0, tracker.projects.count
|
Chris@0
|
61 assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
|
Chris@0
|
62 end
|
Chris@0
|
63
|
Chris@0
|
64 def test_get_edit
|
Chris@0
|
65 Tracker.find(1).project_ids = [1, 3]
|
Chris@0
|
66
|
Chris@0
|
67 get :edit, :id => 1
|
Chris@0
|
68 assert_response :success
|
Chris@0
|
69 assert_template 'edit'
|
Chris@0
|
70
|
Chris@0
|
71 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
|
Chris@0
|
72 :value => '1',
|
Chris@0
|
73 :checked => 'checked' }
|
Chris@0
|
74
|
Chris@0
|
75 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
|
Chris@0
|
76 :value => '2',
|
Chris@0
|
77 :checked => nil }
|
Chris@0
|
78
|
Chris@0
|
79 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
|
Chris@0
|
80 :value => '',
|
Chris@0
|
81 :type => 'hidden'}
|
Chris@0
|
82 end
|
Chris@0
|
83
|
Chris@0
|
84 def test_post_edit
|
Chris@0
|
85 post :edit, :id => 1, :tracker => { :name => 'Renamed',
|
Chris@0
|
86 :project_ids => ['1', '2', ''] }
|
Chris@0
|
87 assert_redirected_to :action => 'index'
|
Chris@0
|
88 assert_equal [1, 2], Tracker.find(1).project_ids.sort
|
Chris@0
|
89 end
|
Chris@0
|
90
|
Chris@0
|
91 def test_post_edit_without_projects
|
Chris@0
|
92 post :edit, :id => 1, :tracker => { :name => 'Renamed',
|
Chris@0
|
93 :project_ids => [''] }
|
Chris@0
|
94 assert_redirected_to :action => 'index'
|
Chris@0
|
95 assert Tracker.find(1).project_ids.empty?
|
Chris@0
|
96 end
|
Chris@0
|
97
|
Chris@0
|
98 def test_move_lower
|
Chris@0
|
99 tracker = Tracker.find_by_position(1)
|
Chris@0
|
100 post :edit, :id => 1, :tracker => { :move_to => 'lower' }
|
Chris@0
|
101 assert_equal 2, tracker.reload.position
|
Chris@0
|
102 end
|
Chris@0
|
103
|
Chris@0
|
104 def test_destroy
|
Chris@0
|
105 tracker = Tracker.create!(:name => 'Destroyable')
|
Chris@0
|
106 assert_difference 'Tracker.count', -1 do
|
Chris@0
|
107 post :destroy, :id => tracker.id
|
Chris@0
|
108 end
|
Chris@0
|
109 assert_redirected_to :action => 'index'
|
Chris@0
|
110 assert_nil flash[:error]
|
Chris@0
|
111 end
|
Chris@0
|
112
|
Chris@0
|
113 def test_destroy_tracker_in_use
|
Chris@0
|
114 assert_no_difference 'Tracker.count' do
|
Chris@0
|
115 post :destroy, :id => 1
|
Chris@0
|
116 end
|
Chris@0
|
117 assert_redirected_to :action => 'index'
|
Chris@0
|
118 assert_not_nil flash[:error]
|
Chris@0
|
119 end
|
Chris@0
|
120 end
|