##// END OF EJS Templates
Fixed: 500 error on issue query grouped by a custom field that was deleted (#7144)....
Jean-Philippe Lang -
r4439:703b0ec422bb
parent child
Show More
@@ -378,15 +378,15 class Query < ActiveRecord::Base
378
378
379 # Returns true if the query is a grouped query
379 # Returns true if the query is a grouped query
380 def grouped?
380 def grouped?
381 !group_by.blank?
381 !group_by_column.nil?
382 end
382 end
383
383
384 def group_by_column
384 def group_by_column
385 groupable_columns.detect {|c| c.name.to_s == group_by}
385 groupable_columns.detect {|c| c.groupable && c.name.to_s == group_by}
386 end
386 end
387
387
388 def group_by_statement
388 def group_by_statement
389 group_by_column.groupable
389 group_by_column.try(:groupable)
390 end
390 end
391
391
392 def project_statement
392 def project_statement
@@ -235,6 +235,22 class QueryTest < ActiveSupport::TestCase
235 q = Query.new
235 q = Query.new
236 assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
236 assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
237 end
237 end
238
239 def test_grouped_with_valid_column
240 q = Query.new(:group_by => 'status')
241 assert q.grouped?
242 assert_not_nil q.group_by_column
243 assert_equal :status, q.group_by_column.name
244 assert_not_nil q.group_by_statement
245 assert_equal 'status', q.group_by_statement
246 end
247
248 def test_grouped_with_invalid_column
249 q = Query.new(:group_by => 'foo')
250 assert !q.grouped?
251 assert_nil q.group_by_column
252 assert_nil q.group_by_statement
253 end
238
254
239 def test_default_sort
255 def test_default_sort
240 q = Query.new
256 q = Query.new
General Comments 0
You need to be logged in to leave comments. Login now