From: Jean-Philippe Lang Date: Sat, 25 Apr 2015 07:49:13 +0000 (+0000) Subject: Merged r14180 (#19606). X-Git-Tag: 3.0.2~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5fced3a7033335f56bba679238261da0054b327a;p=redmine.git Merged r14180 (#19606). git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14214 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/issue.rb b/app/models/issue.rb index 233449bde..b2be17f2a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 @@ -678,7 +679,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 @@ -1579,4 +1584,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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 70a22ab77..5e93769b8 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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'}