Browse Source

Maintenance: Ignore top-level form ID key when checking for taskbar changed state flag.

Dusan Vuckovic 4 months ago
parent
commit
77ba1f0571
2 changed files with 20 additions and 1 deletions
  1. 2 1
      app/models/taskbar.rb
  2. 18 0
      spec/models/taskbar_spec.rb

+ 2 - 1
app/models/taskbar.rb

@@ -53,7 +53,7 @@ class Taskbar < ApplicationModel
   def state_changed?
     return false if state.blank?
 
-    state.each_value do |value|
+    state.each do |key, value|
       if value.is_a? Hash
         value.each do |key1, value1|
           next if value1.blank?
@@ -63,6 +63,7 @@ class Taskbar < ApplicationModel
         end
       else
         next if value.blank?
+        next if key == 'form_id'
 
         return true
       end

+ 18 - 0
spec/models/taskbar_spec.rb

@@ -481,6 +481,24 @@ RSpec.describe Taskbar, type: :model do
                  user_id: 1, apps: { desktop: { last_contact: taskbar.last_contact, changed: false } }
                })
     end
+
+    it 'returns task info for an existing taskbar without changes (form_id only)' do
+      taskbar = create(:taskbar, state: { form_id: SecureRandom.uuid })
+
+      expect(taskbar.preferences_task_info)
+        .to eq({
+                 id: taskbar.id, user_id: 1, apps: { desktop: { last_contact: taskbar.last_contact, changed: false } }
+               })
+    end
+
+    it 'returns task info for an existing taskbar without changes (nested form_id only)' do
+      taskbar = create(:taskbar, state: { article: { form_id: SecureRandom.uuid } })
+
+      expect(taskbar.preferences_task_info)
+        .to eq({
+                 id: taskbar.id, user_id: 1, apps: { desktop: { last_contact: taskbar.last_contact, changed: false } }
+               })
+    end
   end
 
   describe '#update_preferences_infos' do