]> source.dussan.org Git - redmine.git/commitdiff
Saving time tracking activities without any change may turn a system activity into...
authorGo MAEDA <maeda@farend.jp>
Tue, 21 Dec 2021 06:42:47 +0000 (06:42 +0000)
committerGo MAEDA <maeda@farend.jp>
Tue, 21 Dec 2021 06:42:47 +0000 (06:42 +0000)
Patch by Yuichi HARADA.

git-svn-id: http://svn.redmine.org/redmine/trunk@21319 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/enumeration.rb
test/functional/project_enumerations_controller_test.rb
test/unit/time_entry_activity_test.rb

index 5f0e023ed95622e70657a2ddaf3762369c196bed..534d8239e115b30cd4553592eb1c866d3e346585 100644 (file)
@@ -117,7 +117,7 @@ class Enumeration < ActiveRecord::Base
   # Does the +new+ Hash have the same custom values as the previous Enumeration?
   def self.same_custom_values?(new, previous)
     previous.custom_field_values.each do |custom_value|
-      if custom_value.value != new["custom_field_values"][custom_value.custom_field_id.to_s]
+      if custom_value.to_s != new["custom_field_values"][custom_value.custom_field_id.to_s].to_s
         return false
       end
     end
index 3c4f44f32e929987149709b4274d74f8e0ac0356..b82dc509294c80a17d9725269a84a0bdd7e89075 100644 (file)
@@ -93,6 +93,26 @@ class ProjectEnumerationsControllerTest < Redmine::ControllerTest
     assert_nil project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
   end
 
+  def test_update_should_not_create_project_specific_activities_when_setting_empty_value_in_custom_field_with_default_value_of_nil
+    system_activity = TimeEntryActivity.find(9) # Design
+    custom_field_value = system_activity.custom_field_values.detect{|cfv| cfv.custom_field.id == 7}
+    assert_nil custom_field_value.value
+
+    assert_no_difference 'TimeEntryActivity.count' do
+      @request.session[:user_id] = 2 # manager
+      put(
+        :update,
+        :params => {
+          :project_id => 1,
+          :enumerations => {
+            "9" => {"parent_id" => "9", "custom_field_values" => {"7" => ""}, "active" => "1"}
+          }
+        }
+      )
+      assert_response :redirect
+    end
+  end
+
   def test_update_will_update_project_specific_activities
     @request.session[:user_id] = 2 # manager
 
index 67e92585043568a2dca32ebf4b830bd9d766cbeb..7953a7ceef2100b39debaa62936620fc1902bfb7 100644 (file)
@@ -144,7 +144,7 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
         parent_activity.id.to_s => {
           'parent_id' => parent_activity.id.to_s,
           'active' => '0',
-          'custom_field_values' => {'7' => ''}
+          'custom_field_values' => {'7' => '1'}
         }
       }
     )
@@ -158,7 +158,7 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
         other_parent_activity.id.to_s => {
           'parent_id' => other_parent_activity.id.to_s,
           'active' => '0',
-          'custom_field_values' => {'7' => ''}
+          'custom_field_values' => {'7' => '1'}
         }
       }
     )
@@ -179,7 +179,7 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
         parent_activity.id.to_s => {
           'parent_id' => parent_activity.id.to_s,
           'active' => '0',
-          'custom_field_values' => {'7' => ''}
+          'custom_field_values' => {'7' => '1'}
         }
       }
     )
@@ -196,4 +196,27 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
     assert_equal 'Design2', project_activity.reload.name
     assert_equal 'Design3', parent_activity.reload.name
   end
+
+  def test_project_activity_should_not_be_created_if_no_custom_value_is_changed
+    system_activity = TimeEntryActivity.find(9) # Design
+    assert_equal true, system_activity.active
+
+    custom_field_value = system_activity.custom_field_values.detect{|cfv| cfv.custom_field.id == 7}
+    assert_nil custom_field_value.value
+
+    project = Project.find(1)
+    assert_equal 0, project.time_entry_activities.count
+
+    assert_no_difference 'TimeEntryActivity.count' do
+      project.update_or_create_time_entry_activities(
+        {
+          '9' => {
+            'parent_id' => '9',
+            'active' => '1',
+            'custom_field_values' => {'7' => ''}
+          }
+        }
+      )
+    end
+  end
 end