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.
This commit is contained in:
Kabiru Mwenja
2026-01-07 18:16:56 +03:00
parent 20c18d4d0a
commit fbf07278da
2 changed files with 17 additions and 0 deletions
@@ -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)
@@ -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