@@ -1,107 +1,106 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 | class QueriesController < ApplicationController |
|
18 | class QueriesController < ApplicationController | |
19 | menu_item :issues |
|
19 | menu_item :issues | |
20 | before_filter :find_query, :except => [:new, :create, :index] |
|
20 | before_filter :find_query, :except => [:new, :create, :index] | |
21 | before_filter :find_optional_project, :only => [:new, :create] |
|
21 | before_filter :find_optional_project, :only => [:new, :create] | |
22 |
|
22 | |||
23 | accept_api_auth :index |
|
23 | accept_api_auth :index | |
24 |
|
24 | |||
25 | include QueriesHelper |
|
25 | include QueriesHelper | |
26 |
|
26 | |||
27 | def index |
|
27 | def index | |
28 | case params[:format] |
|
28 | case params[:format] | |
29 | when 'xml', 'json' |
|
29 | when 'xml', 'json' | |
30 | @offset, @limit = api_offset_and_limit |
|
30 | @offset, @limit = api_offset_and_limit | |
31 | else |
|
31 | else | |
32 | @limit = per_page_option |
|
32 | @limit = per_page_option | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | @query_count = IssueQuery.visible.count |
|
35 | @query_count = IssueQuery.visible.count | |
36 | @query_pages = Paginator.new self, @query_count, @limit, params['page'] |
|
36 | @query_pages = Paginator.new self, @query_count, @limit, params['page'] | |
37 | @queries = IssueQuery.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name") |
|
37 | @queries = IssueQuery.visible.all(:limit => @limit, :offset => @offset, :order => "#{Query.table_name}.name") | |
38 |
|
38 | |||
39 | respond_to do |format| |
|
39 | respond_to do |format| | |
40 | format.html { render :nothing => true } |
|
|||
41 | format.api |
|
40 | format.api | |
42 | end |
|
41 | end | |
43 | end |
|
42 | end | |
44 |
|
43 | |||
45 | def new |
|
44 | def new | |
46 | @query = IssueQuery.new |
|
45 | @query = IssueQuery.new | |
47 | @query.user = User.current |
|
46 | @query.user = User.current | |
48 | @query.project = @project |
|
47 | @query.project = @project | |
49 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
|
48 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
50 | @query.build_from_params(params) |
|
49 | @query.build_from_params(params) | |
51 | end |
|
50 | end | |
52 |
|
51 | |||
53 | def create |
|
52 | def create | |
54 | @query = IssueQuery.new(params[:query]) |
|
53 | @query = IssueQuery.new(params[:query]) | |
55 | @query.user = User.current |
|
54 | @query.user = User.current | |
56 | @query.project = params[:query_is_for_all] ? nil : @project |
|
55 | @query.project = params[:query_is_for_all] ? nil : @project | |
57 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
|
56 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
58 | @query.build_from_params(params) |
|
57 | @query.build_from_params(params) | |
59 | @query.column_names = nil if params[:default_columns] |
|
58 | @query.column_names = nil if params[:default_columns] | |
60 |
|
59 | |||
61 | if @query.save |
|
60 | if @query.save | |
62 | flash[:notice] = l(:notice_successful_create) |
|
61 | flash[:notice] = l(:notice_successful_create) | |
63 | redirect_to _issues_path(@project, :query_id => @query) |
|
62 | redirect_to _issues_path(@project, :query_id => @query) | |
64 | else |
|
63 | else | |
65 | render :action => 'new', :layout => !request.xhr? |
|
64 | render :action => 'new', :layout => !request.xhr? | |
66 | end |
|
65 | end | |
67 | end |
|
66 | end | |
68 |
|
67 | |||
69 | def edit |
|
68 | def edit | |
70 | end |
|
69 | end | |
71 |
|
70 | |||
72 | def update |
|
71 | def update | |
73 | @query.attributes = params[:query] |
|
72 | @query.attributes = params[:query] | |
74 | @query.project = nil if params[:query_is_for_all] |
|
73 | @query.project = nil if params[:query_is_for_all] | |
75 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? |
|
74 | @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin? | |
76 | @query.build_from_params(params) |
|
75 | @query.build_from_params(params) | |
77 | @query.column_names = nil if params[:default_columns] |
|
76 | @query.column_names = nil if params[:default_columns] | |
78 |
|
77 | |||
79 | if @query.save |
|
78 | if @query.save | |
80 | flash[:notice] = l(:notice_successful_update) |
|
79 | flash[:notice] = l(:notice_successful_update) | |
81 | redirect_to _issues_path(@project, :query_id => @query) |
|
80 | redirect_to _issues_path(@project, :query_id => @query) | |
82 | else |
|
81 | else | |
83 | render :action => 'edit' |
|
82 | render :action => 'edit' | |
84 | end |
|
83 | end | |
85 | end |
|
84 | end | |
86 |
|
85 | |||
87 | def destroy |
|
86 | def destroy | |
88 | @query.destroy |
|
87 | @query.destroy | |
89 | redirect_to _issues_path(@project, :set_filter => 1) |
|
88 | redirect_to _issues_path(@project, :set_filter => 1) | |
90 | end |
|
89 | end | |
91 |
|
90 | |||
92 | private |
|
91 | private | |
93 | def find_query |
|
92 | def find_query | |
94 | @query = IssueQuery.find(params[:id]) |
|
93 | @query = IssueQuery.find(params[:id]) | |
95 | @project = @query.project |
|
94 | @project = @query.project | |
96 | render_403 unless @query.editable_by?(User.current) |
|
95 | render_403 unless @query.editable_by?(User.current) | |
97 | rescue ActiveRecord::RecordNotFound |
|
96 | rescue ActiveRecord::RecordNotFound | |
98 | render_404 |
|
97 | render_404 | |
99 | end |
|
98 | end | |
100 |
|
99 | |||
101 | def find_optional_project |
|
100 | def find_optional_project | |
102 | @project = Project.find(params[:project_id]) if params[:project_id] |
|
101 | @project = Project.find(params[:project_id]) if params[:project_id] | |
103 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) |
|
102 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) | |
104 | rescue ActiveRecord::RecordNotFound |
|
103 | rescue ActiveRecord::RecordNotFound | |
105 | render_404 |
|
104 | render_404 | |
106 | end |
|
105 | end | |
107 | end |
|
106 | end |
@@ -1,128 +1,128 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 | class WorkflowsController < ApplicationController |
|
18 | class WorkflowsController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin, :find_roles, :find_trackers |
|
21 | before_filter :require_admin, :find_roles, :find_trackers | |
22 |
|
22 | |||
23 | def index |
|
23 | def index | |
24 | @workflow_counts = WorkflowTransition.count_by_tracker_and_role |
|
24 | @workflow_counts = WorkflowTransition.count_by_tracker_and_role | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def edit |
|
27 | def edit | |
28 | @role = Role.find_by_id(params[:role_id]) if params[:role_id] |
|
28 | @role = Role.find_by_id(params[:role_id]) if params[:role_id] | |
29 | @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] |
|
29 | @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] | |
30 |
|
30 | |||
31 | if request.post? |
|
31 | if request.post? | |
32 | WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
|
32 | WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) | |
33 | (params[:issue_status] || []).each { |status_id, transitions| |
|
33 | (params[:issue_status] || []).each { |status_id, transitions| | |
34 | transitions.each { |new_status_id, options| |
|
34 | transitions.each { |new_status_id, options| | |
35 | author = options.is_a?(Array) && options.include?('author') && !options.include?('always') |
|
35 | author = options.is_a?(Array) && options.include?('author') && !options.include?('always') | |
36 | assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') |
|
36 | assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') | |
37 | WorkflowTransition.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee) |
|
37 | WorkflowTransition.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee) | |
38 | } |
|
38 | } | |
39 | } |
|
39 | } | |
40 | if @role.save |
|
40 | if @role.save | |
41 | redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only]) |
|
41 | redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only]) | |
42 | return |
|
42 | return | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
|
46 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) | |
47 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
|
47 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? | |
48 | @statuses = @tracker.issue_statuses |
|
48 | @statuses = @tracker.issue_statuses | |
49 | end |
|
49 | end | |
50 | @statuses ||= IssueStatus.sorted.all |
|
50 | @statuses ||= IssueStatus.sorted.all | |
51 |
|
51 | |||
52 | if @tracker && @role && @statuses.any? |
|
52 | if @tracker && @role && @statuses.any? | |
53 | workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all |
|
53 | workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all | |
54 | @workflows = {} |
|
54 | @workflows = {} | |
55 | @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} |
|
55 | @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} | |
56 | @workflows['author'] = workflows.select {|w| w.author} |
|
56 | @workflows['author'] = workflows.select {|w| w.author} | |
57 | @workflows['assignee'] = workflows.select {|w| w.assignee} |
|
57 | @workflows['assignee'] = workflows.select {|w| w.assignee} | |
58 | end |
|
58 | end | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def permissions |
|
61 | def permissions | |
62 | @role = Role.find_by_id(params[:role_id]) if params[:role_id] |
|
62 | @role = Role.find_by_id(params[:role_id]) if params[:role_id] | |
63 | @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] |
|
63 | @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] | |
64 |
|
64 | |||
65 | if request.post? && @role && @tracker |
|
65 | if request.post? && @role && @tracker | |
66 | WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {}) |
|
66 | WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {}) | |
67 | redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only]) |
|
67 | redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only]) | |
68 | return |
|
68 | return | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
|
71 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) | |
72 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
|
72 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? | |
73 | @statuses = @tracker.issue_statuses |
|
73 | @statuses = @tracker.issue_statuses | |
74 | end |
|
74 | end | |
75 | @statuses ||= IssueStatus.sorted.all |
|
75 | @statuses ||= IssueStatus.sorted.all | |
76 |
|
76 | |||
77 | if @role && @tracker |
|
77 | if @role && @tracker | |
78 | @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]} |
|
78 | @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]} | |
79 | @custom_fields = @tracker.custom_fields |
|
79 | @custom_fields = @tracker.custom_fields | |
80 |
|
80 | |||
81 | @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w| |
|
81 | @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w| | |
82 | h[w.old_status_id] ||= {} |
|
82 | h[w.old_status_id] ||= {} | |
83 | h[w.old_status_id][w.field_name] = w.rule |
|
83 | h[w.old_status_id][w.field_name] = w.rule | |
84 | h |
|
84 | h | |
85 | end |
|
85 | end | |
86 | @statuses.each {|status| @permissions[status.id] ||= {}} |
|
86 | @statuses.each {|status| @permissions[status.id] ||= {}} | |
87 | end |
|
87 | end | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def copy |
|
90 | def copy | |
91 |
|
91 | |||
92 | if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' |
|
92 | if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' | |
93 | @source_tracker = nil |
|
93 | @source_tracker = nil | |
94 | else |
|
94 | else | |
95 | @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) |
|
95 | @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) | |
96 | end |
|
96 | end | |
97 | if params[:source_role_id].blank? || params[:source_role_id] == 'any' |
|
97 | if params[:source_role_id].blank? || params[:source_role_id] == 'any' | |
98 | @source_role = nil |
|
98 | @source_role = nil | |
99 | else |
|
99 | else | |
100 | @source_role = Role.find_by_id(params[:source_role_id].to_i) |
|
100 | @source_role = Role.find_by_id(params[:source_role_id].to_i) | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) |
|
103 | @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) | |
104 | @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) |
|
104 | @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) | |
105 |
|
105 | |||
106 | if request.post? |
|
106 | if request.post? | |
107 | if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) |
|
107 | if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) | |
108 | flash.now[:error] = l(:error_workflow_copy_source) |
|
108 | flash.now[:error] = l(:error_workflow_copy_source) | |
109 |
elsif @target_trackers. |
|
109 | elsif @target_trackers.blank? || @target_roles.blank? | |
110 | flash.now[:error] = l(:error_workflow_copy_target) |
|
110 | flash.now[:error] = l(:error_workflow_copy_target) | |
111 | else |
|
111 | else | |
112 | WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles) |
|
112 | WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles) | |
113 | flash[:notice] = l(:notice_successful_update) |
|
113 | flash[:notice] = l(:notice_successful_update) | |
114 | redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role) |
|
114 | redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role) | |
115 | end |
|
115 | end | |
116 | end |
|
116 | end | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | private |
|
119 | private | |
120 |
|
120 | |||
121 | def find_roles |
|
121 | def find_roles | |
122 | @roles = Role.sorted.all |
|
122 | @roles = Role.sorted.all | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | def find_trackers |
|
125 | def find_trackers | |
126 | @trackers = Tracker.sorted.all |
|
126 | @trackers = Tracker.sorted.all | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end |
@@ -1,206 +1,212 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 MessagesControllerTest < ActionController::TestCase |
|
20 | class MessagesControllerTest < 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_show |
|
27 | def test_show | |
28 | get :show, :board_id => 1, :id => 1 |
|
28 | get :show, :board_id => 1, :id => 1 | |
29 | assert_response :success |
|
29 | assert_response :success | |
30 | assert_template 'show' |
|
30 | assert_template 'show' | |
31 | assert_not_nil assigns(:board) |
|
31 | assert_not_nil assigns(:board) | |
32 | assert_not_nil assigns(:project) |
|
32 | assert_not_nil assigns(:project) | |
33 | assert_not_nil assigns(:topic) |
|
33 | assert_not_nil assigns(:topic) | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | def test_show_should_contain_reply_field_tags_for_quoting |
|
36 | def test_show_should_contain_reply_field_tags_for_quoting | |
37 | @request.session[:user_id] = 2 |
|
37 | @request.session[:user_id] = 2 | |
38 | get :show, :board_id => 1, :id => 1 |
|
38 | get :show, :board_id => 1, :id => 1 | |
39 | assert_response :success |
|
39 | assert_response :success | |
40 |
|
40 | |||
41 | # tags required by MessagesController#quote |
|
41 | # tags required by MessagesController#quote | |
42 | assert_tag 'input', :attributes => {:id => 'message_subject'} |
|
42 | assert_tag 'input', :attributes => {:id => 'message_subject'} | |
43 | assert_tag 'textarea', :attributes => {:id => 'message_content'} |
|
43 | assert_tag 'textarea', :attributes => {:id => 'message_content'} | |
44 | assert_tag 'div', :attributes => {:id => 'reply'} |
|
44 | assert_tag 'div', :attributes => {:id => 'reply'} | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_show_with_pagination |
|
47 | def test_show_with_pagination | |
48 | message = Message.find(1) |
|
48 | message = Message.find(1) | |
49 | assert_difference 'Message.count', 30 do |
|
49 | assert_difference 'Message.count', 30 do | |
50 | 30.times do |
|
50 | 30.times do | |
51 | message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1) |
|
51 | message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1) | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id |
|
54 | get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id | |
55 | assert_response :success |
|
55 | assert_response :success | |
56 | assert_template 'show' |
|
56 | assert_template 'show' | |
57 | replies = assigns(:replies) |
|
57 | replies = assigns(:replies) | |
58 | assert_not_nil replies |
|
58 | assert_not_nil replies | |
59 | assert !replies.include?(message.children.first(:order => 'id')) |
|
59 | assert !replies.include?(message.children.first(:order => 'id')) | |
60 | assert replies.include?(message.children.last(:order => 'id')) |
|
60 | assert replies.include?(message.children.last(:order => 'id')) | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def test_show_with_reply_permission |
|
63 | def test_show_with_reply_permission | |
64 | @request.session[:user_id] = 2 |
|
64 | @request.session[:user_id] = 2 | |
65 | get :show, :board_id => 1, :id => 1 |
|
65 | get :show, :board_id => 1, :id => 1 | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'show' |
|
67 | assert_template 'show' | |
68 | assert_tag :div, :attributes => { :id => 'reply' }, |
|
68 | assert_tag :div, :attributes => { :id => 'reply' }, | |
69 | :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } } |
|
69 | :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } } | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_show_message_not_found |
|
72 | def test_show_message_not_found | |
73 | get :show, :board_id => 1, :id => 99999 |
|
73 | get :show, :board_id => 1, :id => 99999 | |
74 | assert_response 404 |
|
74 | assert_response 404 | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_get_new |
|
77 | def test_get_new | |
78 | @request.session[:user_id] = 2 |
|
78 | @request.session[:user_id] = 2 | |
79 | get :new, :board_id => 1 |
|
79 | get :new, :board_id => 1 | |
80 | assert_response :success |
|
80 | assert_response :success | |
81 | assert_template 'new' |
|
81 | assert_template 'new' | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
|
84 | def test_get_new_with_invalid_board | |||
|
85 | @request.session[:user_id] = 2 | |||
|
86 | get :new, :board_id => 99 | |||
|
87 | assert_response 404 | |||
|
88 | end | |||
|
89 | ||||
84 | def test_post_new |
|
90 | def test_post_new | |
85 | @request.session[:user_id] = 2 |
|
91 | @request.session[:user_id] = 2 | |
86 | ActionMailer::Base.deliveries.clear |
|
92 | ActionMailer::Base.deliveries.clear | |
87 |
|
93 | |||
88 | with_settings :notified_events => %w(message_posted) do |
|
94 | with_settings :notified_events => %w(message_posted) do | |
89 | post :new, :board_id => 1, |
|
95 | post :new, :board_id => 1, | |
90 | :message => { :subject => 'Test created message', |
|
96 | :message => { :subject => 'Test created message', | |
91 | :content => 'Message body'} |
|
97 | :content => 'Message body'} | |
92 | end |
|
98 | end | |
93 | message = Message.find_by_subject('Test created message') |
|
99 | message = Message.find_by_subject('Test created message') | |
94 | assert_not_nil message |
|
100 | assert_not_nil message | |
95 | assert_redirected_to "/boards/1/topics/#{message.to_param}" |
|
101 | assert_redirected_to "/boards/1/topics/#{message.to_param}" | |
96 | assert_equal 'Message body', message.content |
|
102 | assert_equal 'Message body', message.content | |
97 | assert_equal 2, message.author_id |
|
103 | assert_equal 2, message.author_id | |
98 | assert_equal 1, message.board_id |
|
104 | assert_equal 1, message.board_id | |
99 |
|
105 | |||
100 | mail = ActionMailer::Base.deliveries.last |
|
106 | mail = ActionMailer::Base.deliveries.last | |
101 | assert_not_nil mail |
|
107 | assert_not_nil mail | |
102 | assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject |
|
108 | assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject | |
103 | assert_mail_body_match 'Message body', mail |
|
109 | assert_mail_body_match 'Message body', mail | |
104 | # author |
|
110 | # author | |
105 | assert mail.bcc.include?('jsmith@somenet.foo') |
|
111 | assert mail.bcc.include?('jsmith@somenet.foo') | |
106 | # project member |
|
112 | # project member | |
107 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
113 | assert mail.bcc.include?('dlopper@somenet.foo') | |
108 | end |
|
114 | end | |
109 |
|
115 | |||
110 | def test_get_edit |
|
116 | def test_get_edit | |
111 | @request.session[:user_id] = 2 |
|
117 | @request.session[:user_id] = 2 | |
112 | get :edit, :board_id => 1, :id => 1 |
|
118 | get :edit, :board_id => 1, :id => 1 | |
113 | assert_response :success |
|
119 | assert_response :success | |
114 | assert_template 'edit' |
|
120 | assert_template 'edit' | |
115 | end |
|
121 | end | |
116 |
|
122 | |||
117 | def test_post_edit |
|
123 | def test_post_edit | |
118 | @request.session[:user_id] = 2 |
|
124 | @request.session[:user_id] = 2 | |
119 | post :edit, :board_id => 1, :id => 1, |
|
125 | post :edit, :board_id => 1, :id => 1, | |
120 | :message => { :subject => 'New subject', |
|
126 | :message => { :subject => 'New subject', | |
121 | :content => 'New body'} |
|
127 | :content => 'New body'} | |
122 | assert_redirected_to '/boards/1/topics/1' |
|
128 | assert_redirected_to '/boards/1/topics/1' | |
123 | message = Message.find(1) |
|
129 | message = Message.find(1) | |
124 | assert_equal 'New subject', message.subject |
|
130 | assert_equal 'New subject', message.subject | |
125 | assert_equal 'New body', message.content |
|
131 | assert_equal 'New body', message.content | |
126 | end |
|
132 | end | |
127 |
|
133 | |||
128 | def test_post_edit_sticky_and_locked |
|
134 | def test_post_edit_sticky_and_locked | |
129 | @request.session[:user_id] = 2 |
|
135 | @request.session[:user_id] = 2 | |
130 | post :edit, :board_id => 1, :id => 1, |
|
136 | post :edit, :board_id => 1, :id => 1, | |
131 | :message => { :subject => 'New subject', |
|
137 | :message => { :subject => 'New subject', | |
132 | :content => 'New body', |
|
138 | :content => 'New body', | |
133 | :locked => '1', |
|
139 | :locked => '1', | |
134 | :sticky => '1'} |
|
140 | :sticky => '1'} | |
135 | assert_redirected_to '/boards/1/topics/1' |
|
141 | assert_redirected_to '/boards/1/topics/1' | |
136 | message = Message.find(1) |
|
142 | message = Message.find(1) | |
137 | assert_equal true, message.sticky? |
|
143 | assert_equal true, message.sticky? | |
138 | assert_equal true, message.locked? |
|
144 | assert_equal true, message.locked? | |
139 | end |
|
145 | end | |
140 |
|
146 | |||
141 | def test_post_edit_should_allow_to_change_board |
|
147 | def test_post_edit_should_allow_to_change_board | |
142 | @request.session[:user_id] = 2 |
|
148 | @request.session[:user_id] = 2 | |
143 | post :edit, :board_id => 1, :id => 1, |
|
149 | post :edit, :board_id => 1, :id => 1, | |
144 | :message => { :subject => 'New subject', |
|
150 | :message => { :subject => 'New subject', | |
145 | :content => 'New body', |
|
151 | :content => 'New body', | |
146 | :board_id => 2} |
|
152 | :board_id => 2} | |
147 | assert_redirected_to '/boards/2/topics/1' |
|
153 | assert_redirected_to '/boards/2/topics/1' | |
148 | message = Message.find(1) |
|
154 | message = Message.find(1) | |
149 | assert_equal Board.find(2), message.board |
|
155 | assert_equal Board.find(2), message.board | |
150 | end |
|
156 | end | |
151 |
|
157 | |||
152 | def test_reply |
|
158 | def test_reply | |
153 | @request.session[:user_id] = 2 |
|
159 | @request.session[:user_id] = 2 | |
154 | post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } |
|
160 | post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } | |
155 | reply = Message.order('id DESC').first |
|
161 | reply = Message.order('id DESC').first | |
156 | assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" |
|
162 | assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" | |
157 | assert Message.find_by_subject('Test reply') |
|
163 | assert Message.find_by_subject('Test reply') | |
158 | end |
|
164 | end | |
159 |
|
165 | |||
160 | def test_destroy_topic |
|
166 | def test_destroy_topic | |
161 | @request.session[:user_id] = 2 |
|
167 | @request.session[:user_id] = 2 | |
162 | assert_difference 'Message.count', -3 do |
|
168 | assert_difference 'Message.count', -3 do | |
163 | post :destroy, :board_id => 1, :id => 1 |
|
169 | post :destroy, :board_id => 1, :id => 1 | |
164 | end |
|
170 | end | |
165 | assert_redirected_to '/projects/ecookbook/boards/1' |
|
171 | assert_redirected_to '/projects/ecookbook/boards/1' | |
166 | assert_nil Message.find_by_id(1) |
|
172 | assert_nil Message.find_by_id(1) | |
167 | end |
|
173 | end | |
168 |
|
174 | |||
169 | def test_destroy_reply |
|
175 | def test_destroy_reply | |
170 | @request.session[:user_id] = 2 |
|
176 | @request.session[:user_id] = 2 | |
171 | assert_difference 'Message.count', -1 do |
|
177 | assert_difference 'Message.count', -1 do | |
172 | post :destroy, :board_id => 1, :id => 2 |
|
178 | post :destroy, :board_id => 1, :id => 2 | |
173 | end |
|
179 | end | |
174 | assert_redirected_to '/boards/1/topics/1?r=2' |
|
180 | assert_redirected_to '/boards/1/topics/1?r=2' | |
175 | assert_nil Message.find_by_id(2) |
|
181 | assert_nil Message.find_by_id(2) | |
176 | end |
|
182 | end | |
177 |
|
183 | |||
178 | def test_quote |
|
184 | def test_quote | |
179 | @request.session[:user_id] = 2 |
|
185 | @request.session[:user_id] = 2 | |
180 | xhr :get, :quote, :board_id => 1, :id => 3 |
|
186 | xhr :get, :quote, :board_id => 1, :id => 3 | |
181 | assert_response :success |
|
187 | assert_response :success | |
182 | assert_equal 'text/javascript', response.content_type |
|
188 | assert_equal 'text/javascript', response.content_type | |
183 | assert_template 'quote' |
|
189 | assert_template 'quote' | |
184 | assert_include 'RE: First post', response.body |
|
190 | assert_include 'RE: First post', response.body | |
185 | assert_include '> An other reply', response.body |
|
191 | assert_include '> An other reply', response.body | |
186 | end |
|
192 | end | |
187 |
|
193 | |||
188 | def test_preview_new |
|
194 | def test_preview_new | |
189 | @request.session[:user_id] = 2 |
|
195 | @request.session[:user_id] = 2 | |
190 | post :preview, |
|
196 | post :preview, | |
191 | :board_id => 1, |
|
197 | :board_id => 1, | |
192 | :message => {:subject => "", :content => "Previewed text"} |
|
198 | :message => {:subject => "", :content => "Previewed text"} | |
193 | assert_response :success |
|
199 | assert_response :success | |
194 | assert_template 'common/_preview' |
|
200 | assert_template 'common/_preview' | |
195 | end |
|
201 | end | |
196 |
|
202 | |||
197 | def test_preview_edit |
|
203 | def test_preview_edit | |
198 | @request.session[:user_id] = 2 |
|
204 | @request.session[:user_id] = 2 | |
199 | post :preview, |
|
205 | post :preview, | |
200 | :id => 4, |
|
206 | :id => 4, | |
201 | :board_id => 1, |
|
207 | :board_id => 1, | |
202 | :message => {:subject => "", :content => "Previewed text"} |
|
208 | :message => {:subject => "", :content => "Previewed text"} | |
203 | assert_response :success |
|
209 | assert_response :success | |
204 | assert_template 'common/_preview' |
|
210 | assert_template 'common/_preview' | |
205 | end |
|
211 | end | |
206 | end |
|
212 | end |
@@ -1,284 +1,290 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 QueriesControllerTest < ActionController::TestCase |
|
20 | class QueriesControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :enabled_modules |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :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 | |||
|
28 | get :index | |||
|
29 | # HTML response not implemented | |||
|
30 | assert_response 406 | |||
|
31 | end | |||
|
32 | ||||
27 | def test_new_project_query |
|
33 | def test_new_project_query | |
28 | @request.session[:user_id] = 2 |
|
34 | @request.session[:user_id] = 2 | |
29 | get :new, :project_id => 1 |
|
35 | get :new, :project_id => 1 | |
30 | assert_response :success |
|
36 | assert_response :success | |
31 | assert_template 'new' |
|
37 | assert_template 'new' | |
32 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
38 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
33 | :name => 'query[is_public]', |
|
39 | :name => 'query[is_public]', | |
34 | :checked => nil } |
|
40 | :checked => nil } | |
35 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
41 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
36 | :name => 'query_is_for_all', |
|
42 | :name => 'query_is_for_all', | |
37 | :checked => nil, |
|
43 | :checked => nil, | |
38 | :disabled => nil } |
|
44 | :disabled => nil } | |
39 | assert_select 'select[name=?]', 'c[]' do |
|
45 | assert_select 'select[name=?]', 'c[]' do | |
40 | assert_select 'option[value=tracker]' |
|
46 | assert_select 'option[value=tracker]' | |
41 | assert_select 'option[value=subject]' |
|
47 | assert_select 'option[value=subject]' | |
42 | end |
|
48 | end | |
43 | end |
|
49 | end | |
44 |
|
50 | |||
45 | def test_new_global_query |
|
51 | def test_new_global_query | |
46 | @request.session[:user_id] = 2 |
|
52 | @request.session[:user_id] = 2 | |
47 | get :new |
|
53 | get :new | |
48 | assert_response :success |
|
54 | assert_response :success | |
49 | assert_template 'new' |
|
55 | assert_template 'new' | |
50 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
56 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
51 | :name => 'query[is_public]' } |
|
57 | :name => 'query[is_public]' } | |
52 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
58 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
53 | :name => 'query_is_for_all', |
|
59 | :name => 'query_is_for_all', | |
54 | :checked => 'checked', |
|
60 | :checked => 'checked', | |
55 | :disabled => nil } |
|
61 | :disabled => nil } | |
56 | end |
|
62 | end | |
57 |
|
63 | |||
58 | def test_new_on_invalid_project |
|
64 | def test_new_on_invalid_project | |
59 | @request.session[:user_id] = 2 |
|
65 | @request.session[:user_id] = 2 | |
60 | get :new, :project_id => 'invalid' |
|
66 | get :new, :project_id => 'invalid' | |
61 | assert_response 404 |
|
67 | assert_response 404 | |
62 | end |
|
68 | end | |
63 |
|
69 | |||
64 | def test_create_project_public_query |
|
70 | def test_create_project_public_query | |
65 | @request.session[:user_id] = 2 |
|
71 | @request.session[:user_id] = 2 | |
66 | post :create, |
|
72 | post :create, | |
67 | :project_id => 'ecookbook', |
|
73 | :project_id => 'ecookbook', | |
68 | :default_columns => '1', |
|
74 | :default_columns => '1', | |
69 | :f => ["status_id", "assigned_to_id"], |
|
75 | :f => ["status_id", "assigned_to_id"], | |
70 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
76 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, | |
71 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
77 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
72 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} |
|
78 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} | |
73 |
|
79 | |||
74 | q = Query.find_by_name('test_new_project_public_query') |
|
80 | q = Query.find_by_name('test_new_project_public_query') | |
75 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
81 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
76 | assert q.is_public? |
|
82 | assert q.is_public? | |
77 | assert q.has_default_columns? |
|
83 | assert q.has_default_columns? | |
78 | assert q.valid? |
|
84 | assert q.valid? | |
79 | end |
|
85 | end | |
80 |
|
86 | |||
81 | def test_create_project_private_query |
|
87 | def test_create_project_private_query | |
82 | @request.session[:user_id] = 3 |
|
88 | @request.session[:user_id] = 3 | |
83 | post :create, |
|
89 | post :create, | |
84 | :project_id => 'ecookbook', |
|
90 | :project_id => 'ecookbook', | |
85 | :default_columns => '1', |
|
91 | :default_columns => '1', | |
86 | :fields => ["status_id", "assigned_to_id"], |
|
92 | :fields => ["status_id", "assigned_to_id"], | |
87 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
93 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
88 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
94 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
89 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} |
|
95 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} | |
90 |
|
96 | |||
91 | q = Query.find_by_name('test_new_project_private_query') |
|
97 | q = Query.find_by_name('test_new_project_private_query') | |
92 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
98 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
93 | assert !q.is_public? |
|
99 | assert !q.is_public? | |
94 | assert q.has_default_columns? |
|
100 | assert q.has_default_columns? | |
95 | assert q.valid? |
|
101 | assert q.valid? | |
96 | end |
|
102 | end | |
97 |
|
103 | |||
98 | def test_create_global_private_query_with_custom_columns |
|
104 | def test_create_global_private_query_with_custom_columns | |
99 | @request.session[:user_id] = 3 |
|
105 | @request.session[:user_id] = 3 | |
100 | post :create, |
|
106 | post :create, | |
101 | :fields => ["status_id", "assigned_to_id"], |
|
107 | :fields => ["status_id", "assigned_to_id"], | |
102 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
108 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
103 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
109 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
104 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, |
|
110 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, | |
105 | :c => ["", "tracker", "subject", "priority", "category"] |
|
111 | :c => ["", "tracker", "subject", "priority", "category"] | |
106 |
|
112 | |||
107 | q = Query.find_by_name('test_new_global_private_query') |
|
113 | q = Query.find_by_name('test_new_global_private_query') | |
108 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
114 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
109 | assert !q.is_public? |
|
115 | assert !q.is_public? | |
110 | assert !q.has_default_columns? |
|
116 | assert !q.has_default_columns? | |
111 | assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} |
|
117 | assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} | |
112 | assert q.valid? |
|
118 | assert q.valid? | |
113 | end |
|
119 | end | |
114 |
|
120 | |||
115 | def test_create_global_query_with_custom_filters |
|
121 | def test_create_global_query_with_custom_filters | |
116 | @request.session[:user_id] = 3 |
|
122 | @request.session[:user_id] = 3 | |
117 | post :create, |
|
123 | post :create, | |
118 | :fields => ["assigned_to_id"], |
|
124 | :fields => ["assigned_to_id"], | |
119 | :operators => {"assigned_to_id" => "="}, |
|
125 | :operators => {"assigned_to_id" => "="}, | |
120 | :values => { "assigned_to_id" => ["me"]}, |
|
126 | :values => { "assigned_to_id" => ["me"]}, | |
121 | :query => {"name" => "test_new_global_query"} |
|
127 | :query => {"name" => "test_new_global_query"} | |
122 |
|
128 | |||
123 | q = Query.find_by_name('test_new_global_query') |
|
129 | q = Query.find_by_name('test_new_global_query') | |
124 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
130 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
125 | assert !q.has_filter?(:status_id) |
|
131 | assert !q.has_filter?(:status_id) | |
126 | assert_equal ['assigned_to_id'], q.filters.keys |
|
132 | assert_equal ['assigned_to_id'], q.filters.keys | |
127 | assert q.valid? |
|
133 | assert q.valid? | |
128 | end |
|
134 | end | |
129 |
|
135 | |||
130 | def test_create_with_sort |
|
136 | def test_create_with_sort | |
131 | @request.session[:user_id] = 1 |
|
137 | @request.session[:user_id] = 1 | |
132 | post :create, |
|
138 | post :create, | |
133 | :default_columns => '1', |
|
139 | :default_columns => '1', | |
134 | :operators => {"status_id" => "o"}, |
|
140 | :operators => {"status_id" => "o"}, | |
135 | :values => {"status_id" => ["1"]}, |
|
141 | :values => {"status_id" => ["1"]}, | |
136 | :query => {:name => "test_new_with_sort", |
|
142 | :query => {:name => "test_new_with_sort", | |
137 | :is_public => "1", |
|
143 | :is_public => "1", | |
138 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
|
144 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} | |
139 |
|
145 | |||
140 | query = Query.find_by_name("test_new_with_sort") |
|
146 | query = Query.find_by_name("test_new_with_sort") | |
141 | assert_not_nil query |
|
147 | assert_not_nil query | |
142 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
148 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria | |
143 | end |
|
149 | end | |
144 |
|
150 | |||
145 | def test_create_with_failure |
|
151 | def test_create_with_failure | |
146 | @request.session[:user_id] = 2 |
|
152 | @request.session[:user_id] = 2 | |
147 | assert_no_difference '::Query.count' do |
|
153 | assert_no_difference '::Query.count' do | |
148 | post :create, :project_id => 'ecookbook', :query => {:name => ''} |
|
154 | post :create, :project_id => 'ecookbook', :query => {:name => ''} | |
149 | end |
|
155 | end | |
150 | assert_response :success |
|
156 | assert_response :success | |
151 | assert_template 'new' |
|
157 | assert_template 'new' | |
152 | assert_select 'input[name=?]', 'query[name]' |
|
158 | assert_select 'input[name=?]', 'query[name]' | |
153 | end |
|
159 | end | |
154 |
|
160 | |||
155 | def test_edit_global_public_query |
|
161 | def test_edit_global_public_query | |
156 | @request.session[:user_id] = 1 |
|
162 | @request.session[:user_id] = 1 | |
157 | get :edit, :id => 4 |
|
163 | get :edit, :id => 4 | |
158 | assert_response :success |
|
164 | assert_response :success | |
159 | assert_template 'edit' |
|
165 | assert_template 'edit' | |
160 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
166 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
161 | :name => 'query[is_public]', |
|
167 | :name => 'query[is_public]', | |
162 | :checked => 'checked' } |
|
168 | :checked => 'checked' } | |
163 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
169 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
164 | :name => 'query_is_for_all', |
|
170 | :name => 'query_is_for_all', | |
165 | :checked => 'checked', |
|
171 | :checked => 'checked', | |
166 | :disabled => 'disabled' } |
|
172 | :disabled => 'disabled' } | |
167 | end |
|
173 | end | |
168 |
|
174 | |||
169 | def test_edit_global_private_query |
|
175 | def test_edit_global_private_query | |
170 | @request.session[:user_id] = 3 |
|
176 | @request.session[:user_id] = 3 | |
171 | get :edit, :id => 3 |
|
177 | get :edit, :id => 3 | |
172 | assert_response :success |
|
178 | assert_response :success | |
173 | assert_template 'edit' |
|
179 | assert_template 'edit' | |
174 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
180 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
175 | :name => 'query[is_public]' } |
|
181 | :name => 'query[is_public]' } | |
176 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
182 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
177 | :name => 'query_is_for_all', |
|
183 | :name => 'query_is_for_all', | |
178 | :checked => 'checked', |
|
184 | :checked => 'checked', | |
179 | :disabled => 'disabled' } |
|
185 | :disabled => 'disabled' } | |
180 | end |
|
186 | end | |
181 |
|
187 | |||
182 | def test_edit_project_private_query |
|
188 | def test_edit_project_private_query | |
183 | @request.session[:user_id] = 3 |
|
189 | @request.session[:user_id] = 3 | |
184 | get :edit, :id => 2 |
|
190 | get :edit, :id => 2 | |
185 | assert_response :success |
|
191 | assert_response :success | |
186 | assert_template 'edit' |
|
192 | assert_template 'edit' | |
187 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
193 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
188 | :name => 'query[is_public]' } |
|
194 | :name => 'query[is_public]' } | |
189 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
195 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
190 | :name => 'query_is_for_all', |
|
196 | :name => 'query_is_for_all', | |
191 | :checked => nil, |
|
197 | :checked => nil, | |
192 | :disabled => nil } |
|
198 | :disabled => nil } | |
193 | end |
|
199 | end | |
194 |
|
200 | |||
195 | def test_edit_project_public_query |
|
201 | def test_edit_project_public_query | |
196 | @request.session[:user_id] = 2 |
|
202 | @request.session[:user_id] = 2 | |
197 | get :edit, :id => 1 |
|
203 | get :edit, :id => 1 | |
198 | assert_response :success |
|
204 | assert_response :success | |
199 | assert_template 'edit' |
|
205 | assert_template 'edit' | |
200 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
206 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
201 | :name => 'query[is_public]', |
|
207 | :name => 'query[is_public]', | |
202 | :checked => 'checked' |
|
208 | :checked => 'checked' | |
203 | } |
|
209 | } | |
204 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
210 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
205 | :name => 'query_is_for_all', |
|
211 | :name => 'query_is_for_all', | |
206 | :checked => nil, |
|
212 | :checked => nil, | |
207 | :disabled => 'disabled' } |
|
213 | :disabled => 'disabled' } | |
208 | end |
|
214 | end | |
209 |
|
215 | |||
210 | def test_edit_sort_criteria |
|
216 | def test_edit_sort_criteria | |
211 | @request.session[:user_id] = 1 |
|
217 | @request.session[:user_id] = 1 | |
212 | get :edit, :id => 5 |
|
218 | get :edit, :id => 5 | |
213 | assert_response :success |
|
219 | assert_response :success | |
214 | assert_template 'edit' |
|
220 | assert_template 'edit' | |
215 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
221 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, | |
216 | :child => { :tag => 'option', :attributes => { :value => 'priority', |
|
222 | :child => { :tag => 'option', :attributes => { :value => 'priority', | |
217 | :selected => 'selected' } } |
|
223 | :selected => 'selected' } } | |
218 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
224 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, | |
219 | :child => { :tag => 'option', :attributes => { :value => 'desc', |
|
225 | :child => { :tag => 'option', :attributes => { :value => 'desc', | |
220 | :selected => 'selected' } } |
|
226 | :selected => 'selected' } } | |
221 | end |
|
227 | end | |
222 |
|
228 | |||
223 | def test_edit_invalid_query |
|
229 | def test_edit_invalid_query | |
224 | @request.session[:user_id] = 2 |
|
230 | @request.session[:user_id] = 2 | |
225 | get :edit, :id => 99 |
|
231 | get :edit, :id => 99 | |
226 | assert_response 404 |
|
232 | assert_response 404 | |
227 | end |
|
233 | end | |
228 |
|
234 | |||
229 | def test_udpate_global_private_query |
|
235 | def test_udpate_global_private_query | |
230 | @request.session[:user_id] = 3 |
|
236 | @request.session[:user_id] = 3 | |
231 | put :update, |
|
237 | put :update, | |
232 | :id => 3, |
|
238 | :id => 3, | |
233 | :default_columns => '1', |
|
239 | :default_columns => '1', | |
234 | :fields => ["status_id", "assigned_to_id"], |
|
240 | :fields => ["status_id", "assigned_to_id"], | |
235 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
241 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
236 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
242 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
237 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} |
|
243 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} | |
238 |
|
244 | |||
239 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
245 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 | |
240 | q = Query.find_by_name('test_edit_global_private_query') |
|
246 | q = Query.find_by_name('test_edit_global_private_query') | |
241 | assert !q.is_public? |
|
247 | assert !q.is_public? | |
242 | assert q.has_default_columns? |
|
248 | assert q.has_default_columns? | |
243 | assert q.valid? |
|
249 | assert q.valid? | |
244 | end |
|
250 | end | |
245 |
|
251 | |||
246 | def test_update_global_public_query |
|
252 | def test_update_global_public_query | |
247 | @request.session[:user_id] = 1 |
|
253 | @request.session[:user_id] = 1 | |
248 | put :update, |
|
254 | put :update, | |
249 | :id => 4, |
|
255 | :id => 4, | |
250 | :default_columns => '1', |
|
256 | :default_columns => '1', | |
251 | :fields => ["status_id", "assigned_to_id"], |
|
257 | :fields => ["status_id", "assigned_to_id"], | |
252 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
258 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
253 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
259 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
254 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} |
|
260 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} | |
255 |
|
261 | |||
256 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
262 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 | |
257 | q = Query.find_by_name('test_edit_global_public_query') |
|
263 | q = Query.find_by_name('test_edit_global_public_query') | |
258 | assert q.is_public? |
|
264 | assert q.is_public? | |
259 | assert q.has_default_columns? |
|
265 | assert q.has_default_columns? | |
260 | assert q.valid? |
|
266 | assert q.valid? | |
261 | end |
|
267 | end | |
262 |
|
268 | |||
263 | def test_update_with_failure |
|
269 | def test_update_with_failure | |
264 | @request.session[:user_id] = 1 |
|
270 | @request.session[:user_id] = 1 | |
265 | put :update, :id => 4, :query => {:name => ''} |
|
271 | put :update, :id => 4, :query => {:name => ''} | |
266 | assert_response :success |
|
272 | assert_response :success | |
267 | assert_template 'edit' |
|
273 | assert_template 'edit' | |
268 | end |
|
274 | end | |
269 |
|
275 | |||
270 | def test_destroy |
|
276 | def test_destroy | |
271 | @request.session[:user_id] = 2 |
|
277 | @request.session[:user_id] = 2 | |
272 | delete :destroy, :id => 1 |
|
278 | delete :destroy, :id => 1 | |
273 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
279 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil | |
274 | assert_nil Query.find_by_id(1) |
|
280 | assert_nil Query.find_by_id(1) | |
275 | end |
|
281 | end | |
276 |
|
282 | |||
277 | def test_backslash_should_be_escaped_in_filters |
|
283 | def test_backslash_should_be_escaped_in_filters | |
278 | @request.session[:user_id] = 2 |
|
284 | @request.session[:user_id] = 2 | |
279 | get :new, :subject => 'foo/bar' |
|
285 | get :new, :subject => 'foo/bar' | |
280 | assert_response :success |
|
286 | assert_response :success | |
281 | assert_template 'new' |
|
287 | assert_template 'new' | |
282 | assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body |
|
288 | assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body | |
283 | end |
|
289 | end | |
284 | end |
|
290 | end |
@@ -1,308 +1,328 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 WorkflowsControllerTest < ActionController::TestCase |
|
20 | class WorkflowsControllerTest < ActionController::TestCase | |
21 | fixtures :roles, :trackers, :workflows, :users, :issue_statuses |
|
21 | fixtures :roles, :trackers, :workflows, :users, :issue_statuses | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | User.current = nil |
|
24 | User.current = nil | |
25 | @request.session[:user_id] = 1 # admin |
|
25 | @request.session[:user_id] = 1 # admin | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def test_index |
|
28 | def test_index | |
29 | get :index |
|
29 | get :index | |
30 | assert_response :success |
|
30 | assert_response :success | |
31 | assert_template 'index' |
|
31 | assert_template 'index' | |
32 |
|
32 | |||
33 | count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') |
|
33 | count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') | |
34 | assert_tag :tag => 'a', :content => count.to_s, |
|
34 | assert_tag :tag => 'a', :content => count.to_s, | |
35 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } |
|
35 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_get_edit |
|
38 | def test_get_edit | |
39 | get :edit |
|
39 | get :edit | |
40 | assert_response :success |
|
40 | assert_response :success | |
41 | assert_template 'edit' |
|
41 | assert_template 'edit' | |
42 | assert_not_nil assigns(:roles) |
|
42 | assert_not_nil assigns(:roles) | |
43 | assert_not_nil assigns(:trackers) |
|
43 | assert_not_nil assigns(:trackers) | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_get_edit_with_role_and_tracker |
|
46 | def test_get_edit_with_role_and_tracker | |
47 | WorkflowTransition.delete_all |
|
47 | WorkflowTransition.delete_all | |
48 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) |
|
48 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) | |
49 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) |
|
49 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) | |
50 |
|
50 | |||
51 | get :edit, :role_id => 2, :tracker_id => 1 |
|
51 | get :edit, :role_id => 2, :tracker_id => 1 | |
52 | assert_response :success |
|
52 | assert_response :success | |
53 | assert_template 'edit' |
|
53 | assert_template 'edit' | |
54 |
|
54 | |||
55 | # used status only |
|
55 | # used status only | |
56 | assert_not_nil assigns(:statuses) |
|
56 | assert_not_nil assigns(:statuses) | |
57 | assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) |
|
57 | assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) | |
58 |
|
58 | |||
59 | # allowed transitions |
|
59 | # allowed transitions | |
60 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
60 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
61 | :name => 'issue_status[3][5][]', |
|
61 | :name => 'issue_status[3][5][]', | |
62 | :value => 'always', |
|
62 | :value => 'always', | |
63 | :checked => 'checked' } |
|
63 | :checked => 'checked' } | |
64 | # not allowed |
|
64 | # not allowed | |
65 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
65 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
66 | :name => 'issue_status[3][2][]', |
|
66 | :name => 'issue_status[3][2][]', | |
67 | :value => 'always', |
|
67 | :value => 'always', | |
68 | :checked => nil } |
|
68 | :checked => nil } | |
69 | # unused |
|
69 | # unused | |
70 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
70 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
71 | :name => 'issue_status[1][1][]' } |
|
71 | :name => 'issue_status[1][1][]' } | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def test_get_edit_with_role_and_tracker_and_all_statuses |
|
74 | def test_get_edit_with_role_and_tracker_and_all_statuses | |
75 | WorkflowTransition.delete_all |
|
75 | WorkflowTransition.delete_all | |
76 |
|
76 | |||
77 | get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' |
|
77 | get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' | |
78 | assert_response :success |
|
78 | assert_response :success | |
79 | assert_template 'edit' |
|
79 | assert_template 'edit' | |
80 |
|
80 | |||
81 | assert_not_nil assigns(:statuses) |
|
81 | assert_not_nil assigns(:statuses) | |
82 | assert_equal IssueStatus.count, assigns(:statuses).size |
|
82 | assert_equal IssueStatus.count, assigns(:statuses).size | |
83 |
|
83 | |||
84 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
84 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
85 | :name => 'issue_status[1][1][]', |
|
85 | :name => 'issue_status[1][1][]', | |
86 | :value => 'always', |
|
86 | :value => 'always', | |
87 | :checked => nil } |
|
87 | :checked => nil } | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_post_edit |
|
90 | def test_post_edit | |
91 | post :edit, :role_id => 2, :tracker_id => 1, |
|
91 | post :edit, :role_id => 2, :tracker_id => 1, | |
92 | :issue_status => { |
|
92 | :issue_status => { | |
93 | '4' => {'5' => ['always']}, |
|
93 | '4' => {'5' => ['always']}, | |
94 | '3' => {'1' => ['always'], '2' => ['always']} |
|
94 | '3' => {'1' => ['always'], '2' => ['always']} | |
95 | } |
|
95 | } | |
96 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
|
96 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
97 |
|
97 | |||
98 | assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
|
98 | assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count | |
99 | assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
|
99 | assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first | |
100 | assert_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first |
|
100 | assert_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def test_post_edit_with_additional_transitions |
|
103 | def test_post_edit_with_additional_transitions | |
104 | post :edit, :role_id => 2, :tracker_id => 1, |
|
104 | post :edit, :role_id => 2, :tracker_id => 1, | |
105 | :issue_status => { |
|
105 | :issue_status => { | |
106 | '4' => {'5' => ['always']}, |
|
106 | '4' => {'5' => ['always']}, | |
107 | '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} |
|
107 | '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} | |
108 | } |
|
108 | } | |
109 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
|
109 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
110 |
|
110 | |||
111 | assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
|
111 | assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count | |
112 |
|
112 | |||
113 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first |
|
113 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first | |
114 | assert ! w.author |
|
114 | assert ! w.author | |
115 | assert ! w.assignee |
|
115 | assert ! w.assignee | |
116 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first |
|
116 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first | |
117 | assert w.author |
|
117 | assert w.author | |
118 | assert ! w.assignee |
|
118 | assert ! w.assignee | |
119 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
|
119 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first | |
120 | assert ! w.author |
|
120 | assert ! w.author | |
121 | assert w.assignee |
|
121 | assert w.assignee | |
122 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first |
|
122 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first | |
123 | assert w.author |
|
123 | assert w.author | |
124 | assert w.assignee |
|
124 | assert w.assignee | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_clear_workflow |
|
127 | def test_clear_workflow | |
128 | assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 |
|
128 | assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 | |
129 |
|
129 | |||
130 | post :edit, :role_id => 2, :tracker_id => 1 |
|
130 | post :edit, :role_id => 2, :tracker_id => 1 | |
131 | assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
131 | assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_get_permissions |
|
134 | def test_get_permissions | |
135 | get :permissions |
|
135 | get :permissions | |
136 |
|
136 | |||
137 | assert_response :success |
|
137 | assert_response :success | |
138 | assert_template 'permissions' |
|
138 | assert_template 'permissions' | |
139 | assert_not_nil assigns(:roles) |
|
139 | assert_not_nil assigns(:roles) | |
140 | assert_not_nil assigns(:trackers) |
|
140 | assert_not_nil assigns(:trackers) | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def test_get_permissions_with_role_and_tracker |
|
143 | def test_get_permissions_with_role_and_tracker | |
144 | WorkflowPermission.delete_all |
|
144 | WorkflowPermission.delete_all | |
145 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') |
|
145 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
146 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
146 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
147 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
147 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
148 |
|
148 | |||
149 | get :permissions, :role_id => 1, :tracker_id => 2 |
|
149 | get :permissions, :role_id => 1, :tracker_id => 2 | |
150 | assert_response :success |
|
150 | assert_response :success | |
151 | assert_template 'permissions' |
|
151 | assert_template 'permissions' | |
152 |
|
152 | |||
153 | assert_select 'input[name=role_id][value=1]' |
|
153 | assert_select 'input[name=role_id][value=1]' | |
154 | assert_select 'input[name=tracker_id][value=2]' |
|
154 | assert_select 'input[name=tracker_id][value=2]' | |
155 |
|
155 | |||
156 | # Required field |
|
156 | # Required field | |
157 | assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do |
|
157 | assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do | |
158 | assert_select 'option[value=]' |
|
158 | assert_select 'option[value=]' | |
159 | assert_select 'option[value=][selected=selected]', 0 |
|
159 | assert_select 'option[value=][selected=selected]', 0 | |
160 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
160 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
161 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
161 | assert_select 'option[value=readonly][selected=selected]', 0 | |
162 | assert_select 'option[value=required]', :text => 'Required' |
|
162 | assert_select 'option[value=required]', :text => 'Required' | |
163 | assert_select 'option[value=required][selected=selected]' |
|
163 | assert_select 'option[value=required][selected=selected]' | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | # Read-only field |
|
166 | # Read-only field | |
167 | assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do |
|
167 | assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do | |
168 | assert_select 'option[value=]' |
|
168 | assert_select 'option[value=]' | |
169 | assert_select 'option[value=][selected=selected]', 0 |
|
169 | assert_select 'option[value=][selected=selected]', 0 | |
170 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
170 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
171 | assert_select 'option[value=readonly][selected=selected]' |
|
171 | assert_select 'option[value=readonly][selected=selected]' | |
172 | assert_select 'option[value=required]', :text => 'Required' |
|
172 | assert_select 'option[value=required]', :text => 'Required' | |
173 | assert_select 'option[value=required][selected=selected]', 0 |
|
173 | assert_select 'option[value=required][selected=selected]', 0 | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | # Other field |
|
176 | # Other field | |
177 | assert_select 'select[name=?]', 'permissions[due_date][3]' do |
|
177 | assert_select 'select[name=?]', 'permissions[due_date][3]' do | |
178 | assert_select 'option[value=]' |
|
178 | assert_select 'option[value=]' | |
179 | assert_select 'option[value=][selected=selected]', 0 |
|
179 | assert_select 'option[value=][selected=selected]', 0 | |
180 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
180 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
181 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
181 | assert_select 'option[value=readonly][selected=selected]', 0 | |
182 | assert_select 'option[value=required]', :text => 'Required' |
|
182 | assert_select 'option[value=required]', :text => 'Required' | |
183 | assert_select 'option[value=required][selected=selected]', 0 |
|
183 | assert_select 'option[value=required][selected=selected]', 0 | |
184 | end |
|
184 | end | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | def test_get_permissions_with_required_custom_field_should_not_show_required_option |
|
187 | def test_get_permissions_with_required_custom_field_should_not_show_required_option | |
188 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [1], :is_required => true) |
|
188 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [1], :is_required => true) | |
189 |
|
189 | |||
190 | get :permissions, :role_id => 1, :tracker_id => 1 |
|
190 | get :permissions, :role_id => 1, :tracker_id => 1 | |
191 | assert_response :success |
|
191 | assert_response :success | |
192 | assert_template 'permissions' |
|
192 | assert_template 'permissions' | |
193 |
|
193 | |||
194 | # Custom field that is always required |
|
194 | # Custom field that is always required | |
195 | # The default option is "(Required)" |
|
195 | # The default option is "(Required)" | |
196 | assert_select 'select[name=?]', "permissions[#{cf.id}][3]" do |
|
196 | assert_select 'select[name=?]', "permissions[#{cf.id}][3]" do | |
197 | assert_select 'option[value=]' |
|
197 | assert_select 'option[value=]' | |
198 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
198 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
199 | assert_select 'option[value=required]', 0 |
|
199 | assert_select 'option[value=required]', 0 | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_get_permissions_with_role_and_tracker_and_all_statuses |
|
203 | def test_get_permissions_with_role_and_tracker_and_all_statuses | |
204 | WorkflowTransition.delete_all |
|
204 | WorkflowTransition.delete_all | |
205 |
|
205 | |||
206 | get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' |
|
206 | get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' | |
207 | assert_response :success |
|
207 | assert_response :success | |
208 | assert_equal IssueStatus.sorted.all, assigns(:statuses) |
|
208 | assert_equal IssueStatus.sorted.all, assigns(:statuses) | |
209 | end |
|
209 | end | |
210 |
|
210 | |||
211 | def test_post_permissions |
|
211 | def test_post_permissions | |
212 | WorkflowPermission.delete_all |
|
212 | WorkflowPermission.delete_all | |
213 |
|
213 | |||
214 | post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { |
|
214 | post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { | |
215 | 'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''}, |
|
215 | 'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''}, | |
216 | 'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''}, |
|
216 | 'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''}, | |
217 | 'due_date' => {'1' => '', '2' => '', '3' => ''}, |
|
217 | 'due_date' => {'1' => '', '2' => '', '3' => ''}, | |
218 | } |
|
218 | } | |
219 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' |
|
219 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
220 |
|
220 | |||
221 | workflows = WorkflowPermission.all |
|
221 | workflows = WorkflowPermission.all | |
222 | assert_equal 3, workflows.size |
|
222 | assert_equal 3, workflows.size | |
223 | workflows.each do |workflow| |
|
223 | workflows.each do |workflow| | |
224 | assert_equal 1, workflow.role_id |
|
224 | assert_equal 1, workflow.role_id | |
225 | assert_equal 2, workflow.tracker_id |
|
225 | assert_equal 2, workflow.tracker_id | |
226 | end |
|
226 | end | |
227 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} |
|
227 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} | |
228 | assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} |
|
228 | assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} | |
229 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} |
|
229 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | def test_post_permissions_should_clear_permissions |
|
232 | def test_post_permissions_should_clear_permissions | |
233 | WorkflowPermission.delete_all |
|
233 | WorkflowPermission.delete_all | |
234 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') |
|
234 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
235 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
235 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
236 | wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
236 | wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
237 | wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
237 | wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
238 |
|
238 | |||
239 | post :permissions, :role_id => 1, :tracker_id => 2 |
|
239 | post :permissions, :role_id => 1, :tracker_id => 2 | |
240 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' |
|
240 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
241 |
|
241 | |||
242 | workflows = WorkflowPermission.all |
|
242 | workflows = WorkflowPermission.all | |
243 | assert_equal 2, workflows.size |
|
243 | assert_equal 2, workflows.size | |
244 | assert wf1.reload |
|
244 | assert wf1.reload | |
245 | assert wf2.reload |
|
245 | assert wf2.reload | |
246 | end |
|
246 | end | |
247 |
|
247 | |||
248 | def test_get_copy |
|
248 | def test_get_copy | |
249 | get :copy |
|
249 | get :copy | |
250 | assert_response :success |
|
250 | assert_response :success | |
251 | assert_template 'copy' |
|
251 | assert_template 'copy' | |
252 | assert_select 'select[name=source_tracker_id]' do |
|
252 | assert_select 'select[name=source_tracker_id]' do | |
253 | assert_select 'option[value=1]', :text => 'Bug' |
|
253 | assert_select 'option[value=1]', :text => 'Bug' | |
254 | end |
|
254 | end | |
255 | assert_select 'select[name=source_role_id]' do |
|
255 | assert_select 'select[name=source_role_id]' do | |
256 | assert_select 'option[value=2]', :text => 'Developer' |
|
256 | assert_select 'option[value=2]', :text => 'Developer' | |
257 | end |
|
257 | end | |
258 | assert_select 'select[name=?]', 'target_tracker_ids[]' do |
|
258 | assert_select 'select[name=?]', 'target_tracker_ids[]' do | |
259 | assert_select 'option[value=3]', :text => 'Support request' |
|
259 | assert_select 'option[value=3]', :text => 'Support request' | |
260 | end |
|
260 | end | |
261 | assert_select 'select[name=?]', 'target_role_ids[]' do |
|
261 | assert_select 'select[name=?]', 'target_role_ids[]' do | |
262 | assert_select 'option[value=1]', :text => 'Manager' |
|
262 | assert_select 'option[value=1]', :text => 'Manager' | |
263 | end |
|
263 | end | |
264 | end |
|
264 | end | |
265 |
|
265 | |||
266 | def test_post_copy_one_to_one |
|
266 | def test_post_copy_one_to_one | |
267 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
267 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
268 |
|
268 | |||
269 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
269 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
270 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] |
|
270 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] | |
271 | assert_response 302 |
|
271 | assert_response 302 | |
272 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
272 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
275 | def test_post_copy_one_to_many |
|
275 | def test_post_copy_one_to_many | |
276 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
276 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
277 |
|
277 | |||
278 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
278 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
279 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
279 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
280 | assert_response 302 |
|
280 | assert_response 302 | |
281 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) |
|
281 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) | |
282 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
282 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
283 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) |
|
283 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) | |
284 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) |
|
284 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) | |
285 | end |
|
285 | end | |
286 |
|
286 | |||
287 | def test_post_copy_many_to_many |
|
287 | def test_post_copy_many_to_many | |
288 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) |
|
288 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) | |
289 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) |
|
289 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) | |
290 |
|
290 | |||
291 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', |
|
291 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', | |
292 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
292 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
293 | assert_response 302 |
|
293 | assert_response 302 | |
294 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) |
|
294 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) | |
295 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) |
|
295 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) | |
296 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) |
|
296 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) | |
297 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) |
|
297 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
|
300 | def test_post_copy_with_incomplete_source_specification_should_fail | |||
|
301 | assert_no_difference 'WorkflowRule.count' do | |||
|
302 | post :copy, | |||
|
303 | :source_tracker_id => '', :source_role_id => '2', | |||
|
304 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |||
|
305 | assert_response 200 | |||
|
306 | assert_select 'div.flash.error', :text => 'Please select a source tracker or role' | |||
|
307 | end | |||
|
308 | end | |||
|
309 | ||||
|
310 | def test_post_copy_with_incomplete_target_specification_should_fail | |||
|
311 | assert_no_difference 'WorkflowRule.count' do | |||
|
312 | post :copy, | |||
|
313 | :source_tracker_id => '1', :source_role_id => '2', | |||
|
314 | :target_tracker_ids => ['2', '3'] | |||
|
315 | assert_response 200 | |||
|
316 | assert_select 'div.flash.error', :text => 'Please select target tracker(s) and role(s)' | |||
|
317 | end | |||
|
318 | end | |||
|
319 | ||||
300 | # Returns an array of status transitions that can be compared |
|
320 | # Returns an array of status transitions that can be compared | |
301 | def status_transitions(conditions) |
|
321 | def status_transitions(conditions) | |
302 | WorkflowTransition. |
|
322 | WorkflowTransition. | |
303 | where(conditions). |
|
323 | where(conditions). | |
304 | order('tracker_id, role_id, old_status_id, new_status_id'). |
|
324 | order('tracker_id, role_id, old_status_id, new_status_id'). | |
305 | all. |
|
325 | all. | |
306 | collect {|w| [w.old_status, w.new_status_id]} |
|
326 | collect {|w| [w.old_status, w.new_status_id]} | |
307 | end |
|
327 | end | |
308 | end |
|
328 | end |
General Comments 0
You need to be logged in to leave comments.
Login now