Commit 8fad93fa authored by jplang's avatar jplang

Fixed that issue details page shows default values for custom fields that...

Fixed that issue details page shows default values for custom fields that aren't actually set (#25726).

git-svn-id: https://svn.redmine.org/redmine/trunk@17499 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 51277a21
......@@ -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
......
......@@ -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)
......
......@@ -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 }
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment