##// END OF EJS Templates
Use #find_issues as before filter for issues context menu....
Jean-Philippe Lang -
r11731:60d2a5e322cb
parent child
Show More
@@ -1,89 +1,87
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class ContextMenusController < ApplicationController
18 class ContextMenusController < ApplicationController
19 helper :watchers
19 helper :watchers
20 helper :issues
20 helper :issues
21
21
22 before_filter :find_issues, :only => :issues
23
22 def issues
24 def issues
23 @issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
24 (render_404; return) unless @issues.present?
25 if (@issues.size == 1)
25 if (@issues.size == 1)
26 @issue = @issues.first
26 @issue = @issues.first
27 end
27 end
28 @issue_ids = @issues.map(&:id).sort
28 @issue_ids = @issues.map(&:id).sort
29
29
30 @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
30 @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
31 @projects = @issues.collect(&:project).compact.uniq
32 @project = @projects.first if @projects.size == 1
33
31
34 @can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
32 @can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
35 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
33 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
36 :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
34 :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
37 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
35 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
38 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
36 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
39 :delete => User.current.allowed_to?(:delete_issues, @projects)
37 :delete => User.current.allowed_to?(:delete_issues, @projects)
40 }
38 }
41 if @project
39 if @project
42 if @issue
40 if @issue
43 @assignables = @issue.assignable_users
41 @assignables = @issue.assignable_users
44 else
42 else
45 @assignables = @project.assignable_users
43 @assignables = @project.assignable_users
46 end
44 end
47 @trackers = @project.trackers
45 @trackers = @project.trackers
48 else
46 else
49 #when multiple projects, we only keep the intersection of each set
47 #when multiple projects, we only keep the intersection of each set
50 @assignables = @projects.map(&:assignable_users).reduce(:&)
48 @assignables = @projects.map(&:assignable_users).reduce(:&)
51 @trackers = @projects.map(&:trackers).reduce(:&)
49 @trackers = @projects.map(&:trackers).reduce(:&)
52 end
50 end
53 @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
51 @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
54
52
55 @priorities = IssuePriority.active.reverse
53 @priorities = IssuePriority.active.reverse
56 @back = back_url
54 @back = back_url
57
55
58 @options_by_custom_field = {}
56 @options_by_custom_field = {}
59 if @can[:edit]
57 if @can[:edit]
60 custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f|
58 custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f|
61 %w(bool list user version).include?(f.field_format) && !f.multiple?
59 %w(bool list user version).include?(f.field_format) && !f.multiple?
62 end
60 end
63 custom_fields.each do |field|
61 custom_fields.each do |field|
64 values = field.possible_values_options(@projects)
62 values = field.possible_values_options(@projects)
65 if values.any?
63 if values.any?
66 @options_by_custom_field[field] = values
64 @options_by_custom_field[field] = values
67 end
65 end
68 end
66 end
69 end
67 end
70
68
71 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
69 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
72 render :layout => false
70 render :layout => false
73 end
71 end
74
72
75 def time_entries
73 def time_entries
76 @time_entries = TimeEntry.all(
74 @time_entries = TimeEntry.all(
77 :conditions => {:id => params[:ids]}, :include => :project)
75 :conditions => {:id => params[:ids]}, :include => :project)
78 (render_404; return) unless @time_entries.present?
76 (render_404; return) unless @time_entries.present?
79
77
80 @projects = @time_entries.collect(&:project).compact.uniq
78 @projects = @time_entries.collect(&:project).compact.uniq
81 @project = @projects.first if @projects.size == 1
79 @project = @projects.first if @projects.size == 1
82 @activities = TimeEntryActivity.shared.active
80 @activities = TimeEntryActivity.shared.active
83 @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects),
81 @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects),
84 :delete => User.current.allowed_to?(:edit_time_entries, @projects)
82 :delete => User.current.allowed_to?(:edit_time_entries, @projects)
85 }
83 }
86 @back = back_url
84 @back = back_url
87 render :layout => false
85 render :layout => false
88 end
86 end
89 end
87 end
@@ -1,252 +1,250
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class ContextMenusControllerTest < ActionController::TestCase
20 class ContextMenusControllerTest < ActionController::TestCase
21 fixtures :projects,
21 fixtures :projects,
22 :trackers,
22 :trackers,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :enabled_modules,
27 :enabled_modules,
28 :workflows,
28 :workflows,
29 :journals, :journal_details,
29 :journals, :journal_details,
30 :versions,
30 :versions,
31 :issues, :issue_statuses, :issue_categories,
31 :issues, :issue_statuses, :issue_categories,
32 :users,
32 :users,
33 :enumerations,
33 :enumerations,
34 :time_entries
34 :time_entries
35
35
36 def test_context_menu_one_issue
36 def test_context_menu_one_issue
37 @request.session[:user_id] = 2
37 @request.session[:user_id] = 2
38 get :issues, :ids => [1]
38 get :issues, :ids => [1]
39 assert_response :success
39 assert_response :success
40 assert_template 'context_menu'
40 assert_template 'context_menu'
41
41
42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
45
45
46 # Statuses
46 # Statuses
47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
49 # No inactive priorities
49 # No inactive priorities
50 assert_select 'a', :text => /Inactive Priority/, :count => 0
50 assert_select 'a', :text => /Inactive Priority/, :count => 0
51 # Versions
51 # Versions
52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
54 # Assignees
54 # Assignees
55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
56 end
56 end
57
57
58 def test_context_menu_one_issue_by_anonymous
58 def test_context_menu_one_issue_by_anonymous
59 get :issues, :ids => [1]
59 get :issues, :ids => [1]
60 assert_response :success
60 assert_response :success
61 assert_template 'context_menu'
61 assert_template 'context_menu'
62 assert_tag :tag => 'a', :content => 'Delete',
62 assert_tag :tag => 'a', :content => 'Delete',
63 :attributes => { :href => '#',
63 :attributes => { :href => '#',
64 :class => 'icon-del disabled' }
64 :class => 'icon-del disabled' }
65 end
65 end
66
66
67 def test_context_menu_multiple_issues_of_same_project
67 def test_context_menu_multiple_issues_of_same_project
68 @request.session[:user_id] = 2
68 @request.session[:user_id] = 2
69 get :issues, :ids => [1, 2]
69 get :issues, :ids => [1, 2]
70 assert_response :success
70 assert_response :success
71 assert_template 'context_menu'
71 assert_template 'context_menu'
72 assert_not_nil assigns(:issues)
72 assert_not_nil assigns(:issues)
73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
74
74
75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
76
76
77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
80
80
81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
84 end
84 end
85
85
86 def test_context_menu_multiple_issues_of_different_projects
86 def test_context_menu_multiple_issues_of_different_projects
87 @request.session[:user_id] = 2
87 @request.session[:user_id] = 2
88 get :issues, :ids => [1, 2, 6]
88 get :issues, :ids => [1, 2, 6]
89 assert_response :success
89 assert_response :success
90 assert_template 'context_menu'
90 assert_template 'context_menu'
91 assert_not_nil assigns(:issues)
91 assert_not_nil assigns(:issues)
92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
93
93
94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
95
95
96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
98
98
99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
102 end
102 end
103
103
104 def test_context_menu_should_include_list_custom_fields
104 def test_context_menu_should_include_list_custom_fields
105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
107 @request.session[:user_id] = 2
107 @request.session[:user_id] = 2
108 get :issues, :ids => [1]
108 get :issues, :ids => [1]
109
109
110 assert_select "li.cf_#{field.id}" do
110 assert_select "li.cf_#{field.id}" do
111 assert_select 'a[href=#]', :text => 'List'
111 assert_select 'a[href=#]', :text => 'List'
112 assert_select 'ul' do
112 assert_select 'ul' do
113 assert_select 'a', 3
113 assert_select 'a', 3
114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
116 end
116 end
117 end
117 end
118 end
118 end
119
119
120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
123 @request.session[:user_id] = 2
123 @request.session[:user_id] = 2
124 get :issues, :ids => [1, 2]
124 get :issues, :ids => [1, 2]
125
125
126 assert_select "li.cf_#{field.id}" do
126 assert_select "li.cf_#{field.id}" do
127 assert_select 'a[href=#]', :text => 'List'
127 assert_select 'a[href=#]', :text => 'List'
128 assert_select 'ul' do
128 assert_select 'ul' do
129 assert_select 'a', 2
129 assert_select 'a', 2
130 assert_select 'a', :text => 'none', :count => 0
130 assert_select 'a', :text => 'none', :count => 0
131 end
131 end
132 end
132 end
133 end
133 end
134
134
135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
138 issue = Issue.find(1)
138 issue = Issue.find(1)
139 issue.custom_field_values = {field.id => 'Bar'}
139 issue.custom_field_values = {field.id => 'Bar'}
140 issue.save!
140 issue.save!
141 @request.session[:user_id] = 2
141 @request.session[:user_id] = 2
142 get :issues, :ids => [1]
142 get :issues, :ids => [1]
143
143
144 assert_select "li.cf_#{field.id}" do
144 assert_select "li.cf_#{field.id}" do
145 assert_select 'a[href=#]', :text => 'List'
145 assert_select 'a[href=#]', :text => 'List'
146 assert_select 'ul' do
146 assert_select 'ul' do
147 assert_select 'a', 3
147 assert_select 'a', 3
148 assert_select 'a.icon-checked', :text => 'Bar'
148 assert_select 'a.icon-checked', :text => 'Bar'
149 end
149 end
150 end
150 end
151 end
151 end
152
152
153 def test_context_menu_should_include_bool_custom_fields
153 def test_context_menu_should_include_bool_custom_fields
154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
155 :is_for_all => true, :tracker_ids => [1, 2, 3])
155 :is_for_all => true, :tracker_ids => [1, 2, 3])
156 @request.session[:user_id] = 2
156 @request.session[:user_id] = 2
157 get :issues, :ids => [1]
157 get :issues, :ids => [1]
158
158
159 assert_select "li.cf_#{field.id}" do
159 assert_select "li.cf_#{field.id}" do
160 assert_select 'a[href=#]', :text => 'Bool'
160 assert_select 'a[href=#]', :text => 'Bool'
161 assert_select 'ul' do
161 assert_select 'ul' do
162 assert_select 'a', 3
162 assert_select 'a', 3
163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
166 end
166 end
167 end
167 end
168 end
168 end
169
169
170 def test_context_menu_should_include_user_custom_fields
170 def test_context_menu_should_include_user_custom_fields
171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
172 :is_for_all => true, :tracker_ids => [1, 2, 3])
172 :is_for_all => true, :tracker_ids => [1, 2, 3])
173 @request.session[:user_id] = 2
173 @request.session[:user_id] = 2
174 get :issues, :ids => [1]
174 get :issues, :ids => [1]
175
175
176 assert_select "li.cf_#{field.id}" do
176 assert_select "li.cf_#{field.id}" do
177 assert_select 'a[href=#]', :text => 'User'
177 assert_select 'a[href=#]', :text => 'User'
178 assert_select 'ul' do
178 assert_select 'ul' do
179 assert_select 'a', Project.find(1).members.count + 1
179 assert_select 'a', Project.find(1).members.count + 1
180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
182 end
182 end
183 end
183 end
184 end
184 end
185
185
186 def test_context_menu_should_include_version_custom_fields
186 def test_context_menu_should_include_version_custom_fields
187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
188 @request.session[:user_id] = 2
188 @request.session[:user_id] = 2
189 get :issues, :ids => [1]
189 get :issues, :ids => [1]
190
190
191 assert_select "li.cf_#{field.id}" do
191 assert_select "li.cf_#{field.id}" do
192 assert_select 'a[href=#]', :text => 'Version'
192 assert_select 'a[href=#]', :text => 'Version'
193 assert_select 'ul' do
193 assert_select 'ul' do
194 assert_select 'a', Project.find(1).shared_versions.count + 1
194 assert_select 'a', Project.find(1).shared_versions.count + 1
195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
197 end
197 end
198 end
198 end
199 end
199 end
200
200
201 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
201 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
202 @request.session[:user_id] = 2
202 @request.session[:user_id] = 2
203 get :issues, :ids => [1]
203 get :issues, :ids => [1]
204 assert_response :success
204 assert_response :success
205 assert_template 'context_menu'
205 assert_template 'context_menu'
206
206
207 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
207 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
208 end
208 end
209
209
210 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
210 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
211 @request.session[:user_id] = 2
211 @request.session[:user_id] = 2
212 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
212 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
213
213
214 get :issues, :ids => [1, 4]
214 get :issues, :ids => [1, 4]
215 assert_response :success
215 assert_response :success
216 assert_template 'context_menu'
216 assert_template 'context_menu'
217
217
218 assert_include version, assigns(:versions)
218 assert_include version, assigns(:versions)
219 assert_select 'a', :text => 'eCookbook - Shared'
219 assert_select 'a', :text => 'eCookbook - Shared'
220 end
220 end
221
221
222 def test_context_menu_issue_visibility
222 def test_context_menu_with_issue_that_is_not_visible_should_fail
223 get :issues, :ids => [1, 4]
223 get :issues, :ids => [1, 4] # issue 4 is not visible
224 assert_response :success
224 assert_response 302
225 assert_template 'context_menu'
226 assert_equal [1], assigns(:issues).collect(&:id)
227 end
225 end
228
226
229 def test_should_respond_with_404_without_ids
227 def test_should_respond_with_404_without_ids
230 get :issues
228 get :issues
231 assert_response 404
229 assert_response 404
232 end
230 end
233
231
234 def test_time_entries_context_menu
232 def test_time_entries_context_menu
235 @request.session[:user_id] = 2
233 @request.session[:user_id] = 2
236 get :time_entries, :ids => [1, 2]
234 get :time_entries, :ids => [1, 2]
237 assert_response :success
235 assert_response :success
238 assert_template 'time_entries'
236 assert_template 'time_entries'
239
237
240 assert_select 'a:not(.disabled)', :text => 'Edit'
238 assert_select 'a:not(.disabled)', :text => 'Edit'
241 end
239 end
242
240
243 def test_time_entries_context_menu_without_edit_permission
241 def test_time_entries_context_menu_without_edit_permission
244 @request.session[:user_id] = 2
242 @request.session[:user_id] = 2
245 Role.find_by_name('Manager').remove_permission! :edit_time_entries
243 Role.find_by_name('Manager').remove_permission! :edit_time_entries
246
244
247 get :time_entries, :ids => [1, 2]
245 get :time_entries, :ids => [1, 2]
248 assert_response :success
246 assert_response :success
249 assert_template 'time_entries'
247 assert_template 'time_entries'
250 assert_select 'a.disabled', :text => 'Edit'
248 assert_select 'a.disabled', :text => 'Edit'
251 end
249 end
252 end
250 end
General Comments 0
You need to be logged in to leave comments. Login now