]> source.dussan.org Git - redmine.git/commitdiff
Merged r4553 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 23 Dec 2010 10:00:35 +0000 (10:00 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 23 Dec 2010 10:00:35 +0000 (10:00 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.0-stable@4565 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/unit/query_test.rb

index b1f784528d069ffc37049c88ff9e811513df3590..ec56864def1600fae8e4148e8ae52ef646d119f4 100644 (file)
@@ -368,15 +368,15 @@ class Query < ActiveRecord::Base
   
   # Returns true if the query is a grouped query
   def grouped?
-    !group_by.blank?
+    !group_by_column.nil?
   end
   
   def group_by_column
-    groupable_columns.detect {|c| c.name.to_s == group_by}
+    groupable_columns.detect {|c| c.groupable && c.name.to_s == group_by}
   end
   
   def group_by_statement
-    group_by_column.groupable
+    group_by_column.try(:groupable)
   end
   
   def project_statement
index 12ab5d93267fc42dd0dd9ab65358193f93329a19..148e5d1514439477865fabb9502a858ff41898db 100644 (file)
@@ -225,6 +225,22 @@ class QueryTest < ActiveSupport::TestCase
     q = Query.new
     assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
   end
+
+  def test_grouped_with_valid_column
+    q = Query.new(:group_by => 'status')
+    assert q.grouped?
+    assert_not_nil q.group_by_column
+    assert_equal :status, q.group_by_column.name
+    assert_not_nil q.group_by_statement
+    assert_equal 'status', q.group_by_statement
+  end
+  
+  def test_grouped_with_invalid_column
+    q = Query.new(:group_by => 'foo')
+    assert !q.grouped?
+    assert_nil q.group_by_column
+    assert_nil q.group_by_statement
+  end
   
   def test_default_sort
     q = Query.new