mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user