From d76ab1b7c20b43d864332d598b1f14e412917ee6 Mon Sep 17 00:00:00 2001 From: Marcello Rocha Date: Wed, 26 Jun 2024 18:53:13 +0200 Subject: [PATCH] Fix the events_spec --- .../lib/open_project/storages/engine.rb | 12 +++---- spec/lib/open_project/events_spec.rb | 36 ++++++++++++++----- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb index f6b4f6bca5a9..134195f6de52 100644 --- a/modules/storages/lib/open_project/storages/engine.rb +++ b/modules/storages/lib/open_project/storages/engine.rb @@ -57,8 +57,8 @@ def self.permissions OpenProject::Events::MEMBER_UPDATED, OpenProject::Events::MEMBER_DESTROYED ].each do |event| - OpenProject::Notifications.subscribe(event) do |_payload| - Storages::Storage.joins(project_storages: :project) + OpenProject::Notifications.subscribe(event) do |payload| + ::Storages::Storage.joins(project_storages: :project) .where(project_storages: { project_id: payload[:member].project_id }).find_each do |storage| ::Storages::AutomaticallyManagedStorageSyncJob.debounce(storage) end @@ -70,8 +70,8 @@ def self.permissions OpenProject::Events::PROJECT_ARCHIVED, OpenProject::Events::PROJECT_UNARCHIVED].each do |event| OpenProject::Notifications.subscribe(event) do |payload| - Storages::Storage.joins(project_storages: :project) - .where(project_storages: { project_id: payload[:project] }).find_each do |storage| + ::Storages::Storage.joins(project_storages: :project) + .where(project_storages: { project: payload[:project] }).find_each do |storage| ::Storages::AutomaticallyManagedStorageSyncJob.debounce(storage) end end @@ -117,13 +117,13 @@ def self.permissions OpenProject::Notifications.subscribe( ::OpenProject::Events::STORAGE_TURNED_UNHEALTHY ) do |payload| - Storages::HealthService.new(storage: payload[:storage]).unhealthy(reason: payload[:reason]) + ::Storages::HealthService.new(storage: payload[:storage]).unhealthy(reason: payload[:reason]) end OpenProject::Notifications.subscribe( ::OpenProject::Events::STORAGE_TURNED_HEALTHY ) do |payload| - Storages::HealthService.new(storage: payload[:storage]).healthy + ::Storages::HealthService.new(storage: payload[:storage]).healthy end end end diff --git a/spec/lib/open_project/events_spec.rb b/spec/lib/open_project/events_spec.rb index da7d20b7251b..3ee1fcb8ec9e 100644 --- a/spec/lib/open_project/events_spec.rb +++ b/spec/lib/open_project/events_spec.rb @@ -38,6 +38,7 @@ def fire_event(event_constant_name) before do allow(Storages::ManageStorageIntegrationsJob).to receive(:debounce) + allow(Storages::AutomaticallyManagedStorageSyncJob).to receive(:debounce) end %w[ @@ -53,16 +54,16 @@ def fire_event(event_constant_name) it do subject - expect(Storages::ManageStorageIntegrationsJob).not_to have_received(:debounce) + expect(Storages::AutomaticallyManagedStorageSyncJob).not_to have_received(:debounce) end end context "when payload contains automatic project_folder_mode" do - let(:payload) { { project_folder_mode: :automatic } } + let(:payload) { { project_folder_mode: :automatic, storage: create(:nextcloud_storage) } } it do subject - expect(Storages::ManageStorageIntegrationsJob).to have_received(:debounce) + expect(Storages::AutomaticallyManagedStorageSyncJob).to have_received(:debounce).with(payload[:storage]) end it do @@ -78,19 +79,36 @@ def fire_event(event_constant_name) MEMBER_CREATED MEMBER_UPDATED MEMBER_DESTROYED - PROJECT_UPDATED - PROJECT_RENAMED - PROJECT_ARCHIVED - PROJECT_UNARCHIVED ].each do |event| describe(event) do + let(:project_role) { create(:existing_project_role) } + let(:project_storage) { create(:project_storage) } + let(:member) { create(:work_package_member, roles: [project_role], project: project_storage.project) } + + let(:payload) { { member: } } + subject { fire_event(event) } - let(:payload) { {} } + it do + subject + expect(Storages::AutomaticallyManagedStorageSyncJob).to have_received(:debounce).with(project_storage.storage) + end + end + end + + %w[PROJECT_UPDATED + PROJECT_RENAMED + PROJECT_ARCHIVED + PROJECT_UNARCHIVED].each do |event| + describe(event) do + let(:project_storage) { create(:project_storage, :as_automatically_managed) } + let(:payload) { { project: project_storage.project } } + + subject { fire_event(event) } it do subject - expect(Storages::ManageStorageIntegrationsJob).to have_received(:debounce) + expect(Storages::AutomaticallyManagedStorageSyncJob).to have_received(:debounce).with(project_storage.storage) end end end