Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Handle a case when health_status is nil.

Pavel Balashou8f174ea7d6c6
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index c414f173d56..0e522f56e9b 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -89,22 +89,20 @@ module Storages
end
def mark_as_unhealthy(reason: nil)
- return true if unhealthy?
-
update(health_status: 'unhealthy', health_changed_at: Time.now.utc, health_reason: reason)
end
def mark_as_healthy
- return true if healthy?
-
update(health_status: 'healthy', health_changed_at: Time.now.utc, health_reason: nil)
end
def healthy?
+ mark_as_healthy if health_status.nil?
health_status == 'healthy'
end
def unhealthy?
+ mark_as_healthy if health_status.nil?
health_status == 'unhealthy'
end
diff --git a/modules/storages/spec/models/storages/nextcloud_storage_spec.rb b/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
index e6f330a734d..fb9cf6a3eb7 100644
--- a/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
+++ b/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
@@ -76,6 +76,40 @@ RSpec.describe Storages::NextcloudStorage do
end
end
+ describe '#healthy?' do
+ it 'marks as healthy if health_status is nil' do
+ expect do
+ storage.healthy?
+ end.to(change(storage, :health_status).from(nil).to('healthy'))
+ expect(storage).to be_healthy
+ end
+
+ it 'does not mark as healthy if health_status has been defined earlier' do
+ storage.mark_as_unhealthy
+ expect do
+ storage.healthy?
+ end.not_to(change(storage, :health_status).from('unhealthy'))
+ expect(storage).not_to be_healthy
+ end
+ end
+
+ describe '#unhealthy?' do
+ it 'marks as healthy if health_status is nil' do
+ expect do
+ storage.unhealthy?
+ end.to(change(storage, :health_status).from(nil).to('healthy'))
+ expect(storage).to be_healthy
+ end
+
+ it 'does not mark as healthy if health_status has been defined earlier' do
+ storage.mark_as_healthy
+ expect do
+ storage.unhealthy?
+ end.not_to(change(storage, :health_status).from('healthy'))
+ expect(storage).not_to be_unhealthy
+ end
+ end
+
describe '#configured?' do
context 'with a complete configuration' do
let(:storage) do