mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-29 11:49:37 +00:00
Fixed that issue details page shows default values for custom fields that aren't actually set (#25726).
git-svn-id: http://svn.redmine.org/redmine/trunk@17499 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
55ee0b8f7f
commit
e856c9f879
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user