]> source.dussan.org Git - redmine.git/commitdiff
Fixed: Custom field is rendered, even if its value is empty (for multiple) (#18654).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Jan 2015 13:03:52 +0000 (13:03 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Jan 2015 13:03:52 +0000 (13:03 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13864 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/custom_fields_helper.rb
app/views/projects/show.html.erb
app/views/versions/_overview.html.erb
test/functional/projects_controller_test.rb

index 5153c1489d75a4c5aaf63d01e8b07b7242a9583e..ca37a2bc03b6c3480f79cb73ff9eb819de9a06a9 100644 (file)
@@ -117,6 +117,17 @@ module CustomFieldsHelper
     Redmine::FieldFormat.as_select(custom_field.class.customized_class.name)
   end
 
+  # Yields the given block for each custom field value of object that should be
+  # displayed, with the custom field and the formatted value as arguments
+  def render_custom_field_values(object, &block)
+    object.visible_custom_field_values.each do |custom_value|
+      formatted = show_value(custom_value)
+      if formatted.present?
+        yield custom_value.custom_field, formatted
+      end
+    end
+  end
+
   # Renders the custom_values in api views
   def render_api_custom_values(custom_values, api)
     api.array :custom_fields do
index b4b563a377251e03ce0c2b3bfd44cb1ceff19b29..addcfdf6214c9dd528b433fa9c0c7ff539d1c283 100644 (file)
     <li><span class="label"><%=l(:label_subproject_plural)%>:</span>
       <%= @subprojects.collect{|p| link_to p, project_path(p)}.join(", ").html_safe %></li>
   <% end %>
-  <% @project.visible_custom_field_values.each do |custom_value| %>
-  <% if !custom_value.value.blank? %>
-     <li><span class="label"><%=h custom_value.custom_field.name %>:</span> <%=h show_value(custom_value) %></li>
-  <% end %>
+  <% render_custom_field_values(@project) do |custom_field, formatted| %>
+    <li><span class="label"><%= custom_field.name %>:</span> <%= formatted %></li>
   <% end %>
   </ul>
 
index 616e1acdcc9751bff8b3a58bb8febd03a5380729..c3d359bb9afe6558608aee6c8a6b21654aef400d 100644 (file)
@@ -7,10 +7,8 @@
 <p><%=h version.description %></p>
 <% if version.custom_field_values.any? %>
 <ul>
-  <% version.custom_field_values.each do |custom_value| %>
-    <% if custom_value.value.present? %>
-       <li><%=h custom_value.custom_field.name %>: <%=h show_value(custom_value) %></li>
-    <% end %>
+  <% render_custom_field_values(version) do |custom_field, formatted| %>
+    <li><span class="label"><%= custom_field.name %>:</span> <%= formatted %></li>
   <% end %>
 </ul>
 <% end %>
index 8e209002d10aa1ce160a8fc9d5b4bda57db5f75b..7ca53d9bdf9dfa822486a55d23c50c22bf48aaad 100644 (file)
@@ -351,6 +351,18 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_select 'li', :text => /Development status/, :count => 0
   end
 
+  def test_show_should_not_display_blank_custom_fields_with_multiple_values
+    f1 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Foo Bar), :multiple => true
+    f2 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Baz Qux), :multiple => true
+    project = Project.generate!(:custom_field_values => {f2.id.to_s => %w(Qux)})
+
+    get :show, :id => project.id
+    assert_response :success
+
+    assert_select 'li', :text => /#{f1.name}/, :count => 0
+    assert_select 'li', :text => /#{f2.name}/
+  end
+
   def test_show_should_not_fail_when_custom_values_are_nil
     project = Project.find_by_identifier('ecookbook')
     project.custom_values.first.update_attribute(:value, nil)