]> source.dussan.org Git - redmine.git/commitdiff
Fixed that issue details page shows default values for custom fields that aren't...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Sep 2018 08:25:25 +0000 (08:25 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Sep 2018 08:25:25 +0000 (08:25 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@17499 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/custom_value.rb
app/models/issue.rb
lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
test/functional/issues_controller_test.rb

index dc511c0d7538781c2ab119615d27d9e8501e70c7..734c76b22e7354a7d45867276969da2b80e8fd20 100644 (file)
@@ -23,7 +23,7 @@ class CustomValue < ActiveRecord::Base
 
   def initialize(attributes=nil, *args)
     super
-    if new_record? && custom_field && !attributes.key?(:value)
+    if new_record? && custom_field && !attributes.key?(:value) && (customized.nil? || customized.set_custom_field_default?(self))
       self.value ||= custom_field.default_value
     end
   end
index 0906771536f6b2aa57401e812eba7db621db552c..b9d8355ecc5ec7684717f3b0b6c9d981f09b2de2 100644 (file)
@@ -259,6 +259,11 @@ class Issue < ActiveRecord::Base
     end
   end
 
+  # Overrides Redmine::Acts::Customizable::InstanceMethods#set_custom_field_default?
+  def set_custom_field_default?(custom_value)
+    new_record? || project_id_changed?|| tracker_id_changed?
+  end
+
   # Copies attributes from another issue, arg can be an id or an Issue
   def copy_from(arg, options={})
     issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
index e7805cbcfcf44b91530b2f36869edd97b5812a40..72cc3033555bd1ff51f5dfa832b660d3a6bfa9bc 100644 (file)
@@ -104,6 +104,12 @@ module Redmine
           @custom_field_values_changed == true
         end
 
+        # Should the default custom field value be set for the given custom_value?
+        # By default, default custom field value is set for new objects only
+        def set_custom_field_default?(custom_value)
+          new_record?
+        end
+
         def custom_value_for(c)
           field_id = (c.is_a?(CustomField) ? c.id : c.to_i)
           custom_values.detect {|v| v.custom_field_id == field_id }
index d01b990f9f4634a1d92a8b630eb40d8a706ce77c..0e2505eef05219f416c302f567b944be3ed572e7 100644 (file)
@@ -2134,6 +2134,20 @@ class IssuesControllerTest < Redmine::ControllerTest
     end
   end
 
+  def test_show_should_not_display_default_value_for_new_custom_field
+    prior = Issue.generate!
+    field = IssueCustomField.generate!(:name => 'WithDefault', :field_format => 'string', :default_value => 'DEFAULT')
+    after = Issue.generate!
+
+    get :show, :params => {:id => prior.id}
+    assert_response :success
+    assert_select ".cf_#{field.id} .value", :text => ''
+
+    get :show, :params => {:id => after.id}
+    assert_response :success
+    assert_select ".cf_#{field.id} .value", :text => 'DEFAULT'
+  end
+
   def test_show_should_display_private_notes_with_permission_only
     journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
     @request.session[:user_id] = 2