@@ -1,276 +1,277 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | module QueriesHelper |
|
21 | 21 | include ApplicationHelper |
|
22 | 22 | |
|
23 | 23 | def filters_options_for_select(query) |
|
24 | 24 | ungrouped = [] |
|
25 | 25 | grouped = {} |
|
26 | 26 | query.available_filters.map do |field, field_options| |
|
27 | 27 | if [:tree, :relation].include?(field_options[:type]) |
|
28 | 28 | group = :label_related_issues |
|
29 | 29 | elsif field =~ /^(.+)\./ |
|
30 | 30 | # association filters |
|
31 | 31 | group = "field_#{$1}" |
|
32 | 32 | elsif %w(member_of_group assigned_to_role).include?(field) |
|
33 | 33 | group = :field_assigned_to |
|
34 | 34 | elsif field_options[:type] == :date_past || field_options[:type] == :date |
|
35 | 35 | group = :label_date |
|
36 | 36 | end |
|
37 | 37 | if group |
|
38 | 38 | (grouped[group] ||= []) << [field_options[:name], field] |
|
39 | 39 | else |
|
40 | 40 | ungrouped << [field_options[:name], field] |
|
41 | 41 | end |
|
42 | 42 | end |
|
43 | 43 | # Don't group dates if there's only one (eg. time entries filters) |
|
44 | 44 | if grouped[:label_date].try(:size) == 1 |
|
45 | 45 | ungrouped << grouped.delete(:label_date).first |
|
46 | 46 | end |
|
47 | 47 | s = options_for_select([[]] + ungrouped) |
|
48 | 48 | if grouped.present? |
|
49 | 49 | localized_grouped = grouped.map {|k,v| [l(k), v]} |
|
50 | 50 | s << grouped_options_for_select(localized_grouped) |
|
51 | 51 | end |
|
52 | 52 | s |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def query_filters_hidden_tags(query) |
|
56 | 56 | tags = ''.html_safe |
|
57 | 57 | query.filters.each do |field, options| |
|
58 | 58 | tags << hidden_field_tag("f[]", field, :id => nil) |
|
59 | 59 | tags << hidden_field_tag("op[#{field}]", options[:operator], :id => nil) |
|
60 | 60 | options[:values].each do |value| |
|
61 | 61 | tags << hidden_field_tag("v[#{field}][]", value, :id => nil) |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | tags |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def query_columns_hidden_tags(query) |
|
68 | 68 | tags = ''.html_safe |
|
69 | 69 | query.columns.each do |column| |
|
70 | 70 | tags << hidden_field_tag("c[]", column.name, :id => nil) |
|
71 | 71 | end |
|
72 | 72 | tags |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def query_hidden_tags(query) |
|
76 | 76 | query_filters_hidden_tags(query) + query_columns_hidden_tags(query) |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | def available_block_columns_tags(query) |
|
80 | 80 | tags = ''.html_safe |
|
81 | 81 | query.available_block_columns.each do |column| |
|
82 | 82 | tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column), :id => nil) + " #{column.caption}", :class => 'inline') |
|
83 | 83 | end |
|
84 | 84 | tags |
|
85 | 85 | end |
|
86 | 86 | |
|
87 | 87 | def available_totalable_columns_tags(query) |
|
88 | 88 | tags = ''.html_safe |
|
89 | 89 | query.available_totalable_columns.each do |column| |
|
90 | 90 | tags << content_tag('label', check_box_tag('t[]', column.name.to_s, query.totalable_columns.include?(column), :id => nil) + " #{column.caption}", :class => 'inline') |
|
91 | 91 | end |
|
92 | tags << hidden_field_tag('t[]', '') | |
|
92 | 93 | tags |
|
93 | 94 | end |
|
94 | 95 | |
|
95 | 96 | def query_available_inline_columns_options(query) |
|
96 | 97 | (query.available_inline_columns - query.columns).reject(&:frozen?).collect {|column| [column.caption, column.name]} |
|
97 | 98 | end |
|
98 | 99 | |
|
99 | 100 | def query_selected_inline_columns_options(query) |
|
100 | 101 | (query.inline_columns & query.available_inline_columns).reject(&:frozen?).collect {|column| [column.caption, column.name]} |
|
101 | 102 | end |
|
102 | 103 | |
|
103 | 104 | def render_query_columns_selection(query, options={}) |
|
104 | 105 | tag_name = (options[:name] || 'c') + '[]' |
|
105 | 106 | render :partial => 'queries/columns', :locals => {:query => query, :tag_name => tag_name} |
|
106 | 107 | end |
|
107 | 108 | |
|
108 | 109 | def render_query_totals(query) |
|
109 | 110 | return unless query.totalable_columns.present? |
|
110 | 111 | totals = query.totalable_columns.map do |column| |
|
111 | 112 | total_tag(column, query.total_for(column)) |
|
112 | 113 | end |
|
113 | 114 | content_tag('p', totals.join(" ").html_safe, :class => "query-totals") |
|
114 | 115 | end |
|
115 | 116 | |
|
116 | 117 | def total_tag(column, value) |
|
117 | 118 | label = content_tag('span', "#{column.caption}:") |
|
118 | 119 | value = content_tag('span', format_object(value), :class => 'value') |
|
119 | 120 | content_tag('span', label + " " + value, :class => "total-for-#{column.name.to_s.dasherize}") |
|
120 | 121 | end |
|
121 | 122 | |
|
122 | 123 | def column_header(column) |
|
123 | 124 | column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, |
|
124 | 125 | :default_order => column.default_order) : |
|
125 | 126 | content_tag('th', h(column.caption)) |
|
126 | 127 | end |
|
127 | 128 | |
|
128 | 129 | def column_content(column, issue) |
|
129 | 130 | value = column.value_object(issue) |
|
130 | 131 | if value.is_a?(Array) |
|
131 | 132 | value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe |
|
132 | 133 | else |
|
133 | 134 | column_value(column, issue, value) |
|
134 | 135 | end |
|
135 | 136 | end |
|
136 | 137 | |
|
137 | 138 | def column_value(column, issue, value) |
|
138 | 139 | case column.name |
|
139 | 140 | when :id |
|
140 | 141 | link_to value, issue_path(issue) |
|
141 | 142 | when :subject |
|
142 | 143 | link_to value, issue_path(issue) |
|
143 | 144 | when :parent |
|
144 | 145 | value ? (value.visible? ? link_to_issue(value, :subject => false) : "##{value.id}") : '' |
|
145 | 146 | when :description |
|
146 | 147 | issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : '' |
|
147 | 148 | when :done_ratio |
|
148 | 149 | progress_bar(value) |
|
149 | 150 | when :relations |
|
150 | 151 | content_tag('span', |
|
151 | 152 | value.to_s(issue) {|other| link_to_issue(other, :subject => false, :tracker => false)}.html_safe, |
|
152 | 153 | :class => value.css_classes_for(issue)) |
|
153 | 154 | else |
|
154 | 155 | format_object(value) |
|
155 | 156 | end |
|
156 | 157 | end |
|
157 | 158 | |
|
158 | 159 | def csv_content(column, issue) |
|
159 | 160 | value = column.value_object(issue) |
|
160 | 161 | if value.is_a?(Array) |
|
161 | 162 | value.collect {|v| csv_value(column, issue, v)}.compact.join(', ') |
|
162 | 163 | else |
|
163 | 164 | csv_value(column, issue, value) |
|
164 | 165 | end |
|
165 | 166 | end |
|
166 | 167 | |
|
167 | 168 | def csv_value(column, object, value) |
|
168 | 169 | format_object(value, false) do |value| |
|
169 | 170 | case value.class.name |
|
170 | 171 | when 'Float' |
|
171 | 172 | sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) |
|
172 | 173 | when 'IssueRelation' |
|
173 | 174 | value.to_s(object) |
|
174 | 175 | when 'Issue' |
|
175 | 176 | if object.is_a?(TimeEntry) |
|
176 | 177 | "#{value.tracker} ##{value.id}: #{value.subject}" |
|
177 | 178 | else |
|
178 | 179 | value.id |
|
179 | 180 | end |
|
180 | 181 | else |
|
181 | 182 | value |
|
182 | 183 | end |
|
183 | 184 | end |
|
184 | 185 | end |
|
185 | 186 | |
|
186 | 187 | def query_to_csv(items, query, options={}) |
|
187 | 188 | options ||= {} |
|
188 | 189 | columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) |
|
189 | 190 | query.available_block_columns.each do |column| |
|
190 | 191 | if options[column.name].present? |
|
191 | 192 | columns << column |
|
192 | 193 | end |
|
193 | 194 | end |
|
194 | 195 | |
|
195 | 196 | Redmine::Export::CSV.generate do |csv| |
|
196 | 197 | # csv header fields |
|
197 | 198 | csv << columns.map {|c| c.caption.to_s} |
|
198 | 199 | # csv lines |
|
199 | 200 | items.each do |item| |
|
200 | 201 | csv << columns.map {|c| csv_content(c, item)} |
|
201 | 202 | end |
|
202 | 203 | end |
|
203 | 204 | end |
|
204 | 205 | |
|
205 | 206 | # Retrieve query from session or build a new query |
|
206 | 207 | def retrieve_query |
|
207 | 208 | if !params[:query_id].blank? |
|
208 | 209 | cond = "project_id IS NULL" |
|
209 | 210 | cond << " OR project_id = #{@project.id}" if @project |
|
210 | 211 | @query = IssueQuery.where(cond).find(params[:query_id]) |
|
211 | 212 | raise ::Unauthorized unless @query.visible? |
|
212 | 213 | @query.project = @project |
|
213 | 214 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
214 | 215 | sort_clear |
|
215 | 216 | elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
216 | 217 | # Give it a name, required to be valid |
|
217 | 218 | @query = IssueQuery.new(:name => "_") |
|
218 | 219 | @query.project = @project |
|
219 | 220 | @query.build_from_params(params) |
|
220 | 221 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names, :totalable_names => @query.totalable_names} |
|
221 | 222 | else |
|
222 | 223 | # retrieve from session |
|
223 | 224 | @query = nil |
|
224 | 225 | @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] |
|
225 | 226 | @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names], :totalable_names => session[:query][:totalable_names]) |
|
226 | 227 | @query.project = @project |
|
227 | 228 | end |
|
228 | 229 | end |
|
229 | 230 | |
|
230 | 231 | def retrieve_query_from_session |
|
231 | 232 | if session[:query] |
|
232 | 233 | if session[:query][:id] |
|
233 | 234 | @query = IssueQuery.find_by_id(session[:query][:id]) |
|
234 | 235 | return unless @query |
|
235 | 236 | else |
|
236 | 237 | @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names], :totalable_names => session[:query][:totalable_names]) |
|
237 | 238 | end |
|
238 | 239 | if session[:query].has_key?(:project_id) |
|
239 | 240 | @query.project_id = session[:query][:project_id] |
|
240 | 241 | else |
|
241 | 242 | @query.project = @project |
|
242 | 243 | end |
|
243 | 244 | @query |
|
244 | 245 | end |
|
245 | 246 | end |
|
246 | 247 | |
|
247 | 248 | # Returns the query definition as hidden field tags |
|
248 | 249 | def query_as_hidden_field_tags(query) |
|
249 | 250 | tags = hidden_field_tag("set_filter", "1", :id => nil) |
|
250 | 251 | |
|
251 | 252 | if query.filters.present? |
|
252 | 253 | query.filters.each do |field, filter| |
|
253 | 254 | tags << hidden_field_tag("f[]", field, :id => nil) |
|
254 | 255 | tags << hidden_field_tag("op[#{field}]", filter[:operator], :id => nil) |
|
255 | 256 | filter[:values].each do |value| |
|
256 | 257 | tags << hidden_field_tag("v[#{field}][]", value, :id => nil) |
|
257 | 258 | end |
|
258 | 259 | end |
|
259 | 260 | end |
|
260 | 261 | if query.column_names.present? |
|
261 | 262 | query.column_names.each do |name| |
|
262 | 263 | tags << hidden_field_tag("c[]", name, :id => nil) |
|
263 | 264 | end |
|
264 | 265 | end |
|
265 | 266 | if query.totalable_names.present? |
|
266 | 267 | query.totalable_names.each do |name| |
|
267 | 268 | tags << hidden_field_tag("t[]", name, :id => nil) |
|
268 | 269 | end |
|
269 | 270 | end |
|
270 | 271 | if query.group_by.present? |
|
271 | 272 | tags << hidden_field_tag("group_by", query.group_by, :id => nil) |
|
272 | 273 | end |
|
273 | 274 | |
|
274 | 275 | tags |
|
275 | 276 | end |
|
276 | 277 | end |
@@ -1,293 +1,313 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../base', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base |
|
21 | 21 | fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, |
|
22 | 22 | :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues, |
|
23 | 23 | :enumerations, :custom_fields, :custom_values, :custom_fields_trackers, |
|
24 | 24 | :watchers, :journals, :journal_details |
|
25 | 25 | |
|
26 | 26 | def test_create_issue |
|
27 | 27 | log_user('jsmith', 'jsmith') |
|
28 | 28 | visit '/projects/ecookbook/issues/new' |
|
29 | 29 | within('form#issue-form') do |
|
30 | 30 | select 'Bug', :from => 'Tracker' |
|
31 | 31 | select 'Low', :from => 'Priority' |
|
32 | 32 | fill_in 'Subject', :with => 'new test issue' |
|
33 | 33 | fill_in 'Description', :with => 'new issue' |
|
34 | 34 | select '0 %', :from => 'Done' |
|
35 | 35 | fill_in 'Due date', :with => '' |
|
36 | 36 | fill_in 'Searchable field', :with => 'Value for field 2' |
|
37 | 37 | # click_button 'Create' would match both 'Create' and 'Create and continue' buttons |
|
38 | 38 | find('input[name=commit]').click |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | # find created issue |
|
42 | 42 | issue = Issue.find_by_subject("new test issue") |
|
43 | 43 | assert_kind_of Issue, issue |
|
44 | 44 | |
|
45 | 45 | # check redirection |
|
46 | 46 | find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created." |
|
47 | 47 | assert_equal issue_path(:id => issue), current_path |
|
48 | 48 | |
|
49 | 49 | # check issue attributes |
|
50 | 50 | assert_equal 'jsmith', issue.author.login |
|
51 | 51 | assert_equal 1, issue.project.id |
|
52 | 52 | assert_equal IssueStatus.find_by_name('New'), issue.status |
|
53 | 53 | assert_equal Tracker.find_by_name('Bug'), issue.tracker |
|
54 | 54 | assert_equal IssuePriority.find_by_name('Low'), issue.priority |
|
55 | 55 | assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field')) |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_create_issue_with_form_update |
|
59 | 59 | field1 = IssueCustomField.create!( |
|
60 | 60 | :field_format => 'string', |
|
61 | 61 | :name => 'Field1', |
|
62 | 62 | :is_for_all => true, |
|
63 | 63 | :trackers => Tracker.where(:id => [1, 2]) |
|
64 | 64 | ) |
|
65 | 65 | field2 = IssueCustomField.create!( |
|
66 | 66 | :field_format => 'string', |
|
67 | 67 | :name => 'Field2', |
|
68 | 68 | :is_for_all => true, |
|
69 | 69 | :trackers => Tracker.where(:id => 2) |
|
70 | 70 | ) |
|
71 | 71 | |
|
72 | 72 | Role.non_member.add_permission! :add_issues |
|
73 | 73 | Role.non_member.remove_permission! :edit_issues, :add_issue_notes |
|
74 | 74 | |
|
75 | 75 | log_user('someone', 'foo') |
|
76 | 76 | visit '/projects/ecookbook/issues/new' |
|
77 | 77 | assert page.has_no_content?(field2.name) |
|
78 | 78 | assert page.has_content?(field1.name) |
|
79 | 79 | |
|
80 | 80 | fill_in 'Subject', :with => 'New test issue' |
|
81 | 81 | fill_in 'Description', :with => 'New test issue description' |
|
82 | 82 | fill_in field1.name, :with => 'CF1 value' |
|
83 | 83 | select 'Low', :from => 'Priority' |
|
84 | 84 | |
|
85 | 85 | # field2 should show up when changing tracker |
|
86 | 86 | select 'Feature request', :from => 'Tracker' |
|
87 | 87 | assert page.has_content?(field2.name) |
|
88 | 88 | assert page.has_content?(field1.name) |
|
89 | 89 | |
|
90 | 90 | fill_in field2.name, :with => 'CF2 value' |
|
91 | 91 | assert_difference 'Issue.count' do |
|
92 | 92 | page.first(:button, 'Create').click |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | issue = Issue.order('id desc').first |
|
96 | 96 | assert_equal 'New test issue', issue.subject |
|
97 | 97 | assert_equal 'New test issue description', issue.description |
|
98 | 98 | assert_equal 'Low', issue.priority.name |
|
99 | 99 | assert_equal 'CF1 value', issue.custom_field_value(field1) |
|
100 | 100 | assert_equal 'CF2 value', issue.custom_field_value(field2) |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | def test_create_issue_with_watchers |
|
104 | 104 | user = User.generate!(:firstname => 'Some', :lastname => 'Watcher') |
|
105 | 105 | assert_equal 'Some Watcher', user.name |
|
106 | 106 | log_user('jsmith', 'jsmith') |
|
107 | 107 | visit '/projects/ecookbook/issues/new' |
|
108 | 108 | fill_in 'Subject', :with => 'Issue with watchers' |
|
109 | 109 | # Add a project member as watcher |
|
110 | 110 | check 'Dave Lopper' |
|
111 | 111 | # Search for another user |
|
112 | 112 | assert page.has_no_css?('form#new-watcher-form') |
|
113 | 113 | assert page.has_no_content?('Some Watcher') |
|
114 | 114 | click_link 'Search for watchers to add' |
|
115 | 115 | within('form#new-watcher-form') do |
|
116 | 116 | fill_in 'user_search', :with => 'watch' |
|
117 | 117 | assert page.has_content?('Some Watcher') |
|
118 | 118 | check 'Some Watcher' |
|
119 | 119 | click_button 'Add' |
|
120 | 120 | end |
|
121 | 121 | assert page.has_css?('form#issue-form') |
|
122 | 122 | assert page.has_css?('p#watchers_form') |
|
123 | 123 | using_wait_time(30) do |
|
124 | 124 | within('span#watchers_inputs') do |
|
125 | 125 | within("label#issue_watcher_user_ids_#{user.id}") do |
|
126 | 126 | assert has_content?('Some Watcher'), "No watcher content" |
|
127 | 127 | end |
|
128 | 128 | end |
|
129 | 129 | end |
|
130 | 130 | assert_difference 'Issue.count' do |
|
131 | 131 | find('input[name=commit]').click |
|
132 | 132 | end |
|
133 | 133 | |
|
134 | 134 | issue = Issue.order('id desc').first |
|
135 | 135 | assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def test_create_issue_start_due_date |
|
139 | 139 | with_settings :default_issue_start_date_to_creation_date => 0 do |
|
140 | 140 | log_user('jsmith', 'jsmith') |
|
141 | 141 | visit '/projects/ecookbook/issues/new' |
|
142 | 142 | assert_equal "", page.find('input#issue_start_date').value |
|
143 | 143 | assert_equal "", page.find('input#issue_due_date').value |
|
144 | 144 | page.first('p#start_date_area img').click |
|
145 | 145 | page.first("td.ui-datepicker-days-cell-over a").click |
|
146 | 146 | assert_equal Date.today.to_s, page.find('input#issue_start_date').value |
|
147 | 147 | page.first('p#due_date_area img').click |
|
148 | 148 | page.first("td.ui-datepicker-days-cell-over a").click |
|
149 | 149 | assert_equal Date.today.to_s, page.find('input#issue_due_date').value |
|
150 | 150 | end |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | def test_default_due_date_proposed_in_date_picker |
|
154 | 154 | log_user('jsmith', 'jsmith') |
|
155 | 155 | visit '/projects/ecookbook/issues/new' |
|
156 | 156 | |
|
157 | 157 | # Future start date: due date should default to start date |
|
158 | 158 | fill_in 'Start date', :with => '2027-04-01' |
|
159 | 159 | fill_in 'Due date', :with => '' |
|
160 | 160 | page.first('p#due_date_area img').click |
|
161 | 161 | page.first("td.ui-datepicker-days-cell-over a").click |
|
162 | 162 | assert_equal '2027-04-01', page.find('input#issue_due_date').value |
|
163 | 163 | |
|
164 | 164 | # Passed start date: due date should default to today |
|
165 | 165 | fill_in 'Start date', :with => '2012-04-01' |
|
166 | 166 | fill_in 'Due date', :with => '' |
|
167 | 167 | page.first('p#due_date_area img').click |
|
168 | 168 | page.first("td.ui-datepicker-days-cell-over a").click |
|
169 | 169 | assert_equal Date.today.to_s, page.find('input#issue_due_date').value |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | def test_default_start_date_proposed_in_date_picker |
|
173 | 173 | log_user('jsmith', 'jsmith') |
|
174 | 174 | visit '/projects/ecookbook/issues/new' |
|
175 | 175 | |
|
176 | 176 | # Passed due date: start date should default to due date |
|
177 | 177 | fill_in 'Start date', :with => '' |
|
178 | 178 | fill_in 'Due date', :with => '2012-04-01' |
|
179 | 179 | page.first('p#start_date_area img').click |
|
180 | 180 | page.first("td.ui-datepicker-days-cell-over a").click |
|
181 | 181 | assert_equal '2012-04-01', page.find('input#issue_start_date').value |
|
182 | 182 | end |
|
183 | 183 | |
|
184 | 184 | def test_preview_issue_description |
|
185 | 185 | log_user('jsmith', 'jsmith') |
|
186 | 186 | visit '/projects/ecookbook/issues/new' |
|
187 | 187 | within('form#issue-form') do |
|
188 | 188 | fill_in 'Subject', :with => 'new issue subject' |
|
189 | 189 | fill_in 'Description', :with => 'new issue description' |
|
190 | 190 | click_link 'Preview' |
|
191 | 191 | end |
|
192 | 192 | find 'div#preview fieldset', :visible => true, :text => 'new issue description' |
|
193 | 193 | assert_difference 'Issue.count' do |
|
194 | 194 | find('input[name=commit]').click |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | issue = Issue.order('id desc').first |
|
198 | 198 | assert_equal 'new issue description', issue.description |
|
199 | 199 | end |
|
200 | 200 | |
|
201 | 201 | def test_update_issue_with_form_update |
|
202 | 202 | field = IssueCustomField.create!( |
|
203 | 203 | :field_format => 'string', |
|
204 | 204 | :name => 'Form update CF', |
|
205 | 205 | :is_for_all => true, |
|
206 | 206 | :trackers => Tracker.where(:name => 'Feature request') |
|
207 | 207 | ) |
|
208 | 208 | |
|
209 | 209 | Role.non_member.add_permission! :edit_issues |
|
210 | 210 | Role.non_member.remove_permission! :add_issues, :add_issue_notes |
|
211 | 211 | |
|
212 | 212 | log_user('someone', 'foo') |
|
213 | 213 | visit '/issues/1' |
|
214 | 214 | assert page.has_no_content?('Form update CF') |
|
215 | 215 | |
|
216 | 216 | page.first(:link, 'Edit').click |
|
217 | 217 | # the custom field should show up when changing tracker |
|
218 | 218 | select 'Feature request', :from => 'Tracker' |
|
219 | 219 | assert page.has_content?('Form update CF') |
|
220 | 220 | |
|
221 | 221 | fill_in 'Form update', :with => 'CF value' |
|
222 | 222 | assert_no_difference 'Issue.count' do |
|
223 | 223 | page.first(:button, 'Submit').click |
|
224 | 224 | end |
|
225 | 225 | |
|
226 | 226 | issue = Issue.find(1) |
|
227 | 227 | assert_equal 'CF value', issue.custom_field_value(field) |
|
228 | 228 | end |
|
229 | 229 | |
|
230 | 230 | def test_remove_issue_watcher_from_sidebar |
|
231 | 231 | user = User.find(3) |
|
232 | 232 | Watcher.create!(:watchable => Issue.find(1), :user => user) |
|
233 | 233 | |
|
234 | 234 | log_user('jsmith', 'jsmith') |
|
235 | 235 | visit '/issues/1' |
|
236 | 236 | assert page.first('#sidebar').has_content?('Watchers (1)') |
|
237 | 237 | assert page.first('#sidebar').has_content?(user.name) |
|
238 | 238 | assert_difference 'Watcher.count', -1 do |
|
239 | 239 | page.first('ul.watchers .user-3 a.delete').click |
|
240 | 240 | assert page.first('#sidebar').has_content?('Watchers (0)') |
|
241 | 241 | end |
|
242 | 242 | assert page.first('#sidebar').has_no_content?(user.name) |
|
243 | 243 | end |
|
244 | 244 | |
|
245 | 245 | def test_watch_should_update_watchers_list |
|
246 | 246 | user = User.find(2) |
|
247 | 247 | log_user('jsmith', 'jsmith') |
|
248 | 248 | visit '/issues/1' |
|
249 | 249 | assert page.first('#sidebar').has_content?('Watchers (0)') |
|
250 | 250 | |
|
251 | 251 | page.first('a.issue-1-watcher').click |
|
252 | 252 | assert page.first('#sidebar').has_content?('Watchers (1)') |
|
253 | 253 | assert page.first('#sidebar').has_content?(user.name) |
|
254 | 254 | end |
|
255 | 255 | |
|
256 | 256 | def test_watch_issue_via_context_menu |
|
257 | 257 | log_user('jsmith', 'jsmith') |
|
258 | 258 | visit '/issues' |
|
259 | 259 | assert page.has_css?('tr#issue-1') |
|
260 | 260 | find('tr#issue-1 td.updated_on').click |
|
261 | 261 | page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');" |
|
262 | 262 | assert_difference 'Watcher.count' do |
|
263 | 263 | within('#context-menu') do |
|
264 | 264 | click_link 'Watch' |
|
265 | 265 | end |
|
266 | 266 | # wait for ajax response |
|
267 | 267 | assert page.has_css?('#context-menu .issue-1-watcher.icon-fav') |
|
268 | 268 | assert page.has_css?('tr#issue-1') |
|
269 | 269 | end |
|
270 | 270 | assert Issue.find(1).watched_by?(User.find_by_login('jsmith')) |
|
271 | 271 | end |
|
272 | 272 | |
|
273 | 273 | def test_bulk_watch_issues_via_context_menu |
|
274 | 274 | log_user('jsmith', 'jsmith') |
|
275 | 275 | visit '/issues' |
|
276 | 276 | assert page.has_css?('tr#issue-1') |
|
277 | 277 | assert page.has_css?('tr#issue-4') |
|
278 | 278 | find('tr#issue-1 input[type=checkbox]').click |
|
279 | 279 | find('tr#issue-4 input[type=checkbox]').click |
|
280 | 280 | page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');" |
|
281 | 281 | assert_difference 'Watcher.count', 2 do |
|
282 | 282 | within('#context-menu') do |
|
283 | 283 | click_link 'Watch' |
|
284 | 284 | end |
|
285 | 285 | # wait for ajax response |
|
286 | 286 | assert page.has_css?('#context-menu .issue-bulk-watcher.icon-fav') |
|
287 | 287 | assert page.has_css?('tr#issue-1') |
|
288 | 288 | assert page.has_css?('tr#issue-4') |
|
289 | 289 | end |
|
290 | 290 | assert Issue.find(1).watched_by?(User.find_by_login('jsmith')) |
|
291 | 291 | assert Issue.find(4).watched_by?(User.find_by_login('jsmith')) |
|
292 | 292 | end |
|
293 | ||
|
294 | def test_issue_list_with_default_totalable_columns | |
|
295 | log_user('admin', 'admin') | |
|
296 | with_settings :issue_list_default_totals => ['estimated_hours'] do | |
|
297 | visit '/projects/ecookbook/issues' | |
|
298 | # Check that the page shows the Estimated hours total | |
|
299 | assert page.has_css?('p.query-totals') | |
|
300 | assert page.has_css?('span.total-for-estimated-hours') | |
|
301 | # Open the Options of the form (necessary for having the totalable columns options clickable) | |
|
302 | page.all('legend')[1].click | |
|
303 | # Deselect the default totalable column (none should be left) | |
|
304 | page.first('input[name="t[]"][value="estimated_hours"]').click | |
|
305 | within('#query_form') do | |
|
306 | click_link 'Apply' | |
|
307 | end | |
|
308 | # Check that Totals are not present in the reloaded page | |
|
309 | assert !page.has_css?('p.query-totals') | |
|
310 | assert !page.has_css?('span.total-for-estimated-hours') | |
|
311 | end | |
|
312 | end | |
|
293 | 313 | end |
General Comments 0
You need to be logged in to leave comments.
Login now