diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-04-14 17:16:52 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-04-14 17:16:52 +0000 |
commit | 9415eff064fdd63c30eb0f985b5e3342bf688d37 (patch) | |
tree | e7dd66150c818801d7e80bc1a5cbef2e9769acf5 | |
parent | a9f052532e3ea4267714610307036558929ea672 (diff) | |
download | redmine-9415eff064fdd63c30eb0f985b5e3342bf688d37.tar.gz redmine-9415eff064fdd63c30eb0f985b5e3342bf688d37.zip |
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
-rw-r--r-- | app/models/issue.rb | 15 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 32 |
2 files changed, 46 insertions, 1 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 7d2bf5bba..f865f403e 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 @@ -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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index fca74cdbc..bb4eb2848 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'} |