]> source.dussan.org Git - redmine.git/commitdiff
Fixed: 500 error on issue query grouped by a custom field that was deleted (#7144).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 21 Dec 2010 21:46:54 +0000 (21:46 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 21 Dec 2010 21:46:54 +0000 (21:46 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4553 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 94905453306c380937bf2305958130b339a79de6..1f033048ad6755340571bf1e0a8a25d57c290cea 100644 (file)
@@ -378,15 +378,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 173367a4bf7261b04431d790802c8cee051c0a25..4d85a2b2bdf349d0fbdef51fb9fc8cdda4b8446b 100644 (file)
@@ -235,6 +235,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