]> source.dussan.org Git - redmine.git/commitdiff
Merged r14180 (#19606).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Apr 2015 07:49:13 +0000 (07:49 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Apr 2015 07:49:13 +0000 (07:49 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14214 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_test.rb

index 233449bdecf711adcb591e7f04f19d1c6d40cb65..b2be17f2abb76838eab0b4701bae713c752b47f1 100644 (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
@@ -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
index 70a22ab77f3e414201a269e717a411f0a9891ad1..5e93769b8730caab523a8300aef8988ddc33d1a4 100644 (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'}