]> source.dussan.org Git - redmine.git/commitdiff
Fixed that grouping issue by key/value custom field does not work (#22178).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Mar 2016 13:40:22 +0000 (13:40 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Mar 2016 13:40:22 +0000 (13:40 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15224 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/custom_field_enumeration.rb
test/functional/issues_controller_test.rb

index 26a580defbffb73eb511b7f8119d33ada3a320f0..e3e1f32382a7fbbd0e4b455ad46381f443978d84 100644 (file)
@@ -65,6 +65,12 @@ class CustomFieldEnumeration < ActiveRecord::Base
     end
   end
 
+  def self.fields_for_order_statement(table=nil)
+    table ||= table_name
+    columns = ['position']
+    columns.uniq.map {|field| "#{table}.#{field}"}
+  end
+
   private
 
   def set_position
index e325e7f3651ed0da0415f285427ae946112f3c0b..a23e632e15e859b4e0f8282b70a310e8877b4d32 100644 (file)
@@ -281,6 +281,32 @@ class IssuesControllerTest < ActionController::TestCase
     assert_not_nil assigns(:issue_count_by_group)
   end
 
+  def test_index_with_query_grouped_by_key_value_custom_field
+    cf = IssueCustomField.create!(:name => 'Key', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'enumeration')
+    cf.enumerations << valueb = CustomFieldEnumeration.new(:name => 'Value B', :position => 1)
+    cf.enumerations << valuea = CustomFieldEnumeration.new(:name => 'Value A', :position => 2)
+    CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => valueb.id)
+    CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => valueb.id)
+    CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => valuea.id)
+    CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
+
+    get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
+    assert_response :success
+    assert_template 'index'
+    assert_not_nil assigns(:issues)
+    assert_not_nil assigns(:issue_count_by_group)
+
+    assert_select 'tr.group', 3
+    assert_select 'tr.group' do
+      assert_select 'span.name', :text => 'Value B'
+      assert_select 'span.count', :text => '2'
+    end
+    assert_select 'tr.group' do
+      assert_select 'span.name', :text => 'Value A'
+      assert_select 'span.count', :text => '1'
+    end
+  end
+
   def test_index_with_query_grouped_by_user_custom_field
     cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
     CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')