##// END OF EJS Templates
Rails 3.1 compatibility....
Jean-Philippe Lang -
r8962:7ec8a9a1009f
parent child
Show More
@@ -1,143 +1,143
1 require File.expand_path('../../test_helper', __FILE__)
1 require File.expand_path('../../test_helper', __FILE__)
2
2
3 class ActivitiesControllerTest < ActionController::TestCase
3 class ActivitiesControllerTest < ActionController::TestCase
4 fixtures :projects, :trackers, :issue_statuses, :issues,
4 fixtures :projects, :trackers, :issue_statuses, :issues,
5 :enumerations, :users, :issue_categories,
5 :enumerations, :users, :issue_categories,
6 :projects_trackers,
6 :projects_trackers,
7 :roles,
7 :roles,
8 :member_roles,
8 :member_roles,
9 :members,
9 :members,
10 :groups_users,
10 :groups_users,
11 :enabled_modules,
11 :enabled_modules,
12 :workflows,
12 :workflows,
13 :journals, :journal_details
13 :journals, :journal_details
14
14
15
15
16 def test_project_index
16 def test_project_index
17 get :index, :id => 1, :with_subprojects => 0
17 get :index, :id => 1, :with_subprojects => 0
18 assert_response :success
18 assert_response :success
19 assert_template 'index'
19 assert_template 'index'
20 assert_not_nil assigns(:events_by_day)
20 assert_not_nil assigns(:events_by_day)
21
21
22 assert_tag :tag => "h3",
22 assert_tag :tag => "h3",
23 :content => /#{2.days.ago.to_date.day}/,
23 :content => /#{2.days.ago.to_date.day}/,
24 :sibling => { :tag => "dl",
24 :sibling => { :tag => "dl",
25 :child => { :tag => "dt",
25 :child => { :tag => "dt",
26 :attributes => { :class => /issue-edit/ },
26 :attributes => { :class => /issue-edit/ },
27 :child => { :tag => "a",
27 :child => { :tag => "a",
28 :content => /(#{IssueStatus.find(2).name})/,
28 :content => /(#{IssueStatus.find(2).name})/,
29 }
29 }
30 }
30 }
31 }
31 }
32 end
32 end
33
33
34 def test_project_index_with_invalid_project_id_should_respond_404
34 def test_project_index_with_invalid_project_id_should_respond_404
35 get :index, :id => 299
35 get :index, :id => 299
36 assert_response 404
36 assert_response 404
37 end
37 end
38
38
39 def test_previous_project_index
39 def test_previous_project_index
40 get :index, :id => 1, :from => 3.days.ago.to_date
40 get :index, :id => 1, :from => 3.days.ago.to_date
41 assert_response :success
41 assert_response :success
42 assert_template 'index'
42 assert_template 'index'
43 assert_not_nil assigns(:events_by_day)
43 assert_not_nil assigns(:events_by_day)
44
44
45 assert_tag :tag => "h3",
45 assert_tag :tag => "h3",
46 :content => /#{3.day.ago.to_date.day}/,
46 :content => /#{3.day.ago.to_date.day}/,
47 :sibling => { :tag => "dl",
47 :sibling => { :tag => "dl",
48 :child => { :tag => "dt",
48 :child => { :tag => "dt",
49 :attributes => { :class => /issue/ },
49 :attributes => { :class => /issue/ },
50 :child => { :tag => "a",
50 :child => { :tag => "a",
51 :content => /#{Issue.find(1).subject}/,
51 :content => /#{Issue.find(1).subject}/,
52 }
52 }
53 }
53 }
54 }
54 }
55 end
55 end
56
56
57 def test_global_index
57 def test_global_index
58 get :index
58 get :index
59 assert_response :success
59 assert_response :success
60 assert_template 'index'
60 assert_template 'index'
61 assert_not_nil assigns(:events_by_day)
61 assert_not_nil assigns(:events_by_day)
62
62
63 assert_tag :tag => "h3",
63 assert_tag :tag => "h3",
64 :content => /#{5.day.ago.to_date.day}/,
64 :content => /#{5.day.ago.to_date.day}/,
65 :sibling => { :tag => "dl",
65 :sibling => { :tag => "dl",
66 :child => { :tag => "dt",
66 :child => { :tag => "dt",
67 :attributes => { :class => /issue/ },
67 :attributes => { :class => /issue/ },
68 :child => { :tag => "a",
68 :child => { :tag => "a",
69 :content => /#{Issue.find(5).subject}/,
69 :content => /#{Issue.find(5).subject}/,
70 }
70 }
71 }
71 }
72 }
72 }
73 end
73 end
74
74
75 def test_user_index
75 def test_user_index
76 get :index, :user_id => 2
76 get :index, :user_id => 2
77 assert_response :success
77 assert_response :success
78 assert_template 'index'
78 assert_template 'index'
79 assert_not_nil assigns(:events_by_day)
79 assert_not_nil assigns(:events_by_day)
80
80
81 assert_tag :tag => "h3",
81 assert_tag :tag => "h3",
82 :content => /#{3.day.ago.to_date.day}/,
82 :content => /#{3.day.ago.to_date.day}/,
83 :sibling => { :tag => "dl",
83 :sibling => { :tag => "dl",
84 :child => { :tag => "dt",
84 :child => { :tag => "dt",
85 :attributes => { :class => /issue/ },
85 :attributes => { :class => /issue/ },
86 :child => { :tag => "a",
86 :child => { :tag => "a",
87 :content => /#{Issue.find(1).subject}/,
87 :content => /#{Issue.find(1).subject}/,
88 }
88 }
89 }
89 }
90 }
90 }
91 end
91 end
92
92
93 def test_user_index_with_invalid_user_id_should_respond_404
93 def test_user_index_with_invalid_user_id_should_respond_404
94 get :index, :user_id => 299
94 get :index, :user_id => 299
95 assert_response 404
95 assert_response 404
96 end
96 end
97
97
98 def test_index_atom_feed
98 def test_index_atom_feed
99 get :index, :format => 'atom', :with_subprojects => 0
99 get :index, :format => 'atom', :with_subprojects => 0
100 assert_response :success
100 assert_response :success
101 assert_template 'common/feed.atom'
101 assert_template 'common/feed'
102
102
103 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
103 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
104 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
104 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
105 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
105 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
106 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
106 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
107
107
108 assert_tag :tag => 'entry', :child => {
108 assert_tag :tag => 'entry', :child => {
109 :tag => 'link',
109 :tag => 'link',
110 :attributes => {:href => 'http://test.host/issues/11'}}
110 :attributes => {:href => 'http://test.host/issues/11'}}
111 end
111 end
112
112
113 def test_index_atom_feed_with_explicit_selection
113 def test_index_atom_feed_with_explicit_selection
114 get :index, :format => 'atom', :with_subprojects => 0,
114 get :index, :format => 'atom', :with_subprojects => 0,
115 :show_changesets => 1,
115 :show_changesets => 1,
116 :show_documents => 1,
116 :show_documents => 1,
117 :show_files => 1,
117 :show_files => 1,
118 :show_issues => 1,
118 :show_issues => 1,
119 :show_messages => 1,
119 :show_messages => 1,
120 :show_news => 1,
120 :show_news => 1,
121 :show_time_entries => 1,
121 :show_time_entries => 1,
122 :show_wiki_edits => 1
122 :show_wiki_edits => 1
123
123
124 assert_response :success
124 assert_response :success
125 assert_template 'common/feed.atom'
125 assert_template 'common/feed'
126
126
127 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
127 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
128 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
128 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
129 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
129 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
130 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
130 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
131
131
132 assert_tag :tag => 'entry', :child => {
132 assert_tag :tag => 'entry', :child => {
133 :tag => 'link',
133 :tag => 'link',
134 :attributes => {:href => 'http://test.host/issues/11'}}
134 :attributes => {:href => 'http://test.host/issues/11'}}
135 end
135 end
136
136
137 def test_index_atom_feed_with_one_item_type
137 def test_index_atom_feed_with_one_item_type
138 get :index, :format => 'atom', :show_issues => '1'
138 get :index, :format => 'atom', :show_issues => '1'
139 assert_response :success
139 assert_response :success
140 assert_template 'common/feed.atom'
140 assert_template 'common/feed'
141 assert_tag :tag => 'title', :content => /Issues/
141 assert_tag :tag => 'title', :content => /Issues/
142 end
142 end
143 end
143 end
@@ -1,140 +1,140
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 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
19
20 class BoardsControllerTest < ActionController::TestCase
20 class BoardsControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
22
22
23 def setup
23 def setup
24 User.current = nil
24 User.current = nil
25 end
25 end
26
26
27 def test_index
27 def test_index
28 get :index, :project_id => 1
28 get :index, :project_id => 1
29 assert_response :success
29 assert_response :success
30 assert_template 'index'
30 assert_template 'index'
31 assert_not_nil assigns(:boards)
31 assert_not_nil assigns(:boards)
32 assert_not_nil assigns(:project)
32 assert_not_nil assigns(:project)
33 end
33 end
34
34
35 def test_index_not_found
35 def test_index_not_found
36 get :index, :project_id => 97
36 get :index, :project_id => 97
37 assert_response 404
37 assert_response 404
38 end
38 end
39
39
40 def test_index_should_show_messages_if_only_one_board
40 def test_index_should_show_messages_if_only_one_board
41 Project.find(1).boards.slice(1..-1).each(&:destroy)
41 Project.find(1).boards.slice(1..-1).each(&:destroy)
42
42
43 get :index, :project_id => 1
43 get :index, :project_id => 1
44 assert_response :success
44 assert_response :success
45 assert_template 'show'
45 assert_template 'show'
46 assert_not_nil assigns(:topics)
46 assert_not_nil assigns(:topics)
47 end
47 end
48
48
49 def test_show
49 def test_show
50 get :show, :project_id => 1, :id => 1
50 get :show, :project_id => 1, :id => 1
51 assert_response :success
51 assert_response :success
52 assert_template 'show'
52 assert_template 'show'
53 assert_not_nil assigns(:board)
53 assert_not_nil assigns(:board)
54 assert_not_nil assigns(:project)
54 assert_not_nil assigns(:project)
55 assert_not_nil assigns(:topics)
55 assert_not_nil assigns(:topics)
56 end
56 end
57
57
58 def test_show_with_permission_should_display_the_new_message_form
58 def test_show_with_permission_should_display_the_new_message_form
59 @request.session[:user_id] = 2
59 @request.session[:user_id] = 2
60 get :show, :project_id => 1, :id => 1
60 get :show, :project_id => 1, :id => 1
61 assert_response :success
61 assert_response :success
62 assert_template 'show'
62 assert_template 'show'
63
63
64 assert_tag 'form', :attributes => {:id => 'message-form'}
64 assert_tag 'form', :attributes => {:id => 'message-form'}
65 assert_tag 'input', :attributes => {:name => 'message[subject]'}
65 assert_tag 'input', :attributes => {:name => 'message[subject]'}
66 end
66 end
67
67
68 def test_show_atom
68 def test_show_atom
69 get :show, :project_id => 1, :id => 1, :format => 'atom'
69 get :show, :project_id => 1, :id => 1, :format => 'atom'
70 assert_response :success
70 assert_response :success
71 assert_template 'common/feed.atom'
71 assert_template 'common/feed'
72 assert_not_nil assigns(:board)
72 assert_not_nil assigns(:board)
73 assert_not_nil assigns(:project)
73 assert_not_nil assigns(:project)
74 assert_not_nil assigns(:messages)
74 assert_not_nil assigns(:messages)
75 end
75 end
76
76
77 def test_show_not_found
77 def test_show_not_found
78 get :index, :project_id => 1, :id => 97
78 get :index, :project_id => 1, :id => 97
79 assert_response 404
79 assert_response 404
80 end
80 end
81
81
82 def test_new
82 def test_new
83 @request.session[:user_id] = 2
83 @request.session[:user_id] = 2
84 get :new, :project_id => 1
84 get :new, :project_id => 1
85 assert_response :success
85 assert_response :success
86 assert_template 'new'
86 assert_template 'new'
87 end
87 end
88
88
89 def test_create
89 def test_create
90 @request.session[:user_id] = 2
90 @request.session[:user_id] = 2
91 assert_difference 'Board.count' do
91 assert_difference 'Board.count' do
92 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
92 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
93 end
93 end
94 assert_redirected_to '/projects/ecookbook/settings/boards'
94 assert_redirected_to '/projects/ecookbook/settings/boards'
95 board = Board.first(:order => 'id DESC')
95 board = Board.first(:order => 'id DESC')
96 assert_equal 'Testing', board.name
96 assert_equal 'Testing', board.name
97 assert_equal 'Testing board creation', board.description
97 assert_equal 'Testing board creation', board.description
98 end
98 end
99
99
100 def test_create_with_failure
100 def test_create_with_failure
101 @request.session[:user_id] = 2
101 @request.session[:user_id] = 2
102 assert_no_difference 'Board.count' do
102 assert_no_difference 'Board.count' do
103 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
103 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
104 end
104 end
105 assert_response :success
105 assert_response :success
106 assert_template 'new'
106 assert_template 'new'
107 end
107 end
108
108
109 def test_edit
109 def test_edit
110 @request.session[:user_id] = 2
110 @request.session[:user_id] = 2
111 get :edit, :project_id => 1, :id => 2
111 get :edit, :project_id => 1, :id => 2
112 assert_response :success
112 assert_response :success
113 assert_template 'edit'
113 assert_template 'edit'
114 end
114 end
115
115
116 def test_update
116 def test_update
117 @request.session[:user_id] = 2
117 @request.session[:user_id] = 2
118 assert_no_difference 'Board.count' do
118 assert_no_difference 'Board.count' do
119 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
119 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
120 end
120 end
121 assert_redirected_to '/projects/ecookbook/settings/boards'
121 assert_redirected_to '/projects/ecookbook/settings/boards'
122 assert_equal 'Testing', Board.find(2).name
122 assert_equal 'Testing', Board.find(2).name
123 end
123 end
124
124
125 def test_update_with_failure
125 def test_update_with_failure
126 @request.session[:user_id] = 2
126 @request.session[:user_id] = 2
127 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
127 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
128 assert_response :success
128 assert_response :success
129 assert_template 'edit'
129 assert_template 'edit'
130 end
130 end
131
131
132 def test_destroy
132 def test_destroy
133 @request.session[:user_id] = 2
133 @request.session[:user_id] = 2
134 assert_difference 'Board.count', -1 do
134 assert_difference 'Board.count', -1 do
135 delete :destroy, :project_id => 1, :id => 2
135 delete :destroy, :project_id => 1, :id => 2
136 end
136 end
137 assert_redirected_to '/projects/ecookbook/settings/boards'
137 assert_redirected_to '/projects/ecookbook/settings/boards'
138 assert_nil Board.find_by_id(2)
138 assert_nil Board.find_by_id(2)
139 end
139 end
140 end
140 end
@@ -1,542 +1,542
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 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 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < ActionController::TestCase
24 class ProjectsControllerTest < ActionController::TestCase
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
27 :attachments, :custom_fields, :custom_values, :time_entries
27 :attachments, :custom_fields, :custom_values, :time_entries
28
28
29 def setup
29 def setup
30 @controller = ProjectsController.new
30 @controller = ProjectsController.new
31 @request = ActionController::TestRequest.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
32 @response = ActionController::TestResponse.new
33 @request.session[:user_id] = nil
33 @request.session[:user_id] = nil
34 Setting.default_language = 'en'
34 Setting.default_language = 'en'
35 end
35 end
36
36
37 def test_index
37 def test_index
38 get :index
38 get :index
39 assert_response :success
39 assert_response :success
40 assert_template 'index'
40 assert_template 'index'
41 assert_not_nil assigns(:projects)
41 assert_not_nil assigns(:projects)
42
42
43 assert_tag :ul, :child => {:tag => 'li',
43 assert_tag :ul, :child => {:tag => 'li',
44 :descendant => {:tag => 'a', :content => 'eCookbook'},
44 :descendant => {:tag => 'a', :content => 'eCookbook'},
45 :child => { :tag => 'ul',
45 :child => { :tag => 'ul',
46 :descendant => { :tag => 'a',
46 :descendant => { :tag => 'a',
47 :content => 'Child of private child'
47 :content => 'Child of private child'
48 }
48 }
49 }
49 }
50 }
50 }
51
51
52 assert_no_tag :a, :content => /Private child of eCookbook/
52 assert_no_tag :a, :content => /Private child of eCookbook/
53 end
53 end
54
54
55 def test_index_atom
55 def test_index_atom
56 get :index, :format => 'atom'
56 get :index, :format => 'atom'
57 assert_response :success
57 assert_response :success
58 assert_template 'common/feed.atom'
58 assert_template 'common/feed'
59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current))
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current))
61 end
61 end
62
62
63 context "#index" do
63 context "#index" do
64 context "by non-admin user with view_time_entries permission" do
64 context "by non-admin user with view_time_entries permission" do
65 setup do
65 setup do
66 @request.session[:user_id] = 3
66 @request.session[:user_id] = 3
67 end
67 end
68 should "show overall spent time link" do
68 should "show overall spent time link" do
69 get :index
69 get :index
70 assert_template 'index'
70 assert_template 'index'
71 assert_tag :a, :attributes => {:href => '/time_entries'}
71 assert_tag :a, :attributes => {:href => '/time_entries'}
72 end
72 end
73 end
73 end
74
74
75 context "by non-admin user without view_time_entries permission" do
75 context "by non-admin user without view_time_entries permission" do
76 setup do
76 setup do
77 Role.find(2).remove_permission! :view_time_entries
77 Role.find(2).remove_permission! :view_time_entries
78 Role.non_member.remove_permission! :view_time_entries
78 Role.non_member.remove_permission! :view_time_entries
79 Role.anonymous.remove_permission! :view_time_entries
79 Role.anonymous.remove_permission! :view_time_entries
80 @request.session[:user_id] = 3
80 @request.session[:user_id] = 3
81 end
81 end
82 should "not show overall spent time link" do
82 should "not show overall spent time link" do
83 get :index
83 get :index
84 assert_template 'index'
84 assert_template 'index'
85 assert_no_tag :a, :attributes => {:href => '/time_entries'}
85 assert_no_tag :a, :attributes => {:href => '/time_entries'}
86 end
86 end
87 end
87 end
88 end
88 end
89
89
90 context "#new" do
90 context "#new" do
91 context "by admin user" do
91 context "by admin user" do
92 setup do
92 setup do
93 @request.session[:user_id] = 1
93 @request.session[:user_id] = 1
94 end
94 end
95
95
96 should "accept get" do
96 should "accept get" do
97 get :new
97 get :new
98 assert_response :success
98 assert_response :success
99 assert_template 'new'
99 assert_template 'new'
100 end
100 end
101
101
102 end
102 end
103
103
104 context "by non-admin user with add_project permission" do
104 context "by non-admin user with add_project permission" do
105 setup do
105 setup do
106 Role.non_member.add_permission! :add_project
106 Role.non_member.add_permission! :add_project
107 @request.session[:user_id] = 9
107 @request.session[:user_id] = 9
108 end
108 end
109
109
110 should "accept get" do
110 should "accept get" do
111 get :new
111 get :new
112 assert_response :success
112 assert_response :success
113 assert_template 'new'
113 assert_template 'new'
114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
115 end
115 end
116 end
116 end
117
117
118 context "by non-admin user with add_subprojects permission" do
118 context "by non-admin user with add_subprojects permission" do
119 setup do
119 setup do
120 Role.find(1).remove_permission! :add_project
120 Role.find(1).remove_permission! :add_project
121 Role.find(1).add_permission! :add_subprojects
121 Role.find(1).add_permission! :add_subprojects
122 @request.session[:user_id] = 2
122 @request.session[:user_id] = 2
123 end
123 end
124
124
125 should "accept get" do
125 should "accept get" do
126 get :new, :parent_id => 'ecookbook'
126 get :new, :parent_id => 'ecookbook'
127 assert_response :success
127 assert_response :success
128 assert_template 'new'
128 assert_template 'new'
129 # parent project selected
129 # parent project selected
130 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
130 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
132 # no empty value
132 # no empty value
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
134 :child => {:tag => 'option', :attributes => {:value => ''}}
134 :child => {:tag => 'option', :attributes => {:value => ''}}
135 end
135 end
136 end
136 end
137
137
138 end
138 end
139
139
140 context "POST :create" do
140 context "POST :create" do
141 context "by admin user" do
141 context "by admin user" do
142 setup do
142 setup do
143 @request.session[:user_id] = 1
143 @request.session[:user_id] = 1
144 end
144 end
145
145
146 should "create a new project" do
146 should "create a new project" do
147 post :create,
147 post :create,
148 :project => {
148 :project => {
149 :name => "blog",
149 :name => "blog",
150 :description => "weblog",
150 :description => "weblog",
151 :homepage => 'http://weblog',
151 :homepage => 'http://weblog',
152 :identifier => "blog",
152 :identifier => "blog",
153 :is_public => 1,
153 :is_public => 1,
154 :custom_field_values => { '3' => 'Beta' },
154 :custom_field_values => { '3' => 'Beta' },
155 :tracker_ids => ['1', '3'],
155 :tracker_ids => ['1', '3'],
156 # an issue custom field that is not for all project
156 # an issue custom field that is not for all project
157 :issue_custom_field_ids => ['9'],
157 :issue_custom_field_ids => ['9'],
158 :enabled_module_names => ['issue_tracking', 'news', 'repository']
158 :enabled_module_names => ['issue_tracking', 'news', 'repository']
159 }
159 }
160 assert_redirected_to '/projects/blog/settings'
160 assert_redirected_to '/projects/blog/settings'
161
161
162 project = Project.find_by_name('blog')
162 project = Project.find_by_name('blog')
163 assert_kind_of Project, project
163 assert_kind_of Project, project
164 assert project.active?
164 assert project.active?
165 assert_equal 'weblog', project.description
165 assert_equal 'weblog', project.description
166 assert_equal 'http://weblog', project.homepage
166 assert_equal 'http://weblog', project.homepage
167 assert_equal true, project.is_public?
167 assert_equal true, project.is_public?
168 assert_nil project.parent
168 assert_nil project.parent
169 assert_equal 'Beta', project.custom_value_for(3).value
169 assert_equal 'Beta', project.custom_value_for(3).value
170 assert_equal [1, 3], project.trackers.map(&:id).sort
170 assert_equal [1, 3], project.trackers.map(&:id).sort
171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
172 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
172 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
173 end
173 end
174
174
175 should "create a new subproject" do
175 should "create a new subproject" do
176 post :create, :project => { :name => "blog",
176 post :create, :project => { :name => "blog",
177 :description => "weblog",
177 :description => "weblog",
178 :identifier => "blog",
178 :identifier => "blog",
179 :is_public => 1,
179 :is_public => 1,
180 :custom_field_values => { '3' => 'Beta' },
180 :custom_field_values => { '3' => 'Beta' },
181 :parent_id => 1
181 :parent_id => 1
182 }
182 }
183 assert_redirected_to '/projects/blog/settings'
183 assert_redirected_to '/projects/blog/settings'
184
184
185 project = Project.find_by_name('blog')
185 project = Project.find_by_name('blog')
186 assert_kind_of Project, project
186 assert_kind_of Project, project
187 assert_equal Project.find(1), project.parent
187 assert_equal Project.find(1), project.parent
188 end
188 end
189
189
190 should "continue" do
190 should "continue" do
191 assert_difference 'Project.count' do
191 assert_difference 'Project.count' do
192 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue'
192 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue'
193 end
193 end
194 assert_redirected_to '/projects/new?'
194 assert_redirected_to '/projects/new?'
195 end
195 end
196 end
196 end
197
197
198 context "by non-admin user with add_project permission" do
198 context "by non-admin user with add_project permission" do
199 setup do
199 setup do
200 Role.non_member.add_permission! :add_project
200 Role.non_member.add_permission! :add_project
201 @request.session[:user_id] = 9
201 @request.session[:user_id] = 9
202 end
202 end
203
203
204 should "accept create a Project" do
204 should "accept create a Project" do
205 post :create, :project => { :name => "blog",
205 post :create, :project => { :name => "blog",
206 :description => "weblog",
206 :description => "weblog",
207 :identifier => "blog",
207 :identifier => "blog",
208 :is_public => 1,
208 :is_public => 1,
209 :custom_field_values => { '3' => 'Beta' },
209 :custom_field_values => { '3' => 'Beta' },
210 :tracker_ids => ['1', '3'],
210 :tracker_ids => ['1', '3'],
211 :enabled_module_names => ['issue_tracking', 'news', 'repository']
211 :enabled_module_names => ['issue_tracking', 'news', 'repository']
212 }
212 }
213
213
214 assert_redirected_to '/projects/blog/settings'
214 assert_redirected_to '/projects/blog/settings'
215
215
216 project = Project.find_by_name('blog')
216 project = Project.find_by_name('blog')
217 assert_kind_of Project, project
217 assert_kind_of Project, project
218 assert_equal 'weblog', project.description
218 assert_equal 'weblog', project.description
219 assert_equal true, project.is_public?
219 assert_equal true, project.is_public?
220 assert_equal [1, 3], project.trackers.map(&:id).sort
220 assert_equal [1, 3], project.trackers.map(&:id).sort
221 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
221 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
222
222
223 # User should be added as a project member
223 # User should be added as a project member
224 assert User.find(9).member_of?(project)
224 assert User.find(9).member_of?(project)
225 assert_equal 1, project.members.size
225 assert_equal 1, project.members.size
226 end
226 end
227
227
228 should "fail with parent_id" do
228 should "fail with parent_id" do
229 assert_no_difference 'Project.count' do
229 assert_no_difference 'Project.count' do
230 post :create, :project => { :name => "blog",
230 post :create, :project => { :name => "blog",
231 :description => "weblog",
231 :description => "weblog",
232 :identifier => "blog",
232 :identifier => "blog",
233 :is_public => 1,
233 :is_public => 1,
234 :custom_field_values => { '3' => 'Beta' },
234 :custom_field_values => { '3' => 'Beta' },
235 :parent_id => 1
235 :parent_id => 1
236 }
236 }
237 end
237 end
238 assert_response :success
238 assert_response :success
239 project = assigns(:project)
239 project = assigns(:project)
240 assert_kind_of Project, project
240 assert_kind_of Project, project
241 assert_not_nil project.errors[:parent_id]
241 assert_not_nil project.errors[:parent_id]
242 end
242 end
243 end
243 end
244
244
245 context "by non-admin user with add_subprojects permission" do
245 context "by non-admin user with add_subprojects permission" do
246 setup do
246 setup do
247 Role.find(1).remove_permission! :add_project
247 Role.find(1).remove_permission! :add_project
248 Role.find(1).add_permission! :add_subprojects
248 Role.find(1).add_permission! :add_subprojects
249 @request.session[:user_id] = 2
249 @request.session[:user_id] = 2
250 end
250 end
251
251
252 should "create a project with a parent_id" do
252 should "create a project with a parent_id" do
253 post :create, :project => { :name => "blog",
253 post :create, :project => { :name => "blog",
254 :description => "weblog",
254 :description => "weblog",
255 :identifier => "blog",
255 :identifier => "blog",
256 :is_public => 1,
256 :is_public => 1,
257 :custom_field_values => { '3' => 'Beta' },
257 :custom_field_values => { '3' => 'Beta' },
258 :parent_id => 1
258 :parent_id => 1
259 }
259 }
260 assert_redirected_to '/projects/blog/settings'
260 assert_redirected_to '/projects/blog/settings'
261 project = Project.find_by_name('blog')
261 project = Project.find_by_name('blog')
262 end
262 end
263
263
264 should "fail without parent_id" do
264 should "fail without parent_id" do
265 assert_no_difference 'Project.count' do
265 assert_no_difference 'Project.count' do
266 post :create, :project => { :name => "blog",
266 post :create, :project => { :name => "blog",
267 :description => "weblog",
267 :description => "weblog",
268 :identifier => "blog",
268 :identifier => "blog",
269 :is_public => 1,
269 :is_public => 1,
270 :custom_field_values => { '3' => 'Beta' }
270 :custom_field_values => { '3' => 'Beta' }
271 }
271 }
272 end
272 end
273 assert_response :success
273 assert_response :success
274 project = assigns(:project)
274 project = assigns(:project)
275 assert_kind_of Project, project
275 assert_kind_of Project, project
276 assert_not_nil project.errors[:parent_id]
276 assert_not_nil project.errors[:parent_id]
277 end
277 end
278
278
279 should "fail with unauthorized parent_id" do
279 should "fail with unauthorized parent_id" do
280 assert !User.find(2).member_of?(Project.find(6))
280 assert !User.find(2).member_of?(Project.find(6))
281 assert_no_difference 'Project.count' do
281 assert_no_difference 'Project.count' do
282 post :create, :project => { :name => "blog",
282 post :create, :project => { :name => "blog",
283 :description => "weblog",
283 :description => "weblog",
284 :identifier => "blog",
284 :identifier => "blog",
285 :is_public => 1,
285 :is_public => 1,
286 :custom_field_values => { '3' => 'Beta' },
286 :custom_field_values => { '3' => 'Beta' },
287 :parent_id => 6
287 :parent_id => 6
288 }
288 }
289 end
289 end
290 assert_response :success
290 assert_response :success
291 project = assigns(:project)
291 project = assigns(:project)
292 assert_kind_of Project, project
292 assert_kind_of Project, project
293 assert_not_nil project.errors[:parent_id]
293 assert_not_nil project.errors[:parent_id]
294 end
294 end
295 end
295 end
296 end
296 end
297
297
298 def test_create_should_preserve_modules_on_validation_failure
298 def test_create_should_preserve_modules_on_validation_failure
299 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
299 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
300 @request.session[:user_id] = 1
300 @request.session[:user_id] = 1
301 assert_no_difference 'Project.count' do
301 assert_no_difference 'Project.count' do
302 post :create, :project => {
302 post :create, :project => {
303 :name => "blog",
303 :name => "blog",
304 :identifier => "",
304 :identifier => "",
305 :enabled_module_names => %w(issue_tracking news)
305 :enabled_module_names => %w(issue_tracking news)
306 }
306 }
307 end
307 end
308 assert_response :success
308 assert_response :success
309 project = assigns(:project)
309 project = assigns(:project)
310 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
310 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
311 end
311 end
312 end
312 end
313
313
314 def test_show_by_id
314 def test_show_by_id
315 get :show, :id => 1
315 get :show, :id => 1
316 assert_response :success
316 assert_response :success
317 assert_template 'show'
317 assert_template 'show'
318 assert_not_nil assigns(:project)
318 assert_not_nil assigns(:project)
319 end
319 end
320
320
321 def test_show_by_identifier
321 def test_show_by_identifier
322 get :show, :id => 'ecookbook'
322 get :show, :id => 'ecookbook'
323 assert_response :success
323 assert_response :success
324 assert_template 'show'
324 assert_template 'show'
325 assert_not_nil assigns(:project)
325 assert_not_nil assigns(:project)
326 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
326 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
327
327
328 assert_tag 'li', :content => /Development status/
328 assert_tag 'li', :content => /Development status/
329 end
329 end
330
330
331 def test_show_should_not_display_hidden_custom_fields
331 def test_show_should_not_display_hidden_custom_fields
332 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
332 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
333 get :show, :id => 'ecookbook'
333 get :show, :id => 'ecookbook'
334 assert_response :success
334 assert_response :success
335 assert_template 'show'
335 assert_template 'show'
336 assert_not_nil assigns(:project)
336 assert_not_nil assigns(:project)
337
337
338 assert_no_tag 'li', :content => /Development status/
338 assert_no_tag 'li', :content => /Development status/
339 end
339 end
340
340
341 def test_show_should_not_fail_when_custom_values_are_nil
341 def test_show_should_not_fail_when_custom_values_are_nil
342 project = Project.find_by_identifier('ecookbook')
342 project = Project.find_by_identifier('ecookbook')
343 project.custom_values.first.update_attribute(:value, nil)
343 project.custom_values.first.update_attribute(:value, nil)
344 get :show, :id => 'ecookbook'
344 get :show, :id => 'ecookbook'
345 assert_response :success
345 assert_response :success
346 assert_template 'show'
346 assert_template 'show'
347 assert_not_nil assigns(:project)
347 assert_not_nil assigns(:project)
348 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
348 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
349 end
349 end
350
350
351 def show_archived_project_should_be_denied
351 def show_archived_project_should_be_denied
352 project = Project.find_by_identifier('ecookbook')
352 project = Project.find_by_identifier('ecookbook')
353 project.archive!
353 project.archive!
354
354
355 get :show, :id => 'ecookbook'
355 get :show, :id => 'ecookbook'
356 assert_response 403
356 assert_response 403
357 assert_nil assigns(:project)
357 assert_nil assigns(:project)
358 assert_tag :tag => 'p', :content => /archived/
358 assert_tag :tag => 'p', :content => /archived/
359 end
359 end
360
360
361 def test_private_subprojects_hidden
361 def test_private_subprojects_hidden
362 get :show, :id => 'ecookbook'
362 get :show, :id => 'ecookbook'
363 assert_response :success
363 assert_response :success
364 assert_template 'show'
364 assert_template 'show'
365 assert_no_tag :tag => 'a', :content => /Private child/
365 assert_no_tag :tag => 'a', :content => /Private child/
366 end
366 end
367
367
368 def test_private_subprojects_visible
368 def test_private_subprojects_visible
369 @request.session[:user_id] = 2 # manager who is a member of the private subproject
369 @request.session[:user_id] = 2 # manager who is a member of the private subproject
370 get :show, :id => 'ecookbook'
370 get :show, :id => 'ecookbook'
371 assert_response :success
371 assert_response :success
372 assert_template 'show'
372 assert_template 'show'
373 assert_tag :tag => 'a', :content => /Private child/
373 assert_tag :tag => 'a', :content => /Private child/
374 end
374 end
375
375
376 def test_settings
376 def test_settings
377 @request.session[:user_id] = 2 # manager
377 @request.session[:user_id] = 2 # manager
378 get :settings, :id => 1
378 get :settings, :id => 1
379 assert_response :success
379 assert_response :success
380 assert_template 'settings'
380 assert_template 'settings'
381 end
381 end
382
382
383 def test_update
383 def test_update
384 @request.session[:user_id] = 2 # manager
384 @request.session[:user_id] = 2 # manager
385 post :update, :id => 1, :project => {:name => 'Test changed name',
385 post :update, :id => 1, :project => {:name => 'Test changed name',
386 :issue_custom_field_ids => ['']}
386 :issue_custom_field_ids => ['']}
387 assert_redirected_to '/projects/ecookbook/settings'
387 assert_redirected_to '/projects/ecookbook/settings'
388 project = Project.find(1)
388 project = Project.find(1)
389 assert_equal 'Test changed name', project.name
389 assert_equal 'Test changed name', project.name
390 end
390 end
391
391
392 def test_update_with_failure
392 def test_update_with_failure
393 @request.session[:user_id] = 2 # manager
393 @request.session[:user_id] = 2 # manager
394 post :update, :id => 1, :project => {:name => ''}
394 post :update, :id => 1, :project => {:name => ''}
395 assert_response :success
395 assert_response :success
396 assert_template 'settings'
396 assert_template 'settings'
397 assert_error_tag :content => /name can't be blank/i
397 assert_error_tag :content => /name can't be blank/i
398 end
398 end
399
399
400 def test_modules
400 def test_modules
401 @request.session[:user_id] = 2
401 @request.session[:user_id] = 2
402 Project.find(1).enabled_module_names = ['issue_tracking', 'news']
402 Project.find(1).enabled_module_names = ['issue_tracking', 'news']
403
403
404 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
404 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
405 assert_redirected_to '/projects/ecookbook/settings/modules'
405 assert_redirected_to '/projects/ecookbook/settings/modules'
406 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
406 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
407 end
407 end
408
408
409 def test_destroy_without_confirmation
409 def test_destroy_without_confirmation
410 @request.session[:user_id] = 1 # admin
410 @request.session[:user_id] = 1 # admin
411 delete :destroy, :id => 1
411 delete :destroy, :id => 1
412 assert_response :success
412 assert_response :success
413 assert_template 'destroy'
413 assert_template 'destroy'
414 assert_not_nil Project.find_by_id(1)
414 assert_not_nil Project.find_by_id(1)
415 end
415 end
416
416
417 def test_destroy
417 def test_destroy
418 @request.session[:user_id] = 1 # admin
418 @request.session[:user_id] = 1 # admin
419 delete :destroy, :id => 1, :confirm => 1
419 delete :destroy, :id => 1, :confirm => 1
420 assert_redirected_to '/admin/projects'
420 assert_redirected_to '/admin/projects'
421 assert_nil Project.find_by_id(1)
421 assert_nil Project.find_by_id(1)
422 end
422 end
423
423
424 def test_archive
424 def test_archive
425 @request.session[:user_id] = 1 # admin
425 @request.session[:user_id] = 1 # admin
426 post :archive, :id => 1
426 post :archive, :id => 1
427 assert_redirected_to '/admin/projects'
427 assert_redirected_to '/admin/projects'
428 assert !Project.find(1).active?
428 assert !Project.find(1).active?
429 end
429 end
430
430
431 def test_archive_with_failure
431 def test_archive_with_failure
432 @request.session[:user_id] = 1
432 @request.session[:user_id] = 1
433 Project.any_instance.stubs(:archive).returns(false)
433 Project.any_instance.stubs(:archive).returns(false)
434 post :archive, :id => 1
434 post :archive, :id => 1
435 assert_redirected_to '/admin/projects'
435 assert_redirected_to '/admin/projects'
436 assert_match /project cannot be archived/i, flash[:error]
436 assert_match /project cannot be archived/i, flash[:error]
437 end
437 end
438
438
439 def test_unarchive
439 def test_unarchive
440 @request.session[:user_id] = 1 # admin
440 @request.session[:user_id] = 1 # admin
441 Project.find(1).archive
441 Project.find(1).archive
442 post :unarchive, :id => 1
442 post :unarchive, :id => 1
443 assert_redirected_to '/admin/projects'
443 assert_redirected_to '/admin/projects'
444 assert Project.find(1).active?
444 assert Project.find(1).active?
445 end
445 end
446
446
447 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
447 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
448 CustomField.delete_all
448 CustomField.delete_all
449 parent = nil
449 parent = nil
450 6.times do |i|
450 6.times do |i|
451 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
451 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
452 p.set_parent!(parent)
452 p.set_parent!(parent)
453 get :show, :id => p
453 get :show, :id => p
454 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
454 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
455 :children => { :count => [i, 3].min,
455 :children => { :count => [i, 3].min,
456 :only => { :tag => 'a' } }
456 :only => { :tag => 'a' } }
457
457
458 parent = p
458 parent = p
459 end
459 end
460 end
460 end
461
461
462 def test_get_copy
462 def test_get_copy
463 @request.session[:user_id] = 1 # admin
463 @request.session[:user_id] = 1 # admin
464 get :copy, :id => 1
464 get :copy, :id => 1
465 assert_response :success
465 assert_response :success
466 assert_template 'copy'
466 assert_template 'copy'
467 assert assigns(:project)
467 assert assigns(:project)
468 assert_equal Project.find(1).description, assigns(:project).description
468 assert_equal Project.find(1).description, assigns(:project).description
469 assert_nil assigns(:project).id
469 assert_nil assigns(:project).id
470
470
471 assert_tag :tag => 'input',
471 assert_tag :tag => 'input',
472 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'}
472 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'}
473 end
473 end
474
474
475 def test_post_copy_should_copy_requested_items
475 def test_post_copy_should_copy_requested_items
476 @request.session[:user_id] = 1 # admin
476 @request.session[:user_id] = 1 # admin
477 CustomField.delete_all
477 CustomField.delete_all
478
478
479 assert_difference 'Project.count' do
479 assert_difference 'Project.count' do
480 post :copy, :id => 1,
480 post :copy, :id => 1,
481 :project => {
481 :project => {
482 :name => 'Copy',
482 :name => 'Copy',
483 :identifier => 'unique-copy',
483 :identifier => 'unique-copy',
484 :tracker_ids => ['1', '2', '3', ''],
484 :tracker_ids => ['1', '2', '3', ''],
485 :enabled_module_names => %w(issue_tracking time_tracking)
485 :enabled_module_names => %w(issue_tracking time_tracking)
486 },
486 },
487 :only => %w(issues versions)
487 :only => %w(issues versions)
488 end
488 end
489 project = Project.find('unique-copy')
489 project = Project.find('unique-copy')
490 source = Project.find(1)
490 source = Project.find(1)
491 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort
491 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort
492
492
493 assert_equal source.versions.count, project.versions.count, "All versions were not copied"
493 assert_equal source.versions.count, project.versions.count, "All versions were not copied"
494 # issues assigned to a closed version won't be copied
494 # issues assigned to a closed version won't be copied
495 assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.size,
495 assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.size,
496 project.issues.count, "All issues were not copied"
496 project.issues.count, "All issues were not copied"
497 assert_equal 0, project.members.count
497 assert_equal 0, project.members.count
498 end
498 end
499
499
500 def test_post_copy_should_redirect_to_settings_when_successful
500 def test_post_copy_should_redirect_to_settings_when_successful
501 @request.session[:user_id] = 1 # admin
501 @request.session[:user_id] = 1 # admin
502 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
502 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
503 assert_response :redirect
503 assert_response :redirect
504 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
504 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
505 end
505 end
506
506
507 def test_jump_should_redirect_to_active_tab
507 def test_jump_should_redirect_to_active_tab
508 get :show, :id => 1, :jump => 'issues'
508 get :show, :id => 1, :jump => 'issues'
509 assert_redirected_to '/projects/ecookbook/issues'
509 assert_redirected_to '/projects/ecookbook/issues'
510 end
510 end
511
511
512 def test_jump_should_not_redirect_to_inactive_tab
512 def test_jump_should_not_redirect_to_inactive_tab
513 get :show, :id => 3, :jump => 'documents'
513 get :show, :id => 3, :jump => 'documents'
514 assert_response :success
514 assert_response :success
515 assert_template 'show'
515 assert_template 'show'
516 end
516 end
517
517
518 def test_jump_should_not_redirect_to_unknown_tab
518 def test_jump_should_not_redirect_to_unknown_tab
519 get :show, :id => 3, :jump => 'foobar'
519 get :show, :id => 3, :jump => 'foobar'
520 assert_response :success
520 assert_response :success
521 assert_template 'show'
521 assert_template 'show'
522 end
522 end
523
523
524 # A hook that is manually registered later
524 # A hook that is manually registered later
525 class ProjectBasedTemplate < Redmine::Hook::ViewListener
525 class ProjectBasedTemplate < Redmine::Hook::ViewListener
526 def view_layouts_base_html_head(context)
526 def view_layouts_base_html_head(context)
527 # Adds a project stylesheet
527 # Adds a project stylesheet
528 stylesheet_link_tag(context[:project].identifier) if context[:project]
528 stylesheet_link_tag(context[:project].identifier) if context[:project]
529 end
529 end
530 end
530 end
531 # Don't use this hook now
531 # Don't use this hook now
532 Redmine::Hook.clear_listeners
532 Redmine::Hook.clear_listeners
533
533
534 def test_hook_response
534 def test_hook_response
535 Redmine::Hook.add_listener(ProjectBasedTemplate)
535 Redmine::Hook.add_listener(ProjectBasedTemplate)
536 get :show, :id => 1
536 get :show, :id => 1
537 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
537 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
538 :parent => {:tag => 'head'}
538 :parent => {:tag => 'head'}
539
539
540 Redmine::Hook.clear_listeners
540 Redmine::Hook.clear_listeners
541 end
541 end
542 end
542 end
General Comments 0
You need to be logged in to leave comments. Login now