##// END OF EJS Templates
Merged r4553 from trunk....
Jean-Philippe Lang -
r4451:902d765ab7ec
parent child
Show More
@@ -368,15 +368,15 class Query < ActiveRecord::Base
368
368
369 # Returns true if the query is a grouped query
369 # Returns true if the query is a grouped query
370 def grouped?
370 def grouped?
371 !group_by.blank?
371 !group_by_column.nil?
372 end
372 end
373
373
374 def group_by_column
374 def group_by_column
375 groupable_columns.detect {|c| c.name.to_s == group_by}
375 groupable_columns.detect {|c| c.groupable && c.name.to_s == group_by}
376 end
376 end
377
377
378 def group_by_statement
378 def group_by_statement
379 group_by_column.groupable
379 group_by_column.try(:groupable)
380 end
380 end
381
381
382 def project_statement
382 def project_statement
@@ -225,6 +225,22 class QueryTest < ActiveSupport::TestCase
225 q = Query.new
225 q = Query.new
226 assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
226 assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
227 end
227 end
228
229 def test_grouped_with_valid_column
230 q = Query.new(:group_by => 'status')
231 assert q.grouped?
232 assert_not_nil q.group_by_column
233 assert_equal :status, q.group_by_column.name
234 assert_not_nil q.group_by_statement
235 assert_equal 'status', q.group_by_statement
236 end
237
238 def test_grouped_with_invalid_column
239 q = Query.new(:group_by => 'foo')
240 assert !q.grouped?
241 assert_nil q.group_by_column
242 assert_nil q.group_by_statement
243 end
228
244
229 def test_default_sort
245 def test_default_sort
230 q = Query.new
246 q = Query.new
General Comments 0
You need to be logged in to leave comments. Login now