1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-28 14:31:48 +00:00

When changing tracker, clear the attributes that are disabled for the new tracker (#17527).

git-svn-id: http://svn.redmine.org/redmine/trunk@14180 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2015-04-14 17:16:52 +00:00
parent a9f052532e
commit 9415eff064
2 changed files with 46 additions and 1 deletions

View File

@ -96,6 +96,7 @@ class Issue < ActiveRecord::Base
ids.any? ? where(:fixed_version_id => ids) : where('1=0')
}
before_validation :clear_disabled_fields
before_create :default_assign
before_save :close_duplicates, :update_done_ratio_from_issue_status,
:force_updated_on_change, :update_closed_on, :set_assigned_to_was
@ -689,7 +690,11 @@ class Issue < ActiveRecord::Base
# Returns the names of attributes that are journalized when updating the issue
def journalized_attribute_names
Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on closed_on)
names = Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on closed_on)
if tracker
names -= tracker.disabled_core_fields
end
names
end
# Returns the id of the last journal or nil
@ -1590,4 +1595,12 @@ class Issue < ActiveRecord::Base
@assigned_to_was = nil
@previous_assigned_to_id = nil
end
def clear_disabled_fields
if tracker
tracker.disabled_core_fields.each do |attribute|
send "#{attribute}=", nil
end
end
end
end

View File

@ -502,6 +502,38 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 'MySQL', issue.custom_field_value(1)
end
def test_changing_tracker_should_clear_disabled_core_fields
tracker = Tracker.find(2)
tracker.core_fields = tracker.core_fields - %w(due_date)
tracker.save!
issue = Issue.generate!(:tracker_id => 1, :start_date => Date.today, :due_date => Date.today)
issue.save!
issue.tracker_id = 2
issue.save!
assert_not_nil issue.start_date
assert_nil issue.due_date
end
def test_changing_tracker_should_not_add_cleared_fields_to_journal
tracker = Tracker.find(2)
tracker.core_fields = tracker.core_fields - %w(due_date)
tracker.save!
issue = Issue.generate!(:tracker_id => 1, :due_date => Date.today)
issue.save!
assert_difference 'Journal.count' do
issue.init_journal User.find(1)
issue.tracker_id = 2
issue.save!
assert_nil issue.due_date
end
journal = Journal.order('id DESC').first
assert_equal 1, journal.details.count
end
def test_reload_should_reload_custom_field_values
issue = Issue.generate!
issue.custom_field_values = {'2' => 'Foo'}