@@ -1,75 +1,75 | |||||
1 | <%= error_messages_for 'project' %> |
|
1 | <%= error_messages_for 'project' %> | |
2 |
|
2 | |||
3 | <div class="box tabular"> |
|
3 | <div class="box tabular"> | |
4 | <!--[form:project]--> |
|
4 | <!--[form:project]--> | |
5 | <p><%= f.text_field :name, :required => true, :size => 60 %></p> |
|
5 | <p><%= f.text_field :name, :required => true, :size => 60 %></p> | |
6 |
|
6 | |||
7 | <p><%= f.text_area :description, :rows => 5, :class => 'wiki-edit' %></p> |
|
7 | <p><%= f.text_area :description, :rows => 5, :class => 'wiki-edit' %></p> | |
8 | <p><%= f.text_field :identifier, :required => true, :size => 60, :disabled => @project.identifier_frozen?, :maxlength => Project::IDENTIFIER_MAX_LENGTH %> |
|
8 | <p><%= f.text_field :identifier, :required => true, :size => 60, :disabled => @project.identifier_frozen?, :maxlength => Project::IDENTIFIER_MAX_LENGTH %> | |
9 | <% unless @project.identifier_frozen? %> |
|
9 | <% unless @project.identifier_frozen? %> | |
10 | <em class="info"><%= l(:text_length_between, :min => 1, :max => Project::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_project_identifier_info).html_safe %></em> |
|
10 | <em class="info"><%= l(:text_length_between, :min => 1, :max => Project::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_project_identifier_info).html_safe %></em> | |
11 | <% end %></p> |
|
11 | <% end %></p> | |
12 | <p><%= f.text_field :homepage, :size => 60 %></p> |
|
12 | <p><%= f.text_field :homepage, :size => 60 %></p> | |
13 | <p><%= f.check_box :is_public %></p> |
|
13 | <p><%= f.check_box :is_public %></p> | |
14 |
|
14 | |||
15 | <% unless @project.allowed_parents.compact.empty? %> |
|
15 | <% unless @project.allowed_parents.compact.empty? %> | |
16 | <p><%= label(:project, :parent_id, l(:field_parent)) %><%= parent_project_select_tag(@project) %></p> |
|
16 | <p><%= label(:project, :parent_id, l(:field_parent)) %><%= parent_project_select_tag(@project) %></p> | |
17 | <% end %> |
|
17 | <% end %> | |
18 |
|
18 | |||
19 |
<% if @project.safe_attribute? ' |
|
19 | <% if @project.safe_attribute? 'inherit_members' %> | |
20 | <p><%= f.check_box :inherit_members %></p> |
|
20 | <p><%= f.check_box :inherit_members %></p> | |
21 | <% end %> |
|
21 | <% end %> | |
22 |
|
22 | |||
23 | <%= wikitoolbar_for 'project_description' %> |
|
23 | <%= wikitoolbar_for 'project_description' %> | |
24 |
|
24 | |||
25 | <% @project.custom_field_values.each do |value| %> |
|
25 | <% @project.custom_field_values.each do |value| %> | |
26 | <p><%= custom_field_tag_with_label :project, value %></p> |
|
26 | <p><%= custom_field_tag_with_label :project, value %></p> | |
27 | <% end %> |
|
27 | <% end %> | |
28 | <%= call_hook(:view_projects_form, :project => @project, :form => f) %> |
|
28 | <%= call_hook(:view_projects_form, :project => @project, :form => f) %> | |
29 | </div> |
|
29 | </div> | |
30 |
|
30 | |||
31 | <% if @project.new_record? %> |
|
31 | <% if @project.new_record? %> | |
32 | <fieldset class="box tabular"><legend><%= l(:label_module_plural) %></legend> |
|
32 | <fieldset class="box tabular"><legend><%= l(:label_module_plural) %></legend> | |
33 | <% Redmine::AccessControl.available_project_modules.each do |m| %> |
|
33 | <% Redmine::AccessControl.available_project_modules.each do |m| %> | |
34 | <label class="floating"> |
|
34 | <label class="floating"> | |
35 | <%= check_box_tag 'project[enabled_module_names][]', m, @project.module_enabled?(m), :id => "project_enabled_module_names_#{m}" %> |
|
35 | <%= check_box_tag 'project[enabled_module_names][]', m, @project.module_enabled?(m), :id => "project_enabled_module_names_#{m}" %> | |
36 | <%= l_or_humanize(m, :prefix => "project_module_") %> |
|
36 | <%= l_or_humanize(m, :prefix => "project_module_") %> | |
37 | </label> |
|
37 | </label> | |
38 | <% end %> |
|
38 | <% end %> | |
39 | <%= hidden_field_tag 'project[enabled_module_names][]', '' %> |
|
39 | <%= hidden_field_tag 'project[enabled_module_names][]', '' %> | |
40 | <%= javascript_tag 'observeProjectModules()' %> |
|
40 | <%= javascript_tag 'observeProjectModules()' %> | |
41 | </fieldset> |
|
41 | </fieldset> | |
42 | <% end %> |
|
42 | <% end %> | |
43 |
|
43 | |||
44 | <% if @project.new_record? || @project.module_enabled?('issue_tracking') %> |
|
44 | <% if @project.new_record? || @project.module_enabled?('issue_tracking') %> | |
45 | <% unless @trackers.empty? %> |
|
45 | <% unless @trackers.empty? %> | |
46 | <fieldset class="box tabular" id="project_trackers"><legend><%=l(:label_tracker_plural)%></legend> |
|
46 | <fieldset class="box tabular" id="project_trackers"><legend><%=l(:label_tracker_plural)%></legend> | |
47 | <% @trackers.each do |tracker| %> |
|
47 | <% @trackers.each do |tracker| %> | |
48 | <label class="floating"> |
|
48 | <label class="floating"> | |
49 | <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %> |
|
49 | <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %> | |
50 | <%=h tracker %> |
|
50 | <%=h tracker %> | |
51 | </label> |
|
51 | </label> | |
52 | <% end %> |
|
52 | <% end %> | |
53 | <%= hidden_field_tag 'project[tracker_ids][]', '' %> |
|
53 | <%= hidden_field_tag 'project[tracker_ids][]', '' %> | |
54 | </fieldset> |
|
54 | </fieldset> | |
55 | <% end %> |
|
55 | <% end %> | |
56 |
|
56 | |||
57 | <% unless @issue_custom_fields.empty? %> |
|
57 | <% unless @issue_custom_fields.empty? %> | |
58 | <fieldset class="box tabular" id="project_issue_custom_fields"><legend><%=l(:label_custom_field_plural)%></legend> |
|
58 | <fieldset class="box tabular" id="project_issue_custom_fields"><legend><%=l(:label_custom_field_plural)%></legend> | |
59 | <% @issue_custom_fields.each do |custom_field| %> |
|
59 | <% @issue_custom_fields.each do |custom_field| %> | |
60 | <label class="floating"> |
|
60 | <label class="floating"> | |
61 | <%= check_box_tag 'project[issue_custom_field_ids][]', custom_field.id, (@project.all_issue_custom_fields.include? custom_field), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %> |
|
61 | <%= check_box_tag 'project[issue_custom_field_ids][]', custom_field.id, (@project.all_issue_custom_fields.include? custom_field), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %> | |
62 | <%=h custom_field.name %> |
|
62 | <%=h custom_field.name %> | |
63 | </label> |
|
63 | </label> | |
64 | <% end %> |
|
64 | <% end %> | |
65 | <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %> |
|
65 | <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %> | |
66 | </fieldset> |
|
66 | </fieldset> | |
67 | <% end %> |
|
67 | <% end %> | |
68 | <% end %> |
|
68 | <% end %> | |
69 | <!--[eoform:project]--> |
|
69 | <!--[eoform:project]--> | |
70 |
|
70 | |||
71 | <% unless @project.identifier_frozen? %> |
|
71 | <% unless @project.identifier_frozen? %> | |
72 | <% content_for :header_tags do %> |
|
72 | <% content_for :header_tags do %> | |
73 | <%= javascript_include_tag 'project_identifier' %> |
|
73 | <%= javascript_include_tag 'project_identifier' %> | |
74 | <% end %> |
|
74 | <% end %> | |
75 | <% end %> |
|
75 | <% end %> |
@@ -1,597 +1,599 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 ProjectsControllerTest < ActionController::TestCase |
|
20 | class ProjectsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, |
|
21 | fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, | |
22 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, |
|
22 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, | |
23 | :attachments, :custom_fields, :custom_values, :time_entries |
|
23 | :attachments, :custom_fields, :custom_values, :time_entries | |
24 |
|
24 | |||
25 | def setup |
|
25 | def setup | |
26 | @request.session[:user_id] = nil |
|
26 | @request.session[:user_id] = nil | |
27 | Setting.default_language = 'en' |
|
27 | Setting.default_language = 'en' | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def test_index |
|
30 | def test_index | |
31 | get :index |
|
31 | get :index | |
32 | assert_response :success |
|
32 | assert_response :success | |
33 | assert_template 'index' |
|
33 | assert_template 'index' | |
34 | assert_not_nil assigns(:projects) |
|
34 | assert_not_nil assigns(:projects) | |
35 |
|
35 | |||
36 | assert_tag :ul, :child => {:tag => 'li', |
|
36 | assert_tag :ul, :child => {:tag => 'li', | |
37 | :descendant => {:tag => 'a', :content => 'eCookbook'}, |
|
37 | :descendant => {:tag => 'a', :content => 'eCookbook'}, | |
38 | :child => { :tag => 'ul', |
|
38 | :child => { :tag => 'ul', | |
39 | :descendant => { :tag => 'a', |
|
39 | :descendant => { :tag => 'a', | |
40 | :content => 'Child of private child' |
|
40 | :content => 'Child of private child' | |
41 | } |
|
41 | } | |
42 | } |
|
42 | } | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | assert_no_tag :a, :content => /Private child of eCookbook/ |
|
45 | assert_no_tag :a, :content => /Private child of eCookbook/ | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_index_atom |
|
48 | def test_index_atom | |
49 | get :index, :format => 'atom' |
|
49 | get :index, :format => 'atom' | |
50 | assert_response :success |
|
50 | assert_response :success | |
51 | assert_template 'common/feed' |
|
51 | assert_template 'common/feed' | |
52 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
52 | assert_select 'feed>title', :text => 'Redmine: Latest projects' | |
53 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) |
|
53 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | context "#index" do |
|
56 | context "#index" do | |
57 | context "by non-admin user with view_time_entries permission" do |
|
57 | context "by non-admin user with view_time_entries permission" do | |
58 | setup do |
|
58 | setup do | |
59 | @request.session[:user_id] = 3 |
|
59 | @request.session[:user_id] = 3 | |
60 | end |
|
60 | end | |
61 | should "show overall spent time link" do |
|
61 | should "show overall spent time link" do | |
62 | get :index |
|
62 | get :index | |
63 | assert_template 'index' |
|
63 | assert_template 'index' | |
64 | assert_tag :a, :attributes => {:href => '/time_entries'} |
|
64 | assert_tag :a, :attributes => {:href => '/time_entries'} | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | context "by non-admin user without view_time_entries permission" do |
|
68 | context "by non-admin user without view_time_entries permission" do | |
69 | setup do |
|
69 | setup do | |
70 | Role.find(2).remove_permission! :view_time_entries |
|
70 | Role.find(2).remove_permission! :view_time_entries | |
71 | Role.non_member.remove_permission! :view_time_entries |
|
71 | Role.non_member.remove_permission! :view_time_entries | |
72 | Role.anonymous.remove_permission! :view_time_entries |
|
72 | Role.anonymous.remove_permission! :view_time_entries | |
73 | @request.session[:user_id] = 3 |
|
73 | @request.session[:user_id] = 3 | |
74 | end |
|
74 | end | |
75 | should "not show overall spent time link" do |
|
75 | should "not show overall spent time link" do | |
76 | get :index |
|
76 | get :index | |
77 | assert_template 'index' |
|
77 | assert_template 'index' | |
78 | assert_no_tag :a, :attributes => {:href => '/time_entries'} |
|
78 | assert_no_tag :a, :attributes => {:href => '/time_entries'} | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | context "#new" do |
|
83 | context "#new" do | |
84 | context "by admin user" do |
|
84 | context "by admin user" do | |
85 | setup do |
|
85 | setup do | |
86 | @request.session[:user_id] = 1 |
|
86 | @request.session[:user_id] = 1 | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | should "accept get" do |
|
89 | should "accept get" do | |
90 | get :new |
|
90 | get :new | |
91 | assert_response :success |
|
91 | assert_response :success | |
92 | assert_template 'new' |
|
92 | assert_template 'new' | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | context "by non-admin user with add_project permission" do |
|
97 | context "by non-admin user with add_project permission" do | |
98 | setup do |
|
98 | setup do | |
99 | Role.non_member.add_permission! :add_project |
|
99 | Role.non_member.add_permission! :add_project | |
100 | @request.session[:user_id] = 9 |
|
100 | @request.session[:user_id] = 9 | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | should "accept get" do |
|
103 | should "accept get" do | |
104 | get :new |
|
104 | get :new | |
105 | assert_response :success |
|
105 | assert_response :success | |
106 | assert_template 'new' |
|
106 | assert_template 'new' | |
107 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} |
|
107 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} | |
108 | end |
|
108 | end | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | context "by non-admin user with add_subprojects permission" do |
|
111 | context "by non-admin user with add_subprojects permission" do | |
112 | setup do |
|
112 | setup do | |
113 | Role.find(1).remove_permission! :add_project |
|
113 | Role.find(1).remove_permission! :add_project | |
114 | Role.find(1).add_permission! :add_subprojects |
|
114 | Role.find(1).add_permission! :add_subprojects | |
115 | @request.session[:user_id] = 2 |
|
115 | @request.session[:user_id] = 2 | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | should "accept get" do |
|
118 | should "accept get" do | |
119 | get :new, :parent_id => 'ecookbook' |
|
119 | get :new, :parent_id => 'ecookbook' | |
120 | assert_response :success |
|
120 | assert_response :success | |
121 | assert_template 'new' |
|
121 | assert_template 'new' | |
122 | # parent project selected |
|
122 | # parent project selected | |
123 | assert_tag :select, :attributes => {:name => 'project[parent_id]'}, |
|
123 | assert_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
124 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} |
|
124 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} | |
125 | # no empty value |
|
125 | # no empty value | |
126 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, |
|
126 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
127 | :child => {:tag => 'option', :attributes => {:value => ''}} |
|
127 | :child => {:tag => 'option', :attributes => {:value => ''}} | |
128 | end |
|
128 | end | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | context "POST :create" do |
|
133 | context "POST :create" do | |
134 | context "by admin user" do |
|
134 | context "by admin user" do | |
135 | setup do |
|
135 | setup do | |
136 | @request.session[:user_id] = 1 |
|
136 | @request.session[:user_id] = 1 | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | should "create a new project" do |
|
139 | should "create a new project" do | |
140 | post :create, |
|
140 | post :create, | |
141 | :project => { |
|
141 | :project => { | |
142 | :name => "blog", |
|
142 | :name => "blog", | |
143 | :description => "weblog", |
|
143 | :description => "weblog", | |
144 | :homepage => 'http://weblog', |
|
144 | :homepage => 'http://weblog', | |
145 | :identifier => "blog", |
|
145 | :identifier => "blog", | |
146 | :is_public => 1, |
|
146 | :is_public => 1, | |
147 | :custom_field_values => { '3' => 'Beta' }, |
|
147 | :custom_field_values => { '3' => 'Beta' }, | |
148 | :tracker_ids => ['1', '3'], |
|
148 | :tracker_ids => ['1', '3'], | |
149 | # an issue custom field that is not for all project |
|
149 | # an issue custom field that is not for all project | |
150 | :issue_custom_field_ids => ['9'], |
|
150 | :issue_custom_field_ids => ['9'], | |
151 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
151 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |
152 | } |
|
152 | } | |
153 | assert_redirected_to '/projects/blog/settings' |
|
153 | assert_redirected_to '/projects/blog/settings' | |
154 |
|
154 | |||
155 | project = Project.find_by_name('blog') |
|
155 | project = Project.find_by_name('blog') | |
156 | assert_kind_of Project, project |
|
156 | assert_kind_of Project, project | |
157 | assert project.active? |
|
157 | assert project.active? | |
158 | assert_equal 'weblog', project.description |
|
158 | assert_equal 'weblog', project.description | |
159 | assert_equal 'http://weblog', project.homepage |
|
159 | assert_equal 'http://weblog', project.homepage | |
160 | assert_equal true, project.is_public? |
|
160 | assert_equal true, project.is_public? | |
161 | assert_nil project.parent |
|
161 | assert_nil project.parent | |
162 | assert_equal 'Beta', project.custom_value_for(3).value |
|
162 | assert_equal 'Beta', project.custom_value_for(3).value | |
163 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
163 | assert_equal [1, 3], project.trackers.map(&:id).sort | |
164 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
164 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |
165 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
|
165 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | should "create a new subproject" do |
|
168 | should "create a new subproject" do | |
169 | post :create, :project => { :name => "blog", |
|
169 | post :create, :project => { :name => "blog", | |
170 | :description => "weblog", |
|
170 | :description => "weblog", | |
171 | :identifier => "blog", |
|
171 | :identifier => "blog", | |
172 | :is_public => 1, |
|
172 | :is_public => 1, | |
173 | :custom_field_values => { '3' => 'Beta' }, |
|
173 | :custom_field_values => { '3' => 'Beta' }, | |
174 | :parent_id => 1 |
|
174 | :parent_id => 1 | |
175 | } |
|
175 | } | |
176 | assert_redirected_to '/projects/blog/settings' |
|
176 | assert_redirected_to '/projects/blog/settings' | |
177 |
|
177 | |||
178 | project = Project.find_by_name('blog') |
|
178 | project = Project.find_by_name('blog') | |
179 | assert_kind_of Project, project |
|
179 | assert_kind_of Project, project | |
180 | assert_equal Project.find(1), project.parent |
|
180 | assert_equal Project.find(1), project.parent | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | should "continue" do |
|
183 | should "continue" do | |
184 | assert_difference 'Project.count' do |
|
184 | assert_difference 'Project.count' do | |
185 | post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' |
|
185 | post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' | |
186 | end |
|
186 | end | |
187 | assert_redirected_to '/projects/new' |
|
187 | assert_redirected_to '/projects/new' | |
188 | end |
|
188 | end | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | context "by non-admin user with add_project permission" do |
|
191 | context "by non-admin user with add_project permission" do | |
192 | setup do |
|
192 | setup do | |
193 | Role.non_member.add_permission! :add_project |
|
193 | Role.non_member.add_permission! :add_project | |
194 | @request.session[:user_id] = 9 |
|
194 | @request.session[:user_id] = 9 | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | should "accept create a Project" do |
|
197 | should "accept create a Project" do | |
198 | post :create, :project => { :name => "blog", |
|
198 | post :create, :project => { :name => "blog", | |
199 | :description => "weblog", |
|
199 | :description => "weblog", | |
200 | :identifier => "blog", |
|
200 | :identifier => "blog", | |
201 | :is_public => 1, |
|
201 | :is_public => 1, | |
202 | :custom_field_values => { '3' => 'Beta' }, |
|
202 | :custom_field_values => { '3' => 'Beta' }, | |
203 | :tracker_ids => ['1', '3'], |
|
203 | :tracker_ids => ['1', '3'], | |
204 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
204 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | assert_redirected_to '/projects/blog/settings' |
|
207 | assert_redirected_to '/projects/blog/settings' | |
208 |
|
208 | |||
209 | project = Project.find_by_name('blog') |
|
209 | project = Project.find_by_name('blog') | |
210 | assert_kind_of Project, project |
|
210 | assert_kind_of Project, project | |
211 | assert_equal 'weblog', project.description |
|
211 | assert_equal 'weblog', project.description | |
212 | assert_equal true, project.is_public? |
|
212 | assert_equal true, project.is_public? | |
213 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
213 | assert_equal [1, 3], project.trackers.map(&:id).sort | |
214 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
214 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |
215 |
|
215 | |||
216 | # User should be added as a project member |
|
216 | # User should be added as a project member | |
217 | assert User.find(9).member_of?(project) |
|
217 | assert User.find(9).member_of?(project) | |
218 | assert_equal 1, project.members.size |
|
218 | assert_equal 1, project.members.size | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | should "fail with parent_id" do |
|
221 | should "fail with parent_id" do | |
222 | assert_no_difference 'Project.count' do |
|
222 | assert_no_difference 'Project.count' do | |
223 | post :create, :project => { :name => "blog", |
|
223 | post :create, :project => { :name => "blog", | |
224 | :description => "weblog", |
|
224 | :description => "weblog", | |
225 | :identifier => "blog", |
|
225 | :identifier => "blog", | |
226 | :is_public => 1, |
|
226 | :is_public => 1, | |
227 | :custom_field_values => { '3' => 'Beta' }, |
|
227 | :custom_field_values => { '3' => 'Beta' }, | |
228 | :parent_id => 1 |
|
228 | :parent_id => 1 | |
229 | } |
|
229 | } | |
230 | end |
|
230 | end | |
231 | assert_response :success |
|
231 | assert_response :success | |
232 | project = assigns(:project) |
|
232 | project = assigns(:project) | |
233 | assert_kind_of Project, project |
|
233 | assert_kind_of Project, project | |
234 | assert_not_nil project.errors[:parent_id] |
|
234 | assert_not_nil project.errors[:parent_id] | |
235 | end |
|
235 | end | |
236 | end |
|
236 | end | |
237 |
|
237 | |||
238 | context "by non-admin user with add_subprojects permission" do |
|
238 | context "by non-admin user with add_subprojects permission" do | |
239 | setup do |
|
239 | setup do | |
240 | Role.find(1).remove_permission! :add_project |
|
240 | Role.find(1).remove_permission! :add_project | |
241 | Role.find(1).add_permission! :add_subprojects |
|
241 | Role.find(1).add_permission! :add_subprojects | |
242 | @request.session[:user_id] = 2 |
|
242 | @request.session[:user_id] = 2 | |
243 | end |
|
243 | end | |
244 |
|
244 | |||
245 | should "create a project with a parent_id" do |
|
245 | should "create a project with a parent_id" do | |
246 | post :create, :project => { :name => "blog", |
|
246 | post :create, :project => { :name => "blog", | |
247 | :description => "weblog", |
|
247 | :description => "weblog", | |
248 | :identifier => "blog", |
|
248 | :identifier => "blog", | |
249 | :is_public => 1, |
|
249 | :is_public => 1, | |
250 | :custom_field_values => { '3' => 'Beta' }, |
|
250 | :custom_field_values => { '3' => 'Beta' }, | |
251 | :parent_id => 1 |
|
251 | :parent_id => 1 | |
252 | } |
|
252 | } | |
253 | assert_redirected_to '/projects/blog/settings' |
|
253 | assert_redirected_to '/projects/blog/settings' | |
254 | project = Project.find_by_name('blog') |
|
254 | project = Project.find_by_name('blog') | |
255 | end |
|
255 | end | |
256 |
|
256 | |||
257 | should "fail without parent_id" do |
|
257 | should "fail without parent_id" do | |
258 | assert_no_difference 'Project.count' do |
|
258 | assert_no_difference 'Project.count' do | |
259 | post :create, :project => { :name => "blog", |
|
259 | post :create, :project => { :name => "blog", | |
260 | :description => "weblog", |
|
260 | :description => "weblog", | |
261 | :identifier => "blog", |
|
261 | :identifier => "blog", | |
262 | :is_public => 1, |
|
262 | :is_public => 1, | |
263 | :custom_field_values => { '3' => 'Beta' } |
|
263 | :custom_field_values => { '3' => 'Beta' } | |
264 | } |
|
264 | } | |
265 | end |
|
265 | end | |
266 | assert_response :success |
|
266 | assert_response :success | |
267 | project = assigns(:project) |
|
267 | project = assigns(:project) | |
268 | assert_kind_of Project, project |
|
268 | assert_kind_of Project, project | |
269 | assert_not_nil project.errors[:parent_id] |
|
269 | assert_not_nil project.errors[:parent_id] | |
270 | end |
|
270 | end | |
271 |
|
271 | |||
272 | should "fail with unauthorized parent_id" do |
|
272 | should "fail with unauthorized parent_id" do | |
273 | assert !User.find(2).member_of?(Project.find(6)) |
|
273 | assert !User.find(2).member_of?(Project.find(6)) | |
274 | assert_no_difference 'Project.count' do |
|
274 | assert_no_difference 'Project.count' do | |
275 | post :create, :project => { :name => "blog", |
|
275 | post :create, :project => { :name => "blog", | |
276 | :description => "weblog", |
|
276 | :description => "weblog", | |
277 | :identifier => "blog", |
|
277 | :identifier => "blog", | |
278 | :is_public => 1, |
|
278 | :is_public => 1, | |
279 | :custom_field_values => { '3' => 'Beta' }, |
|
279 | :custom_field_values => { '3' => 'Beta' }, | |
280 | :parent_id => 6 |
|
280 | :parent_id => 6 | |
281 | } |
|
281 | } | |
282 | end |
|
282 | end | |
283 | assert_response :success |
|
283 | assert_response :success | |
284 | project = assigns(:project) |
|
284 | project = assigns(:project) | |
285 | assert_kind_of Project, project |
|
285 | assert_kind_of Project, project | |
286 | assert_not_nil project.errors[:parent_id] |
|
286 | assert_not_nil project.errors[:parent_id] | |
287 | end |
|
287 | end | |
288 | end |
|
288 | end | |
289 | end |
|
289 | end | |
290 |
|
290 | |||
291 | def test_create_subproject_with_inherit_members_should_inherit_members |
|
291 | def test_create_subproject_with_inherit_members_should_inherit_members | |
292 | Role.find_by_name('Manager').add_permission! :add_subprojects |
|
292 | Role.find_by_name('Manager').add_permission! :add_subprojects | |
293 | parent = Project.find(1) |
|
293 | parent = Project.find(1) | |
294 | @request.session[:user_id] = 2 |
|
294 | @request.session[:user_id] = 2 | |
295 |
|
295 | |||
296 | assert_difference 'Project.count' do |
|
296 | assert_difference 'Project.count' do | |
297 | post :create, :project => { |
|
297 | post :create, :project => { | |
298 | :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' |
|
298 | :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' | |
299 | } |
|
299 | } | |
300 | assert_response 302 |
|
300 | assert_response 302 | |
301 | end |
|
301 | end | |
302 |
|
302 | |||
303 | project = Project.order('id desc').first |
|
303 | project = Project.order('id desc').first | |
304 | assert_equal 'inherited', project.name |
|
304 | assert_equal 'inherited', project.name | |
305 | assert_equal parent, project.parent |
|
305 | assert_equal parent, project.parent | |
306 | assert project.memberships.count > 0 |
|
306 | assert project.memberships.count > 0 | |
307 | assert_equal parent.memberships.count, project.memberships.count |
|
307 | assert_equal parent.memberships.count, project.memberships.count | |
308 | end |
|
308 | end | |
309 |
|
309 | |||
310 | def test_create_should_preserve_modules_on_validation_failure |
|
310 | def test_create_should_preserve_modules_on_validation_failure | |
311 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
311 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
312 | @request.session[:user_id] = 1 |
|
312 | @request.session[:user_id] = 1 | |
313 | assert_no_difference 'Project.count' do |
|
313 | assert_no_difference 'Project.count' do | |
314 | post :create, :project => { |
|
314 | post :create, :project => { | |
315 | :name => "blog", |
|
315 | :name => "blog", | |
316 | :identifier => "", |
|
316 | :identifier => "", | |
317 | :enabled_module_names => %w(issue_tracking news) |
|
317 | :enabled_module_names => %w(issue_tracking news) | |
318 | } |
|
318 | } | |
319 | end |
|
319 | end | |
320 | assert_response :success |
|
320 | assert_response :success | |
321 | project = assigns(:project) |
|
321 | project = assigns(:project) | |
322 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
322 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort | |
323 | end |
|
323 | end | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | def test_show_by_id |
|
326 | def test_show_by_id | |
327 | get :show, :id => 1 |
|
327 | get :show, :id => 1 | |
328 | assert_response :success |
|
328 | assert_response :success | |
329 | assert_template 'show' |
|
329 | assert_template 'show' | |
330 | assert_not_nil assigns(:project) |
|
330 | assert_not_nil assigns(:project) | |
331 | end |
|
331 | end | |
332 |
|
332 | |||
333 | def test_show_by_identifier |
|
333 | def test_show_by_identifier | |
334 | get :show, :id => 'ecookbook' |
|
334 | get :show, :id => 'ecookbook' | |
335 | assert_response :success |
|
335 | assert_response :success | |
336 | assert_template 'show' |
|
336 | assert_template 'show' | |
337 | assert_not_nil assigns(:project) |
|
337 | assert_not_nil assigns(:project) | |
338 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
338 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
339 |
|
339 | |||
340 | assert_tag 'li', :content => /Development status/ |
|
340 | assert_tag 'li', :content => /Development status/ | |
341 | end |
|
341 | end | |
342 |
|
342 | |||
343 | def test_show_should_not_display_hidden_custom_fields |
|
343 | def test_show_should_not_display_hidden_custom_fields | |
344 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false |
|
344 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false | |
345 | get :show, :id => 'ecookbook' |
|
345 | get :show, :id => 'ecookbook' | |
346 | assert_response :success |
|
346 | assert_response :success | |
347 | assert_template 'show' |
|
347 | assert_template 'show' | |
348 | assert_not_nil assigns(:project) |
|
348 | assert_not_nil assigns(:project) | |
349 |
|
349 | |||
350 | assert_no_tag 'li', :content => /Development status/ |
|
350 | assert_no_tag 'li', :content => /Development status/ | |
351 | end |
|
351 | end | |
352 |
|
352 | |||
353 | def test_show_should_not_fail_when_custom_values_are_nil |
|
353 | def test_show_should_not_fail_when_custom_values_are_nil | |
354 | project = Project.find_by_identifier('ecookbook') |
|
354 | project = Project.find_by_identifier('ecookbook') | |
355 | project.custom_values.first.update_attribute(:value, nil) |
|
355 | project.custom_values.first.update_attribute(:value, nil) | |
356 | get :show, :id => 'ecookbook' |
|
356 | get :show, :id => 'ecookbook' | |
357 | assert_response :success |
|
357 | assert_response :success | |
358 | assert_template 'show' |
|
358 | assert_template 'show' | |
359 | assert_not_nil assigns(:project) |
|
359 | assert_not_nil assigns(:project) | |
360 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
360 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
361 | end |
|
361 | end | |
362 |
|
362 | |||
363 | def show_archived_project_should_be_denied |
|
363 | def show_archived_project_should_be_denied | |
364 | project = Project.find_by_identifier('ecookbook') |
|
364 | project = Project.find_by_identifier('ecookbook') | |
365 | project.archive! |
|
365 | project.archive! | |
366 |
|
366 | |||
367 | get :show, :id => 'ecookbook' |
|
367 | get :show, :id => 'ecookbook' | |
368 | assert_response 403 |
|
368 | assert_response 403 | |
369 | assert_nil assigns(:project) |
|
369 | assert_nil assigns(:project) | |
370 | assert_tag :tag => 'p', :content => /archived/ |
|
370 | assert_tag :tag => 'p', :content => /archived/ | |
371 | end |
|
371 | end | |
372 |
|
372 | |||
373 | def test_private_subprojects_hidden |
|
373 | def test_private_subprojects_hidden | |
374 | get :show, :id => 'ecookbook' |
|
374 | get :show, :id => 'ecookbook' | |
375 | assert_response :success |
|
375 | assert_response :success | |
376 | assert_template 'show' |
|
376 | assert_template 'show' | |
377 | assert_no_tag :tag => 'a', :content => /Private child/ |
|
377 | assert_no_tag :tag => 'a', :content => /Private child/ | |
378 | end |
|
378 | end | |
379 |
|
379 | |||
380 | def test_private_subprojects_visible |
|
380 | def test_private_subprojects_visible | |
381 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
381 | @request.session[:user_id] = 2 # manager who is a member of the private subproject | |
382 | get :show, :id => 'ecookbook' |
|
382 | get :show, :id => 'ecookbook' | |
383 | assert_response :success |
|
383 | assert_response :success | |
384 | assert_template 'show' |
|
384 | assert_template 'show' | |
385 | assert_tag :tag => 'a', :content => /Private child/ |
|
385 | assert_tag :tag => 'a', :content => /Private child/ | |
386 | end |
|
386 | end | |
387 |
|
387 | |||
388 | def test_settings |
|
388 | def test_settings | |
389 | @request.session[:user_id] = 2 # manager |
|
389 | @request.session[:user_id] = 2 # manager | |
390 | get :settings, :id => 1 |
|
390 | get :settings, :id => 1 | |
391 | assert_response :success |
|
391 | assert_response :success | |
392 | assert_template 'settings' |
|
392 | assert_template 'settings' | |
393 | end |
|
393 | end | |
394 |
|
394 | |||
395 | def test_settings_of_subproject |
|
395 | def test_settings_of_subproject | |
396 | @request.session[:user_id] = 2 |
|
396 | @request.session[:user_id] = 2 | |
397 | get :settings, :id => 'private-child' |
|
397 | get :settings, :id => 'private-child' | |
398 | assert_response :success |
|
398 | assert_response :success | |
399 | assert_template 'settings' |
|
399 | assert_template 'settings' | |
|
400 | ||||
|
401 | assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]' | |||
400 | end |
|
402 | end | |
401 |
|
403 | |||
402 | def test_settings_should_be_denied_for_member_on_closed_project |
|
404 | def test_settings_should_be_denied_for_member_on_closed_project | |
403 | Project.find(1).close |
|
405 | Project.find(1).close | |
404 | @request.session[:user_id] = 2 # manager |
|
406 | @request.session[:user_id] = 2 # manager | |
405 |
|
407 | |||
406 | get :settings, :id => 1 |
|
408 | get :settings, :id => 1 | |
407 | assert_response 403 |
|
409 | assert_response 403 | |
408 | end |
|
410 | end | |
409 |
|
411 | |||
410 | def test_settings_should_be_denied_for_anonymous_on_closed_project |
|
412 | def test_settings_should_be_denied_for_anonymous_on_closed_project | |
411 | Project.find(1).close |
|
413 | Project.find(1).close | |
412 |
|
414 | |||
413 | get :settings, :id => 1 |
|
415 | get :settings, :id => 1 | |
414 | assert_response 302 |
|
416 | assert_response 302 | |
415 | end |
|
417 | end | |
416 |
|
418 | |||
417 | def test_update |
|
419 | def test_update | |
418 | @request.session[:user_id] = 2 # manager |
|
420 | @request.session[:user_id] = 2 # manager | |
419 | post :update, :id => 1, :project => {:name => 'Test changed name', |
|
421 | post :update, :id => 1, :project => {:name => 'Test changed name', | |
420 | :issue_custom_field_ids => ['']} |
|
422 | :issue_custom_field_ids => ['']} | |
421 | assert_redirected_to '/projects/ecookbook/settings' |
|
423 | assert_redirected_to '/projects/ecookbook/settings' | |
422 | project = Project.find(1) |
|
424 | project = Project.find(1) | |
423 | assert_equal 'Test changed name', project.name |
|
425 | assert_equal 'Test changed name', project.name | |
424 | end |
|
426 | end | |
425 |
|
427 | |||
426 | def test_update_with_failure |
|
428 | def test_update_with_failure | |
427 | @request.session[:user_id] = 2 # manager |
|
429 | @request.session[:user_id] = 2 # manager | |
428 | post :update, :id => 1, :project => {:name => ''} |
|
430 | post :update, :id => 1, :project => {:name => ''} | |
429 | assert_response :success |
|
431 | assert_response :success | |
430 | assert_template 'settings' |
|
432 | assert_template 'settings' | |
431 | assert_error_tag :content => /name can't be blank/i |
|
433 | assert_error_tag :content => /name can't be blank/i | |
432 | end |
|
434 | end | |
433 |
|
435 | |||
434 | def test_update_should_be_denied_for_member_on_closed_project |
|
436 | def test_update_should_be_denied_for_member_on_closed_project | |
435 | Project.find(1).close |
|
437 | Project.find(1).close | |
436 | @request.session[:user_id] = 2 # manager |
|
438 | @request.session[:user_id] = 2 # manager | |
437 |
|
439 | |||
438 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
440 | post :update, :id => 1, :project => {:name => 'Closed'} | |
439 | assert_response 403 |
|
441 | assert_response 403 | |
440 | assert_equal 'eCookbook', Project.find(1).name |
|
442 | assert_equal 'eCookbook', Project.find(1).name | |
441 | end |
|
443 | end | |
442 |
|
444 | |||
443 | def test_update_should_be_denied_for_anonymous_on_closed_project |
|
445 | def test_update_should_be_denied_for_anonymous_on_closed_project | |
444 | Project.find(1).close |
|
446 | Project.find(1).close | |
445 |
|
447 | |||
446 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
448 | post :update, :id => 1, :project => {:name => 'Closed'} | |
447 | assert_response 302 |
|
449 | assert_response 302 | |
448 | assert_equal 'eCookbook', Project.find(1).name |
|
450 | assert_equal 'eCookbook', Project.find(1).name | |
449 | end |
|
451 | end | |
450 |
|
452 | |||
451 | def test_modules |
|
453 | def test_modules | |
452 | @request.session[:user_id] = 2 |
|
454 | @request.session[:user_id] = 2 | |
453 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
|
455 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] | |
454 |
|
456 | |||
455 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] |
|
457 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] | |
456 | assert_redirected_to '/projects/ecookbook/settings/modules' |
|
458 | assert_redirected_to '/projects/ecookbook/settings/modules' | |
457 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort |
|
459 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort | |
458 | end |
|
460 | end | |
459 |
|
461 | |||
460 | def test_destroy_without_confirmation |
|
462 | def test_destroy_without_confirmation | |
461 | @request.session[:user_id] = 1 # admin |
|
463 | @request.session[:user_id] = 1 # admin | |
462 | delete :destroy, :id => 1 |
|
464 | delete :destroy, :id => 1 | |
463 | assert_response :success |
|
465 | assert_response :success | |
464 | assert_template 'destroy' |
|
466 | assert_template 'destroy' | |
465 | assert_not_nil Project.find_by_id(1) |
|
467 | assert_not_nil Project.find_by_id(1) | |
466 | assert_tag :tag => 'strong', |
|
468 | assert_tag :tag => 'strong', | |
467 | :content => ['Private child of eCookbook', |
|
469 | :content => ['Private child of eCookbook', | |
468 | 'Child of private child, eCookbook Subproject 1', |
|
470 | 'Child of private child, eCookbook Subproject 1', | |
469 | 'eCookbook Subproject 2'].join(', ') |
|
471 | 'eCookbook Subproject 2'].join(', ') | |
470 | end |
|
472 | end | |
471 |
|
473 | |||
472 | def test_destroy |
|
474 | def test_destroy | |
473 | @request.session[:user_id] = 1 # admin |
|
475 | @request.session[:user_id] = 1 # admin | |
474 | delete :destroy, :id => 1, :confirm => 1 |
|
476 | delete :destroy, :id => 1, :confirm => 1 | |
475 | assert_redirected_to '/admin/projects' |
|
477 | assert_redirected_to '/admin/projects' | |
476 | assert_nil Project.find_by_id(1) |
|
478 | assert_nil Project.find_by_id(1) | |
477 | end |
|
479 | end | |
478 |
|
480 | |||
479 | def test_archive |
|
481 | def test_archive | |
480 | @request.session[:user_id] = 1 # admin |
|
482 | @request.session[:user_id] = 1 # admin | |
481 | post :archive, :id => 1 |
|
483 | post :archive, :id => 1 | |
482 | assert_redirected_to '/admin/projects' |
|
484 | assert_redirected_to '/admin/projects' | |
483 | assert !Project.find(1).active? |
|
485 | assert !Project.find(1).active? | |
484 | end |
|
486 | end | |
485 |
|
487 | |||
486 | def test_archive_with_failure |
|
488 | def test_archive_with_failure | |
487 | @request.session[:user_id] = 1 |
|
489 | @request.session[:user_id] = 1 | |
488 | Project.any_instance.stubs(:archive).returns(false) |
|
490 | Project.any_instance.stubs(:archive).returns(false) | |
489 | post :archive, :id => 1 |
|
491 | post :archive, :id => 1 | |
490 | assert_redirected_to '/admin/projects' |
|
492 | assert_redirected_to '/admin/projects' | |
491 | assert_match /project cannot be archived/i, flash[:error] |
|
493 | assert_match /project cannot be archived/i, flash[:error] | |
492 | end |
|
494 | end | |
493 |
|
495 | |||
494 | def test_unarchive |
|
496 | def test_unarchive | |
495 | @request.session[:user_id] = 1 # admin |
|
497 | @request.session[:user_id] = 1 # admin | |
496 | Project.find(1).archive |
|
498 | Project.find(1).archive | |
497 | post :unarchive, :id => 1 |
|
499 | post :unarchive, :id => 1 | |
498 | assert_redirected_to '/admin/projects' |
|
500 | assert_redirected_to '/admin/projects' | |
499 | assert Project.find(1).active? |
|
501 | assert Project.find(1).active? | |
500 | end |
|
502 | end | |
501 |
|
503 | |||
502 | def test_close |
|
504 | def test_close | |
503 | @request.session[:user_id] = 2 |
|
505 | @request.session[:user_id] = 2 | |
504 | post :close, :id => 1 |
|
506 | post :close, :id => 1 | |
505 | assert_redirected_to '/projects/ecookbook' |
|
507 | assert_redirected_to '/projects/ecookbook' | |
506 | assert_equal Project::STATUS_CLOSED, Project.find(1).status |
|
508 | assert_equal Project::STATUS_CLOSED, Project.find(1).status | |
507 | end |
|
509 | end | |
508 |
|
510 | |||
509 | def test_reopen |
|
511 | def test_reopen | |
510 | Project.find(1).close |
|
512 | Project.find(1).close | |
511 | @request.session[:user_id] = 2 |
|
513 | @request.session[:user_id] = 2 | |
512 | post :reopen, :id => 1 |
|
514 | post :reopen, :id => 1 | |
513 | assert_redirected_to '/projects/ecookbook' |
|
515 | assert_redirected_to '/projects/ecookbook' | |
514 | assert Project.find(1).active? |
|
516 | assert Project.find(1).active? | |
515 | end |
|
517 | end | |
516 |
|
518 | |||
517 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
|
519 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors | |
518 | CustomField.delete_all |
|
520 | CustomField.delete_all | |
519 | parent = nil |
|
521 | parent = nil | |
520 | 6.times do |i| |
|
522 | 6.times do |i| | |
521 | p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") |
|
523 | p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") | |
522 | p.set_parent!(parent) |
|
524 | p.set_parent!(parent) | |
523 | get :show, :id => p |
|
525 | get :show, :id => p | |
524 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, |
|
526 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, | |
525 | :children => { :count => [i, 3].min, |
|
527 | :children => { :count => [i, 3].min, | |
526 | :only => { :tag => 'a' } } |
|
528 | :only => { :tag => 'a' } } | |
527 |
|
529 | |||
528 | parent = p |
|
530 | parent = p | |
529 | end |
|
531 | end | |
530 | end |
|
532 | end | |
531 |
|
533 | |||
532 | def test_get_copy |
|
534 | def test_get_copy | |
533 | @request.session[:user_id] = 1 # admin |
|
535 | @request.session[:user_id] = 1 # admin | |
534 | get :copy, :id => 1 |
|
536 | get :copy, :id => 1 | |
535 | assert_response :success |
|
537 | assert_response :success | |
536 | assert_template 'copy' |
|
538 | assert_template 'copy' | |
537 | assert assigns(:project) |
|
539 | assert assigns(:project) | |
538 | assert_equal Project.find(1).description, assigns(:project).description |
|
540 | assert_equal Project.find(1).description, assigns(:project).description | |
539 | assert_nil assigns(:project).id |
|
541 | assert_nil assigns(:project).id | |
540 |
|
542 | |||
541 | assert_tag :tag => 'input', |
|
543 | assert_tag :tag => 'input', | |
542 | :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'} |
|
544 | :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'} | |
543 | end |
|
545 | end | |
544 |
|
546 | |||
545 | def test_get_copy_with_invalid_source_should_respond_with_404 |
|
547 | def test_get_copy_with_invalid_source_should_respond_with_404 | |
546 | @request.session[:user_id] = 1 |
|
548 | @request.session[:user_id] = 1 | |
547 | get :copy, :id => 99 |
|
549 | get :copy, :id => 99 | |
548 | assert_response 404 |
|
550 | assert_response 404 | |
549 | end |
|
551 | end | |
550 |
|
552 | |||
551 | def test_post_copy_should_copy_requested_items |
|
553 | def test_post_copy_should_copy_requested_items | |
552 | @request.session[:user_id] = 1 # admin |
|
554 | @request.session[:user_id] = 1 # admin | |
553 | CustomField.delete_all |
|
555 | CustomField.delete_all | |
554 |
|
556 | |||
555 | assert_difference 'Project.count' do |
|
557 | assert_difference 'Project.count' do | |
556 | post :copy, :id => 1, |
|
558 | post :copy, :id => 1, | |
557 | :project => { |
|
559 | :project => { | |
558 | :name => 'Copy', |
|
560 | :name => 'Copy', | |
559 | :identifier => 'unique-copy', |
|
561 | :identifier => 'unique-copy', | |
560 | :tracker_ids => ['1', '2', '3', ''], |
|
562 | :tracker_ids => ['1', '2', '3', ''], | |
561 | :enabled_module_names => %w(issue_tracking time_tracking) |
|
563 | :enabled_module_names => %w(issue_tracking time_tracking) | |
562 | }, |
|
564 | }, | |
563 | :only => %w(issues versions) |
|
565 | :only => %w(issues versions) | |
564 | end |
|
566 | end | |
565 | project = Project.find('unique-copy') |
|
567 | project = Project.find('unique-copy') | |
566 | source = Project.find(1) |
|
568 | source = Project.find(1) | |
567 | assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort |
|
569 | assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort | |
568 |
|
570 | |||
569 | assert_equal source.versions.count, project.versions.count, "All versions were not copied" |
|
571 | assert_equal source.versions.count, project.versions.count, "All versions were not copied" | |
570 | assert_equal source.issues.count, project.issues.count, "All issues were not copied" |
|
572 | assert_equal source.issues.count, project.issues.count, "All issues were not copied" | |
571 | assert_equal 0, project.members.count |
|
573 | assert_equal 0, project.members.count | |
572 | end |
|
574 | end | |
573 |
|
575 | |||
574 | def test_post_copy_should_redirect_to_settings_when_successful |
|
576 | def test_post_copy_should_redirect_to_settings_when_successful | |
575 | @request.session[:user_id] = 1 # admin |
|
577 | @request.session[:user_id] = 1 # admin | |
576 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} |
|
578 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} | |
577 | assert_response :redirect |
|
579 | assert_response :redirect | |
578 | assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' |
|
580 | assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' | |
579 | end |
|
581 | end | |
580 |
|
582 | |||
581 | def test_jump_should_redirect_to_active_tab |
|
583 | def test_jump_should_redirect_to_active_tab | |
582 | get :show, :id => 1, :jump => 'issues' |
|
584 | get :show, :id => 1, :jump => 'issues' | |
583 | assert_redirected_to '/projects/ecookbook/issues' |
|
585 | assert_redirected_to '/projects/ecookbook/issues' | |
584 | end |
|
586 | end | |
585 |
|
587 | |||
586 | def test_jump_should_not_redirect_to_inactive_tab |
|
588 | def test_jump_should_not_redirect_to_inactive_tab | |
587 | get :show, :id => 3, :jump => 'documents' |
|
589 | get :show, :id => 3, :jump => 'documents' | |
588 | assert_response :success |
|
590 | assert_response :success | |
589 | assert_template 'show' |
|
591 | assert_template 'show' | |
590 | end |
|
592 | end | |
591 |
|
593 | |||
592 | def test_jump_should_not_redirect_to_unknown_tab |
|
594 | def test_jump_should_not_redirect_to_unknown_tab | |
593 | get :show, :id => 3, :jump => 'foobar' |
|
595 | get :show, :id => 3, :jump => 'foobar' | |
594 | assert_response :success |
|
596 | assert_response :success | |
595 | assert_template 'show' |
|
597 | assert_template 'show' | |
596 | end |
|
598 | end | |
597 | end |
|
599 | end |
General Comments 0
You need to be logged in to leave comments.
Login now