@@ -32,9 +32,6 class ProjectsController < ApplicationController | |||||
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | # TODO: convert to PUT only |
|
|||
36 | verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
|||
37 |
|
||||
38 | helper :sort |
|
35 | helper :sort | |
39 | include SortHelper |
|
36 | include SortHelper | |
40 | helper :custom_fields |
|
37 | helper :custom_fields | |
@@ -71,13 +68,13 class ProjectsController < ApplicationController | |||||
71 | @project = Project.new(params[:project]) |
|
68 | @project = Project.new(params[:project]) | |
72 | end |
|
69 | end | |
73 |
|
70 | |||
|
71 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |||
74 | def create |
|
72 | def create | |
75 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
73 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
76 | @trackers = Tracker.all |
|
74 | @trackers = Tracker.all | |
77 | @project = Project.new |
|
75 | @project = Project.new | |
78 | @project.safe_attributes = params[:project] |
|
76 | @project.safe_attributes = params[:project] | |
79 |
|
77 | |||
80 | @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules] |
|
|||
81 | if validate_parent_id && @project.save |
|
78 | if validate_parent_id && @project.save | |
82 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
|
79 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
83 | # Add current user as a project member if he is not admin |
|
80 | # Add current user as a project member if he is not admin | |
@@ -184,6 +181,8 class ProjectsController < ApplicationController | |||||
184 | def edit |
|
181 | def edit | |
185 | end |
|
182 | end | |
186 |
|
183 | |||
|
184 | # TODO: convert to PUT only | |||
|
185 | verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |||
187 | def update |
|
186 | def update | |
188 | @project.safe_attributes = params[:project] |
|
187 | @project.safe_attributes = params[:project] | |
189 | if validate_parent_id && @project.save |
|
188 | if validate_parent_id && @project.save | |
@@ -205,9 +204,10 class ProjectsController < ApplicationController | |||||
205 | end |
|
204 | end | |
206 | end |
|
205 | end | |
207 | end |
|
206 | end | |
208 |
|
207 | |||
|
208 | verify :method => :post, :only => :modules, :render => {:nothing => true, :status => :method_not_allowed } | |||
209 | def modules |
|
209 | def modules | |
210 | @project.enabled_module_names = params[:enabled_modules] |
|
210 | @project.enabled_module_names = params[:enabled_module_names] | |
211 | flash[:notice] = l(:notice_successful_update) |
|
211 | flash[:notice] = l(:notice_successful_update) | |
212 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
212 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' | |
213 | end |
|
213 | end |
@@ -66,7 +66,7 class Project < ActiveRecord::Base | |||||
66 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}}, |
|
66 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}}, | |
67 | :author => nil |
|
67 | :author => nil | |
68 |
|
68 | |||
69 |
attr_protected :status |
|
69 | attr_protected :status | |
70 |
|
70 | |||
71 | validates_presence_of :name, :identifier |
|
71 | validates_presence_of :name, :identifier | |
72 | validates_uniqueness_of :identifier |
|
72 | validates_uniqueness_of :identifier | |
@@ -533,6 +533,9 class Project < ActiveRecord::Base | |||||
533 | 'tracker_ids', |
|
533 | 'tracker_ids', | |
534 | 'issue_custom_field_ids' |
|
534 | 'issue_custom_field_ids' | |
535 |
|
535 | |||
|
536 | safe_attributes 'enabled_module_names', | |||
|
537 | :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) } | |||
|
538 | ||||
536 | # Returns an array of projects that are in this project's hierarchy |
|
539 | # Returns an array of projects that are in this project's hierarchy | |
537 | # |
|
540 | # | |
538 | # Example: parents, children, siblings |
|
541 | # Example: parents, children, siblings |
@@ -23,8 +23,22 | |||||
23 | <%= call_hook(:view_projects_form, :project => @project, :form => f) %> |
|
23 | <%= call_hook(:view_projects_form, :project => @project, :form => f) %> | |
24 | </div> |
|
24 | </div> | |
25 |
|
25 | |||
|
26 | <% if @project.new_record? %> | |||
|
27 | <fieldset class="box"><legend><%= l(:label_module_plural) %></legend> | |||
|
28 | <% Redmine::AccessControl.available_project_modules.each do |m| %> | |||
|
29 | <label class="floating"> | |||
|
30 | <%= check_box_tag 'project[enabled_module_names][]', m, @project.module_enabled?(m), :id => "project_enabled_module_names_#{m}" %> | |||
|
31 | <%= l_or_humanize(m, :prefix => "project_module_") %> | |||
|
32 | </label> | |||
|
33 | <% end %> | |||
|
34 | <%= hidden_field_tag 'project[enabled_module_names][]', '' %> | |||
|
35 | <%= javascript_tag 'observeProjectModules()' %> | |||
|
36 | </fieldset> | |||
|
37 | <% end %> | |||
|
38 | ||||
|
39 | <% if @project.new_record? || @project.module_enabled?('issue_tracking') %> | |||
26 | <% unless @trackers.empty? %> |
|
40 | <% unless @trackers.empty? %> | |
27 | <fieldset class="box"><legend><%=l(:label_tracker_plural)%></legend> |
|
41 | <fieldset class="box" id="project_trackers"><legend><%=l(:label_tracker_plural)%></legend> | |
28 | <% @trackers.each do |tracker| %> |
|
42 | <% @trackers.each do |tracker| %> | |
29 | <label class="floating"> |
|
43 | <label class="floating"> | |
30 | <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %> |
|
44 | <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %> | |
@@ -36,7 +50,7 | |||||
36 | <% end %> |
|
50 | <% end %> | |
37 |
|
51 | |||
38 | <% unless @issue_custom_fields.empty? %> |
|
52 | <% unless @issue_custom_fields.empty? %> | |
39 | <fieldset class="box"><legend><%=l(:label_custom_field_plural)%></legend> |
|
53 | <fieldset class="box" id="project_issue_custom_fields"><legend><%=l(:label_custom_field_plural)%></legend> | |
40 | <% @issue_custom_fields.each do |custom_field| %> |
|
54 | <% @issue_custom_fields.each do |custom_field| %> | |
41 | <label class="floating"> |
|
55 | <label class="floating"> | |
42 | <%= 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"} : {}) %> |
|
56 | <%= 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"} : {}) %> | |
@@ -46,4 +60,5 | |||||
46 | <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %> |
|
60 | <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %> | |
47 | </fieldset> |
|
61 | </fieldset> | |
48 | <% end %> |
|
62 | <% end %> | |
|
63 | <% end %> | |||
49 | <!--[eoform:project]--> |
|
64 | <!--[eoform:project]--> |
@@ -2,18 +2,6 | |||||
2 |
|
2 | |||
3 | <% labelled_tabular_form_for :project, @project, :url => { :action => "create" } do |f| %> |
|
3 | <% labelled_tabular_form_for :project, @project, :url => { :action => "create" } do |f| %> | |
4 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
4 | <%= render :partial => 'form', :locals => { :f => f } %> | |
5 |
|
||||
6 | <fieldset class="box"><legend><%= l(:label_module_plural) %></legend> |
|
|||
7 | <% Redmine::AccessControl.available_project_modules.each do |m| %> |
|
|||
8 | <label class="floating"> |
|
|||
9 | <%= check_box_tag 'enabled_modules[]', m, @project.module_enabled?(m) %> |
|
|||
10 | <%= l_or_humanize(m, :prefix => "project_module_") %> |
|
|||
11 | </label> |
|
|||
12 | <% end %> |
|
|||
13 | <%= hidden_field_tag 'enabled_modules[]', '' %> |
|
|||
14 |
|
||||
15 | </fieldset> |
|
|||
16 |
|
||||
17 | <%= submit_tag l(:button_save) %> |
|
5 | <%= submit_tag l(:button_save) %> | |
18 | <%= javascript_tag "Form.Element.focus('project_name');" %> |
|
6 | <%= javascript_tag "Form.Element.focus('project_name');" %> | |
19 | <% end %> |
|
7 | <% end %> |
@@ -7,7 +7,7 | |||||
7 | <legend><%= l(:text_select_project_modules) %></legend> |
|
7 | <legend><%= l(:text_select_project_modules) %></legend> | |
8 |
|
8 | |||
9 | <% Redmine::AccessControl.available_project_modules.each do |m| %> |
|
9 | <% Redmine::AccessControl.available_project_modules.each do |m| %> | |
10 | <p><label><%= check_box_tag 'enabled_modules[]', m, @project.module_enabled?(m) -%> |
|
10 | <p><label><%= check_box_tag 'enabled_module_names[]', m, @project.module_enabled?(m) -%> | |
11 | <%= l_or_humanize(m, :prefix => "project_module_") %></label></p> |
|
11 | <%= l_or_humanize(m, :prefix => "project_module_") %></label></p> | |
12 | <% end %> |
|
12 | <% end %> | |
13 | </fieldset> |
|
13 | </fieldset> |
@@ -4,7 +4,7 | |||||
4 |
|
4 | |||
5 | <% form_tag({:action => "diff"}, :method => :get) do %> |
|
5 | <% form_tag({:action => "diff"}, :method => :get) do %> | |
6 | <%= hidden_field_tag('project_id', h(@project.to_param)) %> |
|
6 | <%= hidden_field_tag('project_id', h(@project.to_param)) %> | |
7 | <table class="list"> |
|
7 | <table class="list wiki-page-versions"> | |
8 | <thead><tr> |
|
8 | <thead><tr> | |
9 | <th>#</th> |
|
9 | <th>#</th> | |
10 | <th></th> |
|
10 | <th></th> | |
@@ -18,14 +18,14 | |||||
18 | <% show_diff = @versions.size > 1 %> |
|
18 | <% show_diff = @versions.size > 1 %> | |
19 | <% line_num = 1 %> |
|
19 | <% line_num = 1 %> | |
20 | <% @versions.each do |ver| %> |
|
20 | <% @versions.each do |ver| %> | |
21 | <tr class="<%= cycle("odd", "even") %>"> |
|
21 | <tr class="wiki-page-version <%= cycle("odd", "even") %>"> | |
22 | <td class="id"><%= link_to ver.version, :action => 'show', :id => @page.title, :project_id => @page.project, :version => ver.version %></td> |
|
22 | <td class="id"><%= link_to ver.version, :action => 'show', :id => @page.title, :project_id => @page.project, :version => ver.version %></td> | |
23 | <td class="checkbox"><%= radio_button_tag('version', ver.version, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < @versions.size) %></td> |
|
23 | <td class="checkbox"><%= radio_button_tag('version', ver.version, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < @versions.size) %></td> | |
24 | <td class="checkbox"><%= radio_button_tag('version_from', ver.version, (line_num==2), :id => "cbto-#{line_num}") if show_diff && (line_num > 1) %></td> |
|
24 | <td class="checkbox"><%= radio_button_tag('version_from', ver.version, (line_num==2), :id => "cbto-#{line_num}") if show_diff && (line_num > 1) %></td> | |
25 |
<td |
|
25 | <td class="updated_on"><%= format_time(ver.updated_on) %></td> | |
26 | <td><%= link_to_user ver.author %></td> |
|
26 | <td class="author"><%= link_to_user ver.author %></td> | |
27 | <td><%=h ver.comments %></td> |
|
27 | <td class="comments"><%=h ver.comments %></td> | |
28 |
<td |
|
28 | <td class="buttons"><%= link_to l(:button_annotate), :action => 'annotate', :id => @page.title, :version => ver.version %></td> | |
29 | </tr> |
|
29 | </tr> | |
30 | <% line_num += 1 %> |
|
30 | <% line_num += 1 %> | |
31 | <% end %> |
|
31 | <% end %> |
@@ -232,6 +232,24 function observeRelatedIssueField(url) { | |||||
232 | }); |
|
232 | }); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
|
235 | function setVisible(id, visible) { | |||
|
236 | var el = $(id); | |||
|
237 | if (el) {if (visible) {el.show();} else {el.hide();}} | |||
|
238 | } | |||
|
239 | ||||
|
240 | function observeProjectModules() { | |||
|
241 | var f = function() { | |||
|
242 | /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */ | |||
|
243 | var c = ($('project_enabled_module_names_issue_tracking').checked == true); | |||
|
244 | setVisible('project_trackers', c); | |||
|
245 | setVisible('project_issue_custom_fields', c); | |||
|
246 | }; | |||
|
247 | ||||
|
248 | Event.observe(window, 'load', f); | |||
|
249 | Event.observe('project_enabled_module_names_issue_tracking', 'change', f); | |||
|
250 | } | |||
|
251 | ||||
|
252 | ||||
235 | /* shows and hides ajax indicator */ |
|
253 | /* shows and hides ajax indicator */ | |
236 | Ajax.Responders.register({ |
|
254 | Ajax.Responders.register({ | |
237 | onCreate: function(){ |
|
255 | onCreate: function(){ |
@@ -179,6 +179,8 tr.user td { white-space: nowrap; } | |||||
179 | tr.user.locked, tr.user.registered { color: #aaa; } |
|
179 | tr.user.locked, tr.user.registered { color: #aaa; } | |
180 | tr.user.locked a, tr.user.registered a { color: #aaa; } |
|
180 | tr.user.locked a, tr.user.registered a { color: #aaa; } | |
181 |
|
181 | |||
|
182 | tr.wiki-page-version td.updated_on, tr.wiki-page-version td.author {text-align:center;} | |||
|
183 | ||||
182 | tr.time-entry { text-align: center; white-space: nowrap; } |
|
184 | tr.time-entry { text-align: center; white-space: nowrap; } | |
183 | tr.time-entry td.subject, tr.time-entry td.comments { text-align: left; white-space: normal; } |
|
185 | tr.time-entry td.subject, tr.time-entry td.comments { text-align: left; white-space: normal; } | |
184 | td.hours { text-align: right; font-weight: bold; padding-right: 0.5em; } |
|
186 | td.hours { text-align: right; font-weight: bold; padding-right: 0.5em; } |
@@ -7,6 +7,7 roles_001: | |||||
7 | --- |
|
7 | --- | |
8 | - :add_project |
|
8 | - :add_project | |
9 | - :edit_project |
|
9 | - :edit_project | |
|
10 | - :select_project_modules | |||
10 | - :manage_members |
|
11 | - :manage_members | |
11 | - :manage_versions |
|
12 | - :manage_versions | |
12 | - :manage_categories |
|
13 | - :manage_categories |
@@ -154,7 +154,8 class ProjectsControllerTest < ActionController::TestCase | |||||
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 | } |
|
159 | } | |
159 | assert_redirected_to '/projects/blog/settings' |
|
160 | assert_redirected_to '/projects/blog/settings' | |
160 |
|
161 | |||
@@ -167,6 +168,7 class ProjectsControllerTest < ActionController::TestCase | |||||
167 | assert_nil project.parent |
|
168 | assert_nil project.parent | |
168 | assert_equal 'Beta', project.custom_value_for(3).value |
|
169 | assert_equal 'Beta', project.custom_value_for(3).value | |
169 | 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 | |||
170 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
|
172 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) | |
171 | end |
|
173 | end | |
172 |
|
174 | |||
@@ -197,7 +199,9 class ProjectsControllerTest < ActionController::TestCase | |||||
197 | :description => "weblog", |
|
199 | :description => "weblog", | |
198 | :identifier => "blog", |
|
200 | :identifier => "blog", | |
199 | :is_public => 1, |
|
201 | :is_public => 1, | |
200 | :custom_field_values => { '3' => 'Beta' } |
|
202 | :custom_field_values => { '3' => 'Beta' }, | |
|
203 | :tracker_ids => ['1', '3'], | |||
|
204 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |||
201 | } |
|
205 | } | |
202 |
|
206 | |||
203 | assert_redirected_to '/projects/blog/settings' |
|
207 | assert_redirected_to '/projects/blog/settings' | |
@@ -206,6 +210,8 class ProjectsControllerTest < ActionController::TestCase | |||||
206 | assert_kind_of Project, project |
|
210 | assert_kind_of Project, project | |
207 | assert_equal 'weblog', project.description |
|
211 | assert_equal 'weblog', project.description | |
208 | assert_equal true, project.is_public? |
|
212 | assert_equal true, project.is_public? | |
|
213 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
214 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |||
209 |
|
215 | |||
210 | # User should be added as a project member |
|
216 | # User should be added as a project member | |
211 | assert User.find(9).member_of?(project) |
|
217 | assert User.find(9).member_of?(project) | |
@@ -282,6 +288,12 class ProjectsControllerTest < ActionController::TestCase | |||||
282 | end |
|
288 | end | |
283 | end |
|
289 | end | |
284 |
|
290 | |||
|
291 | def test_create_should_not_accept_get | |||
|
292 | @request.session[:user_id] = 1 | |||
|
293 | get :create | |||
|
294 | assert_response :method_not_allowed | |||
|
295 | end | |||
|
296 | ||||
285 | def test_show_by_id |
|
297 | def test_show_by_id | |
286 | get :show, :id => 1 |
|
298 | get :show, :id => 1 | |
287 | assert_response :success |
|
299 | assert_response :success | |
@@ -359,6 +371,21 class ProjectsControllerTest < ActionController::TestCase | |||||
359 | project = Project.find(1) |
|
371 | project = Project.find(1) | |
360 | assert_equal 'Test changed name', project.name |
|
372 | assert_equal 'Test changed name', project.name | |
361 | end |
|
373 | end | |
|
374 | ||||
|
375 | def test_modules | |||
|
376 | @request.session[:user_id] = 2 | |||
|
377 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] | |||
|
378 | ||||
|
379 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] | |||
|
380 | assert_redirected_to '/projects/ecookbook/settings/modules' | |||
|
381 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort | |||
|
382 | end | |||
|
383 | ||||
|
384 | def test_modules_should_not_allow_get | |||
|
385 | @request.session[:user_id] = 1 | |||
|
386 | get :modules, :id => 1 | |||
|
387 | assert_response :method_not_allowed | |||
|
388 | end | |||
362 |
|
389 | |||
363 | def test_get_destroy |
|
390 | def test_get_destroy | |
364 | @request.session[:user_id] = 1 # admin |
|
391 | @request.session[:user_id] = 1 # admin |
@@ -122,12 +122,35 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
122 | project = Project.first(:order => 'id DESC') |
|
122 | project = Project.first(:order => 'id DESC') | |
123 | assert_equal 'API test', project.name |
|
123 | assert_equal 'API test', project.name | |
124 | assert_equal 'api-test', project.identifier |
|
124 | assert_equal 'api-test', project.identifier | |
125 | assert_equal ['issue_tracking', 'repository'], project.enabled_module_names |
|
125 | assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort | |
|
126 | assert_equal Tracker.all.size, project.trackers.size | |||
126 |
|
127 | |||
127 | assert_response :created |
|
128 | assert_response :created | |
128 | assert_equal 'application/xml', @response.content_type |
|
129 | assert_equal 'application/xml', @response.content_type | |
129 | assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s} |
|
130 | assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s} | |
130 | end |
|
131 | end | |
|
132 | ||||
|
133 | should "accept enabled_module_names attribute" do | |||
|
134 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) | |||
|
135 | ||||
|
136 | assert_difference('Project.count') do | |||
|
137 | post '/projects.xml', @parameters, :authorization => credentials('admin') | |||
|
138 | end | |||
|
139 | ||||
|
140 | project = Project.first(:order => 'id DESC') | |||
|
141 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort | |||
|
142 | end | |||
|
143 | ||||
|
144 | should "accept tracker_ids attribute" do | |||
|
145 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) | |||
|
146 | ||||
|
147 | assert_difference('Project.count') do | |||
|
148 | post '/projects.xml', @parameters, :authorization => credentials('admin') | |||
|
149 | end | |||
|
150 | ||||
|
151 | project = Project.first(:order => 'id DESC') | |||
|
152 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
153 | end | |||
131 | end |
|
154 | end | |
132 | end |
|
155 | end | |
133 |
|
156 | |||
@@ -171,6 +194,28 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
171 | project = Project.find(2) |
|
194 | project = Project.find(2) | |
172 | assert_equal 'API update', project.name |
|
195 | assert_equal 'API update', project.name | |
173 | end |
|
196 | end | |
|
197 | ||||
|
198 | should "accept enabled_module_names attribute" do | |||
|
199 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) | |||
|
200 | ||||
|
201 | assert_no_difference 'Project.count' do | |||
|
202 | put '/projects/2.xml', @parameters, :authorization => credentials('admin') | |||
|
203 | end | |||
|
204 | assert_response :ok | |||
|
205 | project = Project.find(2) | |||
|
206 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort | |||
|
207 | end | |||
|
208 | ||||
|
209 | should "accept tracker_ids attribute" do | |||
|
210 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) | |||
|
211 | ||||
|
212 | assert_no_difference 'Project.count' do | |||
|
213 | put '/projects/2.xml', @parameters, :authorization => credentials('admin') | |||
|
214 | end | |||
|
215 | assert_response :ok | |||
|
216 | project = Project.find(2) | |||
|
217 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
218 | end | |||
174 | end |
|
219 | end | |
175 | end |
|
220 | end | |
176 |
|
221 |
@@ -19,40 +19,100 require File.expand_path('../../test_helper', __FILE__) | |||||
19 |
|
19 | |||
20 | class ProjectNestedSetTest < ActiveSupport::TestCase |
|
20 | class ProjectNestedSetTest < ActiveSupport::TestCase | |
21 |
|
21 | |||
22 | def setup |
|
22 | context "nested set" do | |
23 | Project.delete_all |
|
23 | setup do | |
24 | end |
|
24 | Project.delete_all | |
25 |
|
25 | |||
26 | def test_destroy_root_and_chldren_should_not_mess_up_the_tree |
|
26 | @a = Project.create!(:name => 'Project A', :identifier => 'projecta') | |
27 | a = Project.create!(:name => 'Project A', :identifier => 'projecta') |
|
27 | @a1 = Project.create!(:name => 'Project A1', :identifier => 'projecta1') | |
28 | a1 = Project.create!(:name => 'Project A1', :identifier => 'projecta1') |
|
28 | @a1.set_parent!(@a) | |
29 | a2 = Project.create!(:name => 'Project A2', :identifier => 'projecta2') |
|
29 | @a2 = Project.create!(:name => 'Project A2', :identifier => 'projecta2') | |
30 |
|
|
30 | @a2.set_parent!(@a) | |
31 | a2.set_parent!(a) |
|
31 | ||
32 | b = Project.create!(:name => 'Project B', :identifier => 'projectb') |
|
32 | @b = Project.create!(:name => 'Project B', :identifier => 'projectb') | |
33 | b1 = Project.create!(:name => 'Project B1', :identifier => 'projectb1') |
|
33 | @b1 = Project.create!(:name => 'Project B1', :identifier => 'projectb1') | |
34 | b1.set_parent!(b) |
|
34 | @b1.set_parent!(@b) | |
35 |
|
35 | @b11 = Project.create!(:name => 'Project B11', :identifier => 'projectb11') | ||
36 | a.reload |
|
36 | @b11.set_parent!(@b1) | |
37 | a1.reload |
|
37 | @b2 = Project.create!(:name => 'Project B2', :identifier => 'projectb2') | |
38 | a2.reload |
|
38 | @b2.set_parent!(@b) | |
39 | b.reload |
|
39 | ||
40 | b1.reload |
|
40 | @c = Project.create!(:name => 'Project C', :identifier => 'projectc') | |
41 |
|
41 | @c1 = Project.create!(:name => 'Project C1', :identifier => 'projectc1') | ||
42 | assert_equal [nil, 1, 6], [a.parent_id, a.lft, a.rgt] |
|
42 | @c1.set_parent!(@c) | |
43 | assert_equal [a.id, 2, 3], [a1.parent_id, a1.lft, a1.rgt] |
|
43 | ||
44 | assert_equal [a.id, 4, 5], [a2.parent_id, a2.lft, a2.rgt] |
|
44 | [@a, @a1, @a2, @b, @b1, @b11, @b2, @c, @c1].each(&:reload) | |
45 | assert_equal [nil, 7, 10], [b.parent_id, b.lft, b.rgt] |
|
45 | end | |
46 | assert_equal [b.id, 8, 9], [b1.parent_id, b1.lft, b1.rgt] |
|
|||
47 |
|
46 | |||
48 | assert_difference 'Project.count', -3 do |
|
47 | context "#create" do | |
49 | a.destroy |
|
48 | should "build valid tree" do | |
|
49 | assert_nested_set_values({ | |||
|
50 | @a => [nil, 1, 6], | |||
|
51 | @a1 => [@a.id, 2, 3], | |||
|
52 | @a2 => [@a.id, 4, 5], | |||
|
53 | @b => [nil, 7, 14], | |||
|
54 | @b1 => [@b.id, 8, 11], | |||
|
55 | @b11 => [@b1.id,9, 10], | |||
|
56 | @b2 => [@b.id,12, 13], | |||
|
57 | @c => [nil, 15, 18], | |||
|
58 | @c1 => [@c.id,16, 17] | |||
|
59 | }) | |||
|
60 | end | |||
50 | end |
|
61 | end | |
51 |
|
62 | |||
52 | b.reload |
|
63 | context "#set_parent!" do | |
53 | b1.reload |
|
64 | should "keep valid tree" do | |
54 |
|
65 | assert_no_difference 'Project.count' do | ||
55 | assert_equal [nil, 1, 4], [b.parent_id, b.lft, b.rgt] |
|
66 | Project.find_by_name('Project B1').set_parent!(Project.find_by_name('Project A2')) | |
56 | assert_equal [b.id, 2, 3], [b1.parent_id, b1.lft, b1.rgt] |
|
67 | end | |
|
68 | assert_nested_set_values({ | |||
|
69 | @a => [nil, 1, 10], | |||
|
70 | @a2 => [@a.id, 4, 9], | |||
|
71 | @b1 => [@a2.id,5, 8], | |||
|
72 | @b11 => [@b1.id,6, 7], | |||
|
73 | @b => [nil, 11, 14], | |||
|
74 | @c => [nil, 15, 18] | |||
|
75 | }) | |||
|
76 | end | |||
|
77 | end | |||
|
78 | ||||
|
79 | context "#destroy" do | |||
|
80 | context "a root with children" do | |||
|
81 | should "not mess up the tree" do | |||
|
82 | assert_difference 'Project.count', -4 do | |||
|
83 | Project.find_by_name('Project B').destroy | |||
|
84 | end | |||
|
85 | assert_nested_set_values({ | |||
|
86 | @a => [nil, 1, 6], | |||
|
87 | @a1 => [@a.id, 2, 3], | |||
|
88 | @a2 => [@a.id, 4, 5], | |||
|
89 | @c => [nil, 7, 10], | |||
|
90 | @c1 => [@c.id, 8, 9] | |||
|
91 | }) | |||
|
92 | end | |||
|
93 | end | |||
|
94 | ||||
|
95 | context "a child with children" do | |||
|
96 | should "not mess up the tree" do | |||
|
97 | assert_difference 'Project.count', -2 do | |||
|
98 | Project.find_by_name('Project B1').destroy | |||
|
99 | end | |||
|
100 | assert_nested_set_values({ | |||
|
101 | @a => [nil, 1, 6], | |||
|
102 | @b => [nil, 7, 10], | |||
|
103 | @b2 => [@b.id, 8, 9], | |||
|
104 | @c => [nil, 11, 14] | |||
|
105 | }) | |||
|
106 | end | |||
|
107 | end | |||
|
108 | end | |||
|
109 | end | |||
|
110 | ||||
|
111 | def assert_nested_set_values(h) | |||
|
112 | assert Project.valid? | |||
|
113 | h.each do |project, expected| | |||
|
114 | project.reload | |||
|
115 | assert_equal expected, [project.parent_id, project.lft, project.rgt], "Unexpected nested set values for #{project.name}" | |||
|
116 | end | |||
57 | end |
|
117 | end | |
58 | end No newline at end of file |
|
118 | end |
General Comments 0
You need to be logged in to leave comments.
Login now