]> source.dussan.org Git - redmine.git/commitdiff
Let QueryColumn accept a Proc as caption (#18276).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 4 Nov 2014 21:00:59 +0000 (21:00 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 4 Nov 2014 21:00:59 +0000 (21:00 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13558 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index a4d34d1e431b144fd3c93267aee0240c9f4946c9..755c41db3920990aeb6bb4df1595cae0cc9ddb78 100644 (file)
@@ -33,7 +33,14 @@ class QueryColumn
   end
 
   def caption
-    @caption_key.is_a?(Symbol) ? l(@caption_key) : @caption_key
+    case @caption_key
+    when Symbol
+      l(@caption_key)
+    when Proc
+      @caption_key.call
+    else
+      @caption_key
+    end
   end
 
   # Returns true if the column is sortable, otherwise false
index c9c669387c972bdfe9af1dfa6e6007bb3141f9e2..bf3dcd5e89298f920d08b3d355fa1b708b41a838 100644 (file)
@@ -1415,4 +1415,14 @@ class QueryTest < ActiveSupport::TestCase
       end
     end
   end
+
+  def test_query_column_should_accept_a_symbol_as_caption
+    c = QueryColumn.new('foo', :caption => :general_text_Yes)
+    assert_equal 'Yes', c.caption
+  end
+
+  def test_query_column_should_accept_a_proc_as_caption
+    c = QueryColumn.new('foo', :caption => lambda {'Foo'})
+    assert_equal 'Foo', c.caption
+  end
 end