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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Test that events are fired.
Pavel Balashoud0536718f9ea
diff --git a/modules/storages/spec/services/storages/project_storages/create_service_spec.rb b/modules/storages/spec/services/storages/project_storages/create_service_spec.rbindex b619b4e3969..3d2855ab050 100644--- a/modules/storages/spec/services/storages/project_storages/create_service_spec.rb+++ b/modules/storages/spec/services/storages/project_storages/create_service_spec.rb@@ -28,12 +28,12 @@require 'spec_helper'require 'services/base_services/behaves_like_create_service'-require_relative 'shared_synchronization_trigger_examples'+require_relative 'shared_event_gun_examples'RSpec.describe Storages::ProjectStorages::CreateService, type: :model doit_behaves_like 'BaseServices create service' dolet(:factory) { :project_storage }- it_behaves_like 'a nextcloud synchronization trigger'+ it_behaves_like('an event gun', OpenProject::Events::PROJECT_STORAGE_CREATED)endenddiff --git a/modules/storages/spec/services/storages/project_storages/delete_service_spec.rb b/modules/storages/spec/services/storages/project_storages/delete_service_spec.rbindex 590a82e56e7..e4277f873ec 100644--- a/modules/storages/spec/services/storages/project_storages/delete_service_spec.rb+++ b/modules/storages/spec/services/storages/project_storages/delete_service_spec.rb@@ -29,7 +29,7 @@require 'spec_helper'require_module_spec_helperrequire 'services/base_services/behaves_like_delete_service'-require_relative 'shared_synchronization_trigger_examples'+require_relative 'shared_event_gun_examples'RSpec.describe Storages::ProjectStorages::DeleteService, type: :model, webmock: true docontext 'with records written to DB' do@@ -51,8 +51,7 @@ RSpec.describe Storages::ProjectStorages::DeleteService, type: :model, webmock:project_storagedescribed_class.new(model: project_storage, user:).call- expect(Storages::ProjectStorage.where(id: project_storage.id))- .not_to exist+ expect(Storages::ProjectStorage.where(id: project_storage.id)).not_to existendit 'deletes all FileLinks that belong to containers of the related project' do@@ -61,10 +60,8 @@ RSpec.describe Storages::ProjectStorages::DeleteService, type: :model, webmock:described_class.new(model: project_storage, user:).call- expect(Storages::FileLink.where(id: file_link.id))- .not_to exist- expect(Storages::FileLink.where(id: other_file_link.id))- .to exist+ expect(Storages::FileLink.where(id: file_link.id)).not_to exist+ expect(Storages::FileLink.where(id: other_file_link.id)).to existendcontext 'with Nextcloud storage' do@@ -76,9 +73,7 @@ RSpec.describe Storages::ProjectStorages::DeleteService, type: :model, webmock:stub_request(:delete, delete_folder_url).to_return(status: 204, body: nil, headers: {})end- before do- delete_folder_stub- end+ before { delete_folder_stub }it 'tries to remove the project folder at the external nextcloud storage' doexpect(described_class.new(model: project_storage, user:).call).to be_success@@ -98,11 +93,9 @@ RSpec.describe Storages::ProjectStorages::DeleteService, type: :model, webmock:endend- # Includes many specs that are common for every DeleteService that inherits from ::BaseServices::Delete.- # Collected tests on DeleteContracts from last 15 years.it_behaves_like 'BaseServices delete service' dolet(:factory) { :project_storage }- it_behaves_like 'a nextcloud synchronization trigger'+ it_behaves_like('an event gun', OpenProject::Events::PROJECT_STORAGE_DESTROYED)endenddiff --git a/modules/storages/spec/services/storages/project_storages/shared_synchronization_trigger_examples.rb b/modules/storages/spec/services/storages/project_storages/shared_event_gun_examples.rbsimilarity index 60%rename from modules/storages/spec/services/storages/project_storages/shared_synchronization_trigger_examples.rbrename to modules/storages/spec/services/storages/project_storages/shared_event_gun_examples.rbindex 21ec1b43956..1bd47653020 100644--- a/modules/storages/spec/services/storages/project_storages/shared_synchronization_trigger_examples.rb+++ b/modules/storages/spec/services/storages/project_storages/shared_event_gun_examples.rb@@ -26,29 +26,19 @@# See COPYRIGHT and LICENSE files for more details.#++-RSpec.shared_examples 'a nextcloud synchronization trigger' do- context 'when project_folder mode is automatic' do- it 'schedules appropriate background job' do- model_instance.project_folder_mode = 'automatic'- subject- expect(enqueued_jobs.count).to eq(1)- expect(enqueued_jobs[0][:job]).to eq(Storages::ManageNextcloudIntegrationEventsJob)- end- end+RSpec.shared_examples 'an event gun' do |event|+ %i[automatic manual inactive].each do |mode|+ context "when project_folder mode is #{mode}" do+ it 'fires an appropriate event' do+ allow(OpenProject::Notifications).to(receive(:send))+ model_instance.project_folder_mode = mode- context 'when project_folder mode is manual' do- it 'does not schedule a background job' do- model_instance.project_folder_mode = 'manual'- subject- expect(enqueued_jobs.count).to eq(0)- end- end+ subject- context 'when project_folder mode is inactive' do- it 'does not schedule a background job' do- model_instance.project_folder_mode = 'inactive'- subject- expect(enqueued_jobs.count).to eq(0)+ expect(OpenProject::Notifications).to(+ have_received(:send).with(event, project_folder_mode: mode)+ )+ endendendenddiff --git a/modules/storages/spec/services/storages/project_storages/update_service_spec.rb b/modules/storages/spec/services/storages/project_storages/update_service_spec.rbindex 1e8493ce1ba..48efb889b54 100644--- a/modules/storages/spec/services/storages/project_storages/update_service_spec.rb+++ b/modules/storages/spec/services/storages/project_storages/update_service_spec.rb@@ -28,12 +28,12 @@require 'spec_helper'require 'services/base_services/behaves_like_update_service'-require_relative 'shared_synchronization_trigger_examples'+require_relative 'shared_event_gun_examples'RSpec.describe Storages::ProjectStorages::UpdateService, type: :model doit_behaves_like 'BaseServices update service' dolet(:factory) { :project_storage }- it_behaves_like 'a nextcloud synchronization trigger'+ it_behaves_like('an event gun', OpenProject::Events::PROJECT_STORAGE_UPDATED)endenddiff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rbindex df92a54f244..f00b1ebf351 100644--- a/spec/services/oauth_clients/connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_spec.rb@@ -161,7 +161,10 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model do.to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })end- it 'returns a valid ClientToken object' do+ it 'returns a valid ClientToken object and issues an appropriate event' do+ expect(OpenProject::Notifications)+ .to(receive(:send))+ .with(OpenProject::Events::OAUTH_CLIENT_TOKEN_CREATED, integration_type: "Storages::Storage")expect(subject.success).to be_truthyexpect(subject.result).to be_a OAuthClientTokenend@@ -466,7 +469,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model dothread2.joinexpect([result1.access_token,- result2.access_token]).to match_array([response_body1[:access_token], response_body2[:access_token]])+ result2.access_token]).to contain_exactly(response_body1[:access_token], response_body2[:access_token])expect(WebMock).to have_requested(:any, request_url).twiceendenddiff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rbindex 23cd6b5ac05..5bd698f1811 100644--- a/spec/services/projects/update_service_spec.rb+++ b/spec/services/projects/update_service_spec.rb@@ -38,7 +38,7 @@ RSpec.describe Projects::UpdateService, type: :model doit 'sends an update notification' doexpect(OpenProject::Notifications).to(receive(:send))- .with('project_updated', project: model_instance)+ .with(OpenProject::Events::PROJECT_UPDATED, project: model_instance)subjectend@@ -55,10 +55,10 @@ RSpec.describe Projects::UpdateService, type: :model doit 'sends the notification' doexpect(OpenProject::Notifications).to(receive(:send))- .with('project_updated', project: model_instance)+ .with(OpenProject::Events::PROJECT_UPDATED, project: model_instance)expect(OpenProject::Notifications).to(receive(:send))- .with('project_renamed', project: model_instance)+ .with(OpenProject::Events::PROJECT_RENAMED, project: model_instance)subjectend