From fbf07278dab3a0b9ff64c262fed802eb1fbc152f Mon Sep 17 00:00:00 2001 From: Kabiru Mwenja Date: Wed, 7 Jan 2026 18:16:56 +0300 Subject: [PATCH] Add safety check for Setting.exists? in migration Ensures the real_time_text_collaboration_enabled setting exists before checking its value in the migration. This guards against potential edge cases where the setting definition might be removed in the future. --- ..._add_documents_to_default_projects_modules.rb | 1 + ...documents_to_default_projects_modules_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/db/migrate/20260106151226_add_documents_to_default_projects_modules.rb b/db/migrate/20260106151226_add_documents_to_default_projects_modules.rb index 81a20792f55..a6eaf0a2629 100644 --- a/db/migrate/20260106151226_add_documents_to_default_projects_modules.rb +++ b/db/migrate/20260106151226_add_documents_to_default_projects_modules.rb @@ -30,6 +30,7 @@ class AddDocumentsToDefaultProjectsModules < ActiveRecord::Migration[8.0] def up + return unless Setting.exists?(:real_time_text_collaboration_enabled) return unless Setting.real_time_text_collaboration_enabled? # Only update if setting exists in DB (avoid updating on new installations - seeder handles that) diff --git a/spec/migrations/add_documents_to_default_projects_modules_spec.rb b/spec/migrations/add_documents_to_default_projects_modules_spec.rb index d2dcbad789e..14e7bf64b8d 100644 --- a/spec/migrations/add_documents_to_default_projects_modules_spec.rb +++ b/spec/migrations/add_documents_to_default_projects_modules_spec.rb @@ -101,4 +101,20 @@ RSpec.describe AddDocumentsToDefaultProjectsModules, type: :model do expect(Setting.default_projects_modules).to match_array(base_modules) end end + + context "when real_time_text_collaboration_enabled setting does not exist" do + before do + Setting.default_projects_modules = base_modules + allow(Setting).to receive(:exists?).and_call_original + allow(Setting).to receive(:exists?).with(:real_time_text_collaboration_enabled).and_return(false) + end + + it "does not modify the default modules" do + ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) } + + Setting.clear_cache + expect(Setting.default_projects_modules).not_to include("documents") + expect(Setting.default_projects_modules).to match_array(base_modules) + end + end end