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
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)
@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 }
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