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

Use ServiceResult factory methods where possible

Christophe Bliardb50855a955de
diff --git a/app/services/api/parse_resource_params_service.rb b/app/services/api/parse_resource_params_service.rb
index c8954d40a6e..2fb1449c6ba 100644
--- a/app/services/api/parse_resource_params_service.rb
+++ b/app/services/api/parse_resource_params_service.rb
@@ -52,8 +52,7 @@ module API
{}
end
- ServiceResult.new(success: true,
- result: parsed)
+ ServiceResult.success(result: parsed)
end
private
diff --git a/app/services/api/v3/parse_query_params_service.rb b/app/services/api/v3/parse_query_params_service.rb
index c64bb18d4d0..7fb5dc7f305 100644
--- a/app/services/api/v3/parse_query_params_service.rb
+++ b/app/services/api/v3/parse_query_params_service.rb
@@ -40,7 +40,7 @@ module API
result = without_empty(parsed.merge(json_parsed.result), determine_allowed_empty(params))
- ServiceResult.new(success: true, result:)
+ ServiceResult.success(result:)
end
private
@@ -52,9 +52,9 @@ module API
timeline_labels: timeline_labels_from_params(params)
}
- ServiceResult.new success: true, result: parsed
+ ServiceResult.success result: parsed
rescue ::JSON::ParserError => e
- result = ServiceResult.new success: false
+ result = ServiceResult.failure
result.errors.add(:base, e.message)
result
end
diff --git a/app/services/api/v3/work_package_collection_from_query_service.rb b/app/services/api/v3/work_package_collection_from_query_service.rb
index 6d24f0af788..6cd73522848 100644
--- a/app/services/api/v3/work_package_collection_from_query_service.rb
+++ b/app/services/api/v3/work_package_collection_from_query_service.rb
@@ -46,7 +46,7 @@ module API
if update.success?
representer = results_to_representer(params)
- ServiceResult.new(success: true, result: representer)
+ ServiceResult.success(result: representer)
else
update
end
diff --git a/app/services/attachments/prepare_upload_service.rb b/app/services/attachments/prepare_upload_service.rb
index 0e381c3ded2..4d68c18deb7 100644
--- a/app/services/attachments/prepare_upload_service.rb
+++ b/app/services/attachments/prepare_upload_service.rb
@@ -33,9 +33,9 @@ module Attachments
if attachment.save
attachment.reload # necessary so that the fog file uploader path is correct
- ServiceResult.new success: true, result: attachment
+ ServiceResult.success result: attachment
else
- ServiceResult.new success: false, result: attachment
+ ServiceResult.failure result: attachment
end
end
diff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rb
index 97a6593bb71..c5a04ecb801 100644
--- a/app/services/authentication/omniauth_service.rb
+++ b/app/services/authentication/omniauth_service.rb
@@ -51,7 +51,7 @@ module Authentication
inspect_response(Logger::DEBUG)
unless contract.validate
- result = ServiceResult.new(success: false, errors: contract.errors)
+ result = ServiceResult.failure(errors: contract.errors)
Rails.logger.error do
"[OmniAuth strategy #{strategy.name}] Failed to process omniauth response for #{auth_uid}: #{result.message}"
end
@@ -194,7 +194,7 @@ module Authentication
.new(user)
.call
else
- ServiceResult.new(success: true, result: user)
+ ServiceResult.success(result: user)
end
end
diff --git a/app/services/authorization/user_allowed_service.rb b/app/services/authorization/user_allowed_service.rb
index 27bc85b5474..64283dd704a 100644
--- a/app/services/authorization/user_allowed_service.rb
+++ b/app/services/authorization/user_allowed_service.rb
@@ -45,11 +45,9 @@ class Authorization::UserAllowedService
# or falls back to Non Member / Anonymous permissions depending if the user is logged
def call(action, context, global: false)
if supported_context?(context, global:)
- ServiceResult.new(success: true,
- result: allowed_to?(action, context, global:))
+ ServiceResult.success(result: allowed_to?(action, context, global:))
else
- ServiceResult.new(success: false,
- result: false)
+ ServiceResult.failure(result: false)
end
end
diff --git a/app/services/base_services/base_contracted.rb b/app/services/base_services/base_contracted.rb
index 390df28969f..101ee190865 100644
--- a/app/services/base_services/base_contracted.rb
+++ b/app/services/base_services/base_contracted.rb
@@ -68,11 +68,11 @@ module BaseServices
end
def validate_params(_params)
- ServiceResult.new(success: true, result: model)
+ ServiceResult.success(result: model)
end
def before_perform(*)
- ServiceResult.new(success: true, result: model)
+ ServiceResult.success(result: model)
end
def after_validate(_params, contract_call)
diff --git a/app/services/base_services/copy.rb b/app/services/base_services/copy.rb
index 0cc3cf5b5e1..a7bad660060 100644
--- a/app/services/base_services/copy.rb
+++ b/app/services/base_services/copy.rb
@@ -77,7 +77,7 @@ module BaseServices
# Try to save the result or return its errors
copy_instance = call.result
unless copy_instance.save
- return ServiceResult.new(success: false, result: copy_instance, errors: copy_instance.errors)
+ return ServiceResult.failure(result: copy_instance, errors: copy_instance.errors)
end
self.class.copy_dependencies.each do |service_cls|
diff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rb
index e1c140b3230..aaeefaa731f 100644
--- a/app/services/base_type_service.rb
+++ b/app/services/base_type_service.rb
@@ -73,7 +73,7 @@ class BaseTypeService
errors:,
result: type)
rescue StandardError => e
- ServiceResult.new(success: false).tap do |result|
+ ServiceResult.failure.tap do |result|
result.errors.add(:base, e.message)
end
end
diff --git a/app/services/copy/dependency.rb b/app/services/copy/dependency.rb
index 0cbfef2859f..f4cc8a350bc 100644
--- a/app/services/copy/dependency.rb
+++ b/app/services/copy/dependency.rb
@@ -53,7 +53,7 @@ module Copy
@user = user
# Create a result with an empty error set
# that we can merge! so that not the target.errors object is reused.
- @result = ServiceResult.new(result: target, success: true, errors: ActiveModel::Errors.new(target))
+ @result = ServiceResult.success(result: target, errors: ActiveModel::Errors.new(target))
end
protected
diff --git a/app/services/custom_fields/create_service.rb b/app/services/custom_fields/create_service.rb
index 5c341395f23..fe0659ac10d 100644
--- a/app/services/custom_fields/create_service.rb
+++ b/app/services/custom_fields/create_service.rb
@@ -41,7 +41,7 @@ module CustomFields
def perform(params)
super
rescue StandardError => e
- ServiceResult.new(success: false, message: e.message)
+ ServiceResult.failure(message: e.message)
end
def instance(params)
diff --git a/app/services/design/update_design_service.rb b/app/services/design/update_design_service.rb
index 867dba44ce7..95c1fdc4724 100644
--- a/app/services/design/update_design_service.rb
+++ b/app/services/design/update_design_service.rb
@@ -42,10 +42,10 @@ module Design
custom_style.save!
- ServiceResult.new success: true, result: custom_style
+ ServiceResult.success result: custom_style
end
rescue StandardError => e
- ServiceResult.new success: false, message: e.message
+ ServiceResult.failure message: e.message
end
private
diff --git a/app/services/grids/copy/widgets_dependent_service.rb b/app/services/grids/copy/widgets_dependent_service.rb
index cd9d0fb4818..15c75a406c8 100644
--- a/app/services/grids/copy/widgets_dependent_service.rb
+++ b/app/services/grids/copy/widgets_dependent_service.rb
@@ -78,7 +78,7 @@ module Grids::Copy
if mapper
mapper.call(value, params).map { |id| [option, id] }
else
- ServiceResult.new success: true, result: [option, value]
+ ServiceResult.success result: [option, value]
end
end
@@ -101,7 +101,7 @@ module Grids::Copy
existing_query_id = state.query_id_lookup[query_id.to_i] if state.query_id_lookup
if existing_query_id
- ServiceResult.new(result: existing_query_id, success: true)
+ ServiceResult.success(result: existing_query_id)
else
duplicate_query(query_id, params).map(&:id)
end
@@ -112,7 +112,7 @@ module Grids::Copy
.new(state, filters)
.map_filters!
- ServiceResult.new success: true, result: filters
+ ServiceResult.success result: filters
end
def duplicate_query(query_id, params)
diff --git a/app/services/groups/concerns/membership_manipulation.rb b/app/services/groups/concerns/membership_manipulation.rb
index b9bcdc89398..1c355e3e72e 100644
--- a/app/services/groups/concerns/membership_manipulation.rb
+++ b/app/services/groups/concerns/membership_manipulation.rb
@@ -44,11 +44,10 @@ module Groups::Concerns
def with_error_handled
yield
- ServiceResult.new success: true, result: model
+ ServiceResult.success result: model
rescue StandardError => e
Rails.logger.error { "Failed to modify members and associated roles of group #{model.id}: #{e} #{e.message}" }
- ServiceResult.new(success: false,
- message: I18n.t(:notice_internal_server_error, app_title: Setting.app_title))
+ ServiceResult.failure(message: I18n.t(:notice_internal_server_error, app_title: Setting.app_title))
end
def exec_query!(params, send_notifications, message)
diff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rb
index fd792c3bdad..21d39066902 100644
--- a/app/services/journals/create_service.rb
+++ b/app/services/journals/create_service.rb
@@ -51,13 +51,13 @@ module Journals
Journal.transaction do
journal = create_journal(notes)
- return ServiceResult.new success: true unless journal
+ return ServiceResult.success unless journal
destroy_predecessor(journal)
reload_journals
touch_journable(journal)
- ServiceResult.new success: true, result: journal
+ ServiceResult.success result: journal
end
end
diff --git a/app/services/members/cleanup_service.rb b/app/services/members/cleanup_service.rb
index 33f20eb44bc..4a3e5f0e533 100644
--- a/app/services/members/cleanup_service.rb
+++ b/app/services/members/cleanup_service.rb
@@ -41,7 +41,7 @@ module Members
prune_watchers
unassign_categories
- ServiceResult.new(success: true)
+ ServiceResult.success
end
attr_accessor :users,
diff --git a/app/services/oauth_clients/connection_manager.rb b/app/services/oauth_clients/connection_manager.rb
index d0bbd83afd2..7a9f3fbe0d5 100644
--- a/app/services/oauth_clients/connection_manager.rb
+++ b/app/services/oauth_clients/connection_manager.rb
@@ -46,11 +46,11 @@ module OAuthClients
def get_access_token(scope: [], state: nil)
# Check for an already existing token from last call
token = get_existing_token
- return ServiceResult.new(success: true, result: token) if token.present?
+ return ServiceResult.success(result: token) if token.present?
# Return a String with a redirect URL to Nextcloud instead of a token
@redirect_url = redirect_to_oauth_authorize(scope:, state:)
- ServiceResult.new(success: false, result: @redirect_url)
+ ServiceResult.failure(result: @redirect_url)
end
# The bearer/access token has expired or is due for renew for other reasons.
@@ -89,8 +89,7 @@ module OAuthClients
return service_result unless service_result.success?
# Create a new OAuthClientToken from Rack::OAuth::AccessToken::Bearer and return
- ServiceResult.new(
- success: true,
+ ServiceResult.success(
result: create_new_oauth_client_token(service_result.result)
)
end
@@ -110,8 +109,7 @@ module OAuthClients
rack_access_token = rack_oauth_client(options)
.access_token!(:body) # Rack::OAuth2::AccessToken
- ServiceResult.new(success: true,
- result: rack_access_token)
+ ServiceResult.success(result: rack_access_token)
rescue Rack::OAuth2::Client::Error => e # Handle Rack::OAuth2 specific errors
service_result_with_error(i18n_rack_oauth2_error_message(e))
rescue Timeout::Error, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
@@ -189,11 +187,11 @@ module OAuthClients
)
if success
- ServiceResult.new(success: true, result: oauth_client_token)
+ ServiceResult.success(result: oauth_client_token)
else
- result = ServiceResult.new(success: false)
+ result = ServiceResult.failure
result.errors.add(:base, I18n.t('oauth_client.errors.refresh_token_updated_failed'))
- result.add_dependent!(ServiceResult.new(success: false, errors: oauth_client_token.errors))
+ result.add_dependent!(ServiceResult.failure(errors: oauth_client_token.errors))
result
end
end
@@ -201,7 +199,7 @@ module OAuthClients
# Shortcut method to convert an error message into an unsuccessful
# ServiceResult with that error message
def service_result_with_error(message)
- ServiceResult.new(success: false).tap do |result|
+ ServiceResult.failure.tap do |result|
result.errors.add(:base, message)
end
end
diff --git a/app/services/oauth_clients/redirect_uri_from_state_service.rb b/app/services/oauth_clients/redirect_uri_from_state_service.rb
index cb70a810aba..5a20266c666 100644
--- a/app/services/oauth_clients/redirect_uri_from_state_service.rb
+++ b/app/services/oauth_clients/redirect_uri_from_state_service.rb
@@ -40,9 +40,9 @@ module OAuthClients
redirect_uri = oauth_state_cookie
if redirect_uri.present? && ::API::V3::Utilities::PathHelper::ApiV3Path::same_origin?(redirect_uri)
- ServiceResult.new(success: true, result: redirect_uri)
+ ServiceResult.success(result: redirect_uri)
else
- ServiceResult.new(success: false)
+ ServiceResult.failure
end
end
diff --git a/app/services/parse_schema_filter_params_service.rb b/app/services/parse_schema_filter_params_service.rb
index 12216492728..01f42f7f7cc 100644
--- a/app/services/parse_schema_filter_params_service.rb
+++ b/app/services/parse_schema_filter_params_service.rb
@@ -75,11 +75,11 @@ class ParseSchemaFilterParamsService
def error(message)
errors = ActiveModel::Errors.new(self)
errors.add(:base, message)
- ServiceResult.new(errors:)
+ ServiceResult.failure(errors:)
end
def success(result)
- ServiceResult.new(success: true, result:)
+ ServiceResult.success(result:)
end
def valid_project_type_pairs(filter)
diff --git a/app/services/principals/replace_references_service.rb b/app/services/principals/replace_references_service.rb
index d5df05544a9..9eaa6370ca9 100644
--- a/app/services/principals/replace_references_service.rb
+++ b/app/services/principals/replace_references_service.rb
@@ -36,7 +36,7 @@ module Principals
rewrite_default_journals(from, to)
rewrite_customizable_journals(from, to)
- ServiceResult.new success: true
+ ServiceResult.success
end
private
diff --git a/app/services/projects/enqueue_copy_service.rb b/app/services/projects/enqueue_copy_service.rb
index 581fc4e75b7..3231d031a4d 100644
--- a/app/services/projects/enqueue_copy_service.rb
+++ b/app/services/projects/enqueue_copy_service.rb
@@ -41,7 +41,7 @@ module Projects
call = test_copy(params)
if call.success?
- ServiceResult.new success: true, result: schedule_copy_job(params)
+ ServiceResult.success result: schedule_copy_job(params)
else
call
end
diff --git a/app/services/sessions/initialize_session_service.rb b/app/services/sessions/initialize_session_service.rb
index 17f87d31a1c..947f894aa03 100644
--- a/app/services/sessions/initialize_session_service.rb
+++ b/app/services/sessions/initialize_session_service.rb
@@ -43,7 +43,7 @@ module Sessions
::Sessions::UserSession.for_user(user).delete_all
end
- ServiceResult.new(success: true, result: session)
+ ServiceResult.success(result: session)
end
private
diff --git a/app/services/update_query_from_params_service.rb b/app/services/update_query_from_params_service.rb
index 794f4d3abc3..e91f4e111f5 100644
--- a/app/services/update_query_from_params_service.rb
+++ b/app/services/update_query_from_params_service.rb
@@ -60,10 +60,9 @@ class UpdateQueryFromParamsService
end
if query.valid?
- ServiceResult.new(success: true,
- result: query)
+ ServiceResult.success(result: query)
else
- ServiceResult.new(errors: query.errors)
+ ServiceResult.failure(errors: query.errors)
end
end
diff --git a/app/services/users/create_service.rb b/app/services/users/create_service.rb
index c2ee32b60a7..80db39155c9 100644
--- a/app/services/users/create_service.rb
+++ b/app/services/users/create_service.rb
@@ -46,7 +46,7 @@ module Users
end
def fail_with_missing_email(new_user)
- ServiceResult.new(success: false, result: new_user).tap do |result|
+ ServiceResult.failure(result: new_user).tap do |result|
result.errors.add :mail, :blank
end
end
diff --git a/app/services/users/login_service.rb b/app/services/users/login_service.rb
index 9dea45757f7..803f015a9f6 100644
--- a/app/services/users/login_service.rb
+++ b/app/services/users/login_service.rb
@@ -53,7 +53,7 @@ module Users
user.log_successful_login
- ServiceResult.new(result: user)
+ ServiceResult.failure(result: user)
end
def retain_sso_session_values!(user)
diff --git a/app/services/users/logout_service.rb b/app/services/users/logout_service.rb
index 86e7e31c914..1aa3da6f5a1 100644
--- a/app/services/users/logout_service.rb
+++ b/app/services/users/logout_service.rb
@@ -43,7 +43,7 @@ module Users
end
User.current = User.anonymous
- ServiceResult.new(result: User.anonymous)
+ ServiceResult.failure(result: User.anonymous)
end
private
diff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rb
index 692848760bd..e3a714c7a6d 100644
--- a/app/services/users/register_user_service.rb
+++ b/app/services/users/register_user_service.rb
@@ -50,7 +50,7 @@ module Users
end
rescue StandardError => e
Rails.logger.error { "User #{user.login} failed to activate #{e}." }
- ServiceResult.new(success: false, result: user, message: I18n.t(:notice_activation_failed))
+ ServiceResult.failure(result: user, message: I18n.t(:notice_activation_failed))
end
private
@@ -60,7 +60,7 @@ module Users
# for non-invited users
def ensure_registration_allowed!
if Setting::SelfRegistration.disabled?
- ServiceResult.new(success: false, result: user, message: I18n.t('account.error_self_registration_disabled'))
+ ServiceResult.failure(result: user, message: I18n.t('account.error_self_registration_disabled'))
end
end
@@ -69,7 +69,7 @@ module Users
def ensure_user_limit_not_reached!
if OpenProject::Enterprise.user_limit_reached?
OpenProject::Enterprise.send_activation_limit_notification_about user
- ServiceResult.new(success: false, result: user, message: I18n.t(:error_enterprise_activation_user_limit))
+ ServiceResult.failure(result: user, message: I18n.t(:error_enterprise_activation_user_limit))
end
end
@@ -140,7 +140,7 @@ module Users
def fail_activation
Rails.logger.error { "User #{user.login} could not be activated, all options were exhausted." }
- ServiceResult.new(success: false, message: I18n.t(:notice_activation_failed))
+ ServiceResult.failure(message: I18n.t(:notice_activation_failed))
end
##
@@ -149,10 +149,10 @@ module Users
def with_saved_user_result(success_message: I18n.t(:notice_account_activated))
if user.save
yield if block_given?
- return ServiceResult.new(success: true, result: user, message: success_message)
+ return ServiceResult.success(result: user, message: success_message)
end
- ServiceResult.new(success: false).tap do |call|
+ ServiceResult.failure.tap do |call|
# Avoid using the errors from the user
call.result = user
call.errors.add(:base, I18n.t(:notice_activation_failed), error: :failed_to_activate)
diff --git a/app/services/work_packages/bulk/bulked_service.rb b/app/services/work_packages/bulk/bulked_service.rb
index c57252fcfa7..36d5e9213ed 100644
--- a/app/services/work_packages/bulk/bulked_service.rb
+++ b/app/services/work_packages/bulk/bulked_service.rb
@@ -51,7 +51,7 @@ module WorkPackages
private
def bulk(params)
- result = ServiceResult.new success: true, result: true
+ result = ServiceResult.success result: true
work_packages.each do |work_package|
# As updating one work package might have already saved another one,
diff --git a/app/services/work_packages/exports/schedule_service.rb b/app/services/work_packages/exports/schedule_service.rb
index f070ed490ea..9e1099b55f3 100644
--- a/app/services/work_packages/exports/schedule_service.rb
+++ b/app/services/work_packages/exports/schedule_service.rb
@@ -37,7 +37,7 @@ class WorkPackages::Exports::ScheduleService
export_storage = WorkPackages::Export.create
job = schedule_export(export_storage, mime_type, params, query)
- ServiceResult.new success: true, result: job.job_id
+ ServiceResult.success result: job.job_id
end
private
diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rb
index 1c8d5e6f9d1..dc6635b5834 100644
--- a/app/services/work_packages/set_schedule_service.rb
+++ b/app/services/work_packages/set_schedule_service.rb
@@ -45,12 +45,10 @@ class WorkPackages::SetScheduleService
altered += schedule_following
end
- result = ServiceResult.new(success: true,
- result: work_packages.first)
+ result = ServiceResult.success(result: work_packages.first)
altered.each do |wp|
- result.add_dependent!(ServiceResult.new(success: true,
- result: wp))
+ result.add_dependent!(ServiceResult.success(result: wp))
end
result
diff --git a/modules/avatars/app/services/avatars/update_service.rb b/modules/avatars/app/services/avatars/update_service.rb
index cf1e8c5ca19..c0b169f8378 100644
--- a/modules/avatars/app/services/avatars/update_service.rb
+++ b/modules/avatars/app/services/avatars/update_service.rb
@@ -10,7 +10,7 @@ module ::Avatars
def replace(avatar)
if avatar.nil?
- return ServiceResult.new(success: false).tap do |_result|
+ return ServiceResult.failure.tap do |_result|
return error_result(I18n.t(:empty_file_error))
end
end
@@ -33,7 +33,7 @@ module ::Avatars
end
@user.local_avatar_attachment = avatar
- ServiceResult.new(success: true, result: I18n.t(:message_avatar_uploaded))
+ ServiceResult.success(result: I18n.t(:message_avatar_uploaded))
rescue StandardError => e
Rails.logger.error "Failed to update avatar of user##{user.id}: #{e}"
error_result(I18n.t(:error_image_upload))
@@ -43,7 +43,7 @@ module ::Avatars
current_attachment = @user.local_avatar_attachment
if current_attachment && current_attachment.destroy
@user.reload
- ServiceResult.new(success: true, result: I18n.t(:avatar_deleted))
+ ServiceResult.success(result: I18n.t(:avatar_deleted))
else
error_result(I18n.t(:unable_to_delete_avatar))
end
@@ -55,7 +55,7 @@ module ::Avatars
private
def error_result(message)
- ServiceResult.new(success: false).tap do |result|
+ ServiceResult.failure.tap do |result|
result.errors.add(:base, message)
end
end
diff --git a/modules/avatars/spec/controllers/avatars/my_controller_spec.rb b/modules/avatars/spec/controllers/avatars/my_controller_spec.rb
index 2598d25521c..41b0d9a3392 100644
--- a/modules/avatars/spec/controllers/avatars/my_controller_spec.rb
+++ b/modules/avatars/spec/controllers/avatars/my_controller_spec.rb
@@ -50,7 +50,7 @@ describe ::Avatars::MyAvatarController, type: :controller do
it 'calls the service for put' do
expect_any_instance_of(::Avatars::UpdateService)
.to receive(:replace)
- .and_return(ServiceResult.new(success: true))
+ .and_return(ServiceResult.success)
put :update
expect(response).to be_successful
@@ -60,7 +60,7 @@ describe ::Avatars::MyAvatarController, type: :controller do
it 'calls the service for put' do
expect_any_instance_of(::Avatars::UpdateService)
.to receive(:replace)
- .and_return(ServiceResult.new(success: false))
+ .and_return(ServiceResult.failure)
put :update
expect(response).not_to be_successful
@@ -78,7 +78,7 @@ describe ::Avatars::MyAvatarController, type: :controller do
it 'calls the service for delete' do
expect_any_instance_of(::Avatars::UpdateService)
.to receive(:destroy)
- .and_return(ServiceResult.new(success: true, result: 'message'))
+ .and_return(ServiceResult.success(result: 'message'))
delete :destroy
expect(flash[:notice]).to include 'message'
@@ -87,7 +87,7 @@ describe ::Avatars::MyAvatarController, type: :controller do
end
it 'calls the service for delete' do
- result = ServiceResult.new(success: false)
+ result = ServiceResult.failure
result.errors.add :base, 'error'
expect_any_instance_of(::Avatars::UpdateService)
diff --git a/modules/avatars/spec/controllers/avatars/users_controller_spec.rb b/modules/avatars/spec/controllers/avatars/users_controller_spec.rb
index 4d17037cdee..952edea9951 100644
--- a/modules/avatars/spec/controllers/avatars/users_controller_spec.rb
+++ b/modules/avatars/spec/controllers/avatars/users_controller_spec.rb
@@ -68,7 +68,7 @@ describe ::Avatars::UsersController, type: :controller do
it 'calls the service for put' do
expect_any_instance_of(::Avatars::UpdateService)
.to receive(:replace)
- .and_return(ServiceResult.new(success: true))
+ .and_return(ServiceResult.success)
put :update, params: { id: target_user.id }
expect(response).to be_successful
@@ -78,7 +78,7 @@ describe ::Avatars::UsersController, type: :controller do
it 'calls the service for put' do
expect_any_instance_of(::Avatars::UpdateService)
.to receive(:replace)
- .and_return(ServiceResult.new(success: false))
+ .and_return(ServiceResult.failure)
put :update, params: { id: target_user.id }
expect(response).not_to be_successful
@@ -107,7 +107,7 @@ describe ::Avatars::UsersController, type: :controller do
it 'calls the service for delete' do
expect_any_instance_of(::Avatars::UpdateService)
.to receive(:destroy)
- .and_return(ServiceResult.new(success: true, result: 'message'))
+ .and_return(ServiceResult.success(result: 'message'))
delete :destroy, params: { id: target_user.id }
expect(flash[:notice]).to include 'message'
@@ -116,7 +116,7 @@ describe ::Avatars::UsersController, type: :controller do
end
it 'calls the service for delete' do
- result = ServiceResult.new(success: false)
+ result = ServiceResult.failure
result.errors.add :base, 'error'
expect_any_instance_of(::Avatars::UpdateService)
diff --git a/modules/bim/app/services/bim/bcf/issues/create_service.rb b/modules/bim/app/services/bim/bcf/issues/create_service.rb
index 2f5a0a17090..c3a8f2111f3 100644
--- a/modules/bim/app/services/bim/bcf/issues/create_service.rb
+++ b/modules/bim/app/services/bim/bcf/issues/create_service.rb
@@ -87,7 +87,7 @@ module Bim::Bcf
end
def work_package_not_found_result
- ServiceResult.new(errors: Bim::Bcf::Issue.new.errors).tap do |r|
+ ServiceResult.failure(errors: Bim::Bcf::Issue.new.errors).tap do |r|
r.errors.add :work_package, :does_not_exist
end
end
diff --git a/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb b/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb
index 736a547ccee..bb7fa342eec 100644
--- a/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb
+++ b/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb
@@ -34,8 +34,7 @@ module Bim::Bcf
end
def call(attributes)
- ServiceResult.new success: true,
- result: work_package_attributes(attributes)
+ ServiceResult.success result: work_package_attributes(attributes)
end
private
diff --git a/modules/bim/app/services/bim/ifc_models/view_converter_service.rb b/modules/bim/app/services/bim/ifc_models/view_converter_service.rb
index da330d0b877..7d173294e5f 100644
--- a/modules/bim/app/services/bim/ifc_models/view_converter_service.rb
+++ b/modules/bim/app/services/bim/ifc_models/view_converter_service.rb
@@ -74,7 +74,7 @@ module Bim
ifc_model.conversion_error_message = e.message
ifc_model.save
- ServiceResult.new(success: false).tap { |r| r.errors.add(:base, e.message) }
+ ServiceResult.failure.tap { |r| r.errors.add(:base, e.message) }
ensure
self.working_directory = nil
end
diff --git a/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb b/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
index d56c3a1e95c..af682ac7646 100644
--- a/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
+++ b/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
@@ -318,7 +318,7 @@ module OpenProject::Bim::BcfXml
message: I18n.t('bcf.bcf_xml.import.work_package_has_newer_changes',
bcf_uuid: issue.uuid)
- ServiceResult.new(success: false, errors:)
+ ServiceResult.failure(errors:)
end
end
end
diff --git a/modules/bim/spec/controllers/work_packages_controller_spec.rb b/modules/bim/spec/controllers/work_packages_controller_spec.rb
index 0293365d226..a32559e2de3 100644
--- a/modules/bim/spec/controllers/work_packages_controller_spec.rb
+++ b/modules/bim/spec/controllers/work_packages_controller_spec.rb
@@ -62,7 +62,7 @@ describe WorkPackagesController, type: :controller do
allow(service_instance)
.to receive(:call)
.with(query:, mime_type: mime_type.to_sym, params: anything)
- .and_return(ServiceResult.new(result: 'uuid of the export job'))
+ .and_return(ServiceResult.failure(result: 'uuid of the export job'))
end
it 'redirects to the export' do
diff --git a/modules/bim/spec/services/bcf/issues/create_service_spec.rb b/modules/bim/spec/services/bcf/issues/create_service_spec.rb
index 08523199a74..f7b477406ad 100644
--- a/modules/bim/spec/services/bcf/issues/create_service_spec.rb
+++ b/modules/bim/spec/services/bcf/issues/create_service_spec.rb
@@ -34,7 +34,7 @@ describe Bim::Bcf::Issues::CreateService, type: :model do
let(:model_class) { ::Bim::Bcf::Issue }
let(:factory) { :bcf_issue }
let(:work_package) { build_stubbed :work_package }
- let(:wp_call) { ServiceResult.new(success: true, result: work_package) }
+ let(:wp_call) { ServiceResult.success(result: work_package) }
before do
allow(instance)
@@ -43,7 +43,7 @@ describe Bim::Bcf::Issues::CreateService, type: :model do
end
context 'when WP service call fails' do
- let(:wp_call) { ServiceResult.new(success: false, result: work_package) }
+ let(:wp_call) { ServiceResult.failure(result: work_package) }
it 'returns with that call immediately' do
expect(subject).to eq wp_call
diff --git a/modules/bim/spec/workers/ifc_conversion_job_spec.rb b/modules/bim/spec/workers/ifc_conversion_job_spec.rb
index 6b0b42858a5..bc9d5cc637c 100644
--- a/modules/bim/spec/workers/ifc_conversion_job_spec.rb
+++ b/modules/bim/spec/workers/ifc_conversion_job_spec.rb
@@ -8,7 +8,7 @@ describe Bim::IfcModels::IfcConversionJob, type: :job do
it 'calls the conversion service' do
expect(::Bim::IfcModels::ViewConverterService)
.to receive_message_chain(:new, :call)
- .and_return ServiceResult.new success: true
+ .and_return ServiceResult.success
expect { subject }.not_to raise_error
end
diff --git a/modules/bim/spec/workers/work_packages/exports/export_job_spec.rb b/modules/bim/spec/workers/work_packages/exports/export_job_spec.rb
index 4fd99a7cbda..b2f30135a81 100644
--- a/modules/bim/spec/workers/work_packages/exports/export_job_spec.rb
+++ b/modules/bim/spec/workers/work_packages/exports/export_job_spec.rb
@@ -76,7 +76,7 @@ describe WorkPackages::ExportJob do
expect(service)
.to(receive(:call))
- .and_return(ServiceResult.new(result: attachment, success: true))
+ .and_return(ServiceResult.success(result: attachment))
allow(exporter).to receive(:new).and_return(exporter_instance)
allow(exporter_instance).to receive(:export!).and_return(result)
diff --git a/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rb b/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rb
index b5650a2d9dd..62380f1c2e2 100644
--- a/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rb
+++ b/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rb
@@ -8,11 +8,11 @@ module LdapGroups
def call
count = synchronize!
- ServiceResult.new(success: true, result: count)
+ ServiceResult.success(result: count)
rescue StandardError => e
error = "[LDAP groups] Failed to extract LDAP groups from filter #{filter.name}: #{e.class}: #{e.message}"
Rails.logger.error(error)
- ServiceResult.new(success: false, message: error)
+ ServiceResult.failure(message: error)
end
##
diff --git a/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb b/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb
index 4be86c58e85..b7f22bdb294 100644
--- a/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb
+++ b/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb
@@ -11,11 +11,11 @@ module LdapGroups
def call
synchronize!
- ServiceResult.new(success: true)
+ ServiceResult.success
rescue StandardError => e
error = "[LDAP groups] Failed to perform LDAP group synchronization: #{e.class}: #{e.message}"
Rails.logger.error(error)
- ServiceResult.new(message: error, success: false)
+ ServiceResult.failure(message: error)
end
def synchronize!
diff --git a/modules/storages/lib/api/v3/file_links/create_endpoint.rb b/modules/storages/lib/api/v3/file_links/create_endpoint.rb
index 78f03a711e2..3239dea17e0 100644
--- a/modules/storages/lib/api/v3/file_links/create_endpoint.rb
+++ b/modules/storages/lib/api/v3/file_links/create_endpoint.rb
@@ -46,7 +46,7 @@ module API::V3::FileLinks
# call is done by calling the `super` method. Results are aggregated in
# global_result using the `add_dependent!` method.
def process(request, params_elements)
- global_result = ServiceResult.new(success: true)
+ global_result = ServiceResult.success
Storages::FileLink.transaction do
params_elements.each do |params|
diff --git a/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb b/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb
index 516a02415bb..09c6bbdf3d4 100644
--- a/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb
+++ b/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb
@@ -45,11 +45,11 @@ module TwoFactorAuthentication
# Produce the token with the given strategy (e.g., sending an sms)
strategy.transmit
- ServiceResult.new(success: true, result: strategy.transmit_success_message)
+ ServiceResult.success(result: strategy.transmit_success_message)
rescue StandardError => e
Rails.logger.error "[2FA plugin] Error during token request to user##{user.id}: #{e}"
- result = ServiceResult.new(success: false)
+ result = ServiceResult.failure
result.errors.add(:base, e.message)
result
@@ -69,7 +69,7 @@ module TwoFactorAuthentication
rescue StandardError => e
Rails.logger.error "[2FA plugin] Error during token validation for user##{user.id}: #{e}"
- result = ServiceResult.new(success: false)
+ result = ServiceResult.failure
result.errors.add(:base, e.message)
result
diff --git a/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb b/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb
index 568ec43936d..1a90bfbb844 100644
--- a/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb
+++ b/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb
@@ -19,7 +19,7 @@ module TwoFactorAuthentication
rescue StandardError => e
Rails.logger.error "[2FA plugin] Error during backup code validation for user##{user.id}: #{e}"
- result = ServiceResult.new(success: false)
+ result = ServiceResult.failure
result.errors.add(:base, e.message)
result
@@ -31,7 +31,7 @@ module TwoFactorAuthentication
token.destroy!
Rails.logger.info { "[2FA plugin] User ##{user.id} has used backup code." }
- ServiceResult.new(success: true, result: token)
+ ServiceResult.success(result: token)
end
end
end
diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb
index aa04e38b34d..189aa535a3b 100644
--- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb
+++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb
@@ -150,7 +150,7 @@ describe ::TwoFactorAuthentication::ForcedRegistration::TwoFactorDevicesControll
it 'redirects to failure path if token request failed' do
allow_any_instance_of(::TwoFactorAuthentication::TokenService)
.to receive(:request)
- .and_return(ServiceResult.new(success: false))
+ .and_return(ServiceResult.failure)
get :confirm, params: { device_id: device.id }
expect(response).to redirect_to stage_failure_path(stage: :two_factor_authentication)
@@ -189,7 +189,7 @@ describe ::TwoFactorAuthentication::ForcedRegistration::TwoFactorDevicesControll
allow_any_instance_of(::TwoFactorAuthentication::TokenService)
.to receive(:verify)
.with('1234')
- .and_return(ServiceResult.new(success: true))
+ .and_return(ServiceResult.success)
post :confirm, params: { device_id: device.id, otp: '1234' }
expect(response).to redirect_to stage_success_path(stage: :two_factor_authentication, secret: 'asdf')
diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb
index 287186e19f4..0ce5763a16f 100644
--- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb
+++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb
@@ -144,7 +144,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee:
it 'redirects to index if token request failed' do
allow_any_instance_of(::TwoFactorAuthentication::TokenService)
.to receive(:request)
- .and_return(ServiceResult.new(success: false))
+ .and_return(ServiceResult.failure)
get :confirm, params: { device_id: device.id }
expect(response).to redirect_to action: :index
@@ -183,7 +183,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee:
allow_any_instance_of(::TwoFactorAuthentication::TokenService)
.to receive(:verify)
.with('1234')
- .and_return(ServiceResult.new(success: true))
+ .and_return(ServiceResult.success)
post :confirm, params: { device_id: device.id, otp: '1234' }
expect(response).to redirect_to action: :index
@@ -200,7 +200,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee:
allow_any_instance_of(::TwoFactorAuthentication::TokenService)
.to receive(:verify)
.with('1234')
- .and_return(ServiceResult.new(success: true))
+ .and_return(ServiceResult.success)
post :confirm, params: { device_id: device.id, otp: '1234' }
expect(response).to redirect_to action: :index
diff --git a/modules/xls_export/spec/patches/work_packages_controller_patch_spec.rb b/modules/xls_export/spec/patches/work_packages_controller_patch_spec.rb
index cb28b63a041..be4d3ce62a2 100644
--- a/modules/xls_export/spec/patches/work_packages_controller_patch_spec.rb
+++ b/modules/xls_export/spec/patches/work_packages_controller_patch_spec.rb
@@ -133,7 +133,7 @@ describe WorkPackagesController, type: :controller do
allow(service_instance)
.to receive(:call)
.with(query:, mime_type: mime_type.to_sym, params: anything)
- .and_return(ServiceResult.new(result: export_result))
+ .and_return(ServiceResult.failure(result: export_result))
end
it 'fulfills the defined should_receives' do
diff --git a/spec/controllers/roles_controller_spec.rb b/spec/controllers/roles_controller_spec.rb
index 448cbe1d5f0..dffe409b50e 100644
--- a/spec/controllers/roles_controller_spec.rb
+++ b/spec/controllers/roles_controller_spec.rb
@@ -49,7 +49,7 @@ describe RolesController, type: :controller do
describe '#create' do
let(:new_role) { double('role double') }
- let(:service_call) { ServiceResult.new(success: true, result: new_role) }
+ let(:service_call) { ServiceResult.success(result: new_role) }
let(:create_params) do
cp = ActionController::Parameters.new(params[:role])
.merge(global_role: nil, copy_workflow_from: '5')
@@ -123,7 +123,7 @@ describe RolesController, type: :controller do
end
context 'failure' do
- let(:service_call) { ServiceResult.new(success: false, result: new_role) }
+ let(:service_call) { ServiceResult.failure(result: new_role) }
it 'returns a 200 OK' do
expect(response.status)
@@ -166,7 +166,7 @@ describe RolesController, type: :controller do
.and_return(d)
end
end
- let(:service_call) { ServiceResult.new(success: true, result: role) }
+ let(:service_call) { ServiceResult.success(result: role) }
let(:update_params) do
cp = ActionController::Parameters.new(params[:role])
cp.permit!
@@ -206,7 +206,7 @@ describe RolesController, type: :controller do
end
context 'failure' do
- let(:service_call) { ServiceResult.new(success: false, result: role) }
+ let(:service_call) { ServiceResult.failure(result: role) }
it 'returns a 200 OK' do
expect(response.status)
@@ -258,10 +258,10 @@ describe RolesController, type: :controller do
.and_return(roles)
end
- let(:service_call0) { ServiceResult.new(success: true, result: role0) }
- let(:service_call1) { ServiceResult.new(success: true, result: role1) }
- let(:service_call2) { ServiceResult.new(success: true, result: role2) }
- let(:service_call3) { ServiceResult.new(success: true, result: role3) }
+ let(:service_call0) { ServiceResult.success(result: role0) }
+ let(:service_call1) { ServiceResult.success(result: role1) }
+ let(:service_call2) { ServiceResult.success(result: role2) }
+ let(:service_call3) { ServiceResult.success(result: role3) }
let(:update_params0) do
{ permissions: [] }
end
@@ -349,7 +349,7 @@ describe RolesController, type: :controller do
end
context 'failure' do
- let(:service_call2) { ServiceResult.new(success: false, result: role2) }
+ let(:service_call2) { ServiceResult.failure(result: role2) }
it 'returns a 200 OK' do
expect(response.status)
diff --git a/spec/controllers/work_packages_controller_spec.rb b/spec/controllers/work_packages_controller_spec.rb
index ccf990c1775..4adda33a9ab 100644
--- a/spec/controllers/work_packages_controller_spec.rb
+++ b/spec/controllers/work_packages_controller_spec.rb
@@ -175,7 +175,7 @@ describe WorkPackagesController, type: :controller do
allow(service_instance)
.to receive(:call)
.with(query:, mime_type: mime_type.to_sym, params: anything)
- .and_return(ServiceResult.new(result: 'uuid of the export job'))
+ .and_return(ServiceResult.failure(result: 'uuid of the export job'))
end
it 'redirects to the job status' do
diff --git a/spec/controllers/workflows_controller_spec.rb b/spec/controllers/workflows_controller_spec.rb
index fbe06bef675..c1f7bbfbda8 100644
--- a/spec/controllers/workflows_controller_spec.rb
+++ b/spec/controllers/workflows_controller_spec.rb
@@ -91,7 +91,7 @@ describe WorkflowsController, type: :controller do
.with(status_params)
.and_return(call_result)
end
- let(:call_result) { ServiceResult.new success: true }
+ let(:call_result) { ServiceResult.success }
let(:params) do
{
role_id: role.id,
diff --git a/spec/requests/oauth_clients/callback_flow_spec.rb b/spec/requests/oauth_clients/callback_flow_spec.rb
index ed357ccf26d..a3bdc757d4a 100644
--- a/spec/requests/oauth_clients/callback_flow_spec.rb
+++ b/spec/requests/oauth_clients/callback_flow_spec.rb
@@ -131,7 +131,7 @@ describe 'OAuthClient callback endpoint', with_flag: { storages_module_active: t
allow(::OAuthClients::ConnectionManager)
.to receive(:new).and_return(connection_manager)
allow(connection_manager)
- .to receive(:code_to_token).with(code).and_return(ServiceResult.new(success: false))
+ .to receive(:code_to_token).with(code).and_return(ServiceResult.failure)
uri.query = URI.encode_www_form([['code', code], ['state', state]])
get uri.to_s
diff --git a/spec/services/base/base_callable_spec.rb b/spec/services/base/base_callable_spec.rb
index b23f3b00055..d80ab47616c 100644
--- a/spec/services/base/base_callable_spec.rb
+++ b/spec/services/base/base_callable_spec.rb
@@ -33,7 +33,7 @@ describe ::BaseServices::BaseCallable, type: :model do
Class.new(::BaseServices::BaseCallable) do
def perform(*)
state.test = 'foo'
- ServiceResult.new(success: true, result: 'something')
+ ServiceResult.success(result: 'something')
end
def rollback
@@ -46,7 +46,7 @@ describe ::BaseServices::BaseCallable, type: :model do
Class.new(::BaseServices::BaseCallable) do
def perform(*)
state.test2 = 'foo'
- ServiceResult.new(success: true, result: 'something')
+ ServiceResult.success(result: 'something')
end
def rollback
diff --git a/spec/services/custom_actions/update_work_package_service_spec.rb b/spec/services/custom_actions/update_work_package_service_spec.rb
index 67c22821da4..7d1d9fa57b5 100644
--- a/spec/services/custom_actions/update_work_package_service_spec.rb
+++ b/spec/services/custom_actions/update_work_package_service_spec.rb
@@ -84,7 +84,7 @@ describe CustomActions::UpdateWorkPackageService do
end
let(:work_package) { build_stubbed(:work_package) }
let(:result) do
- ServiceResult.new(result: work_package, success: true)
+ ServiceResult.success(result: work_package)
end
let(:validation_result) { true }
let!(:contract) do
@@ -194,7 +194,7 @@ describe CustomActions::UpdateWorkPackageService do
context 'on unfixable validation error' do
let(:result) do
- ServiceResult.new(result: work_package, success: false)
+ ServiceResult.failure(result: work_package)
end
let(:update_service_call_implementation) do
-> do
diff --git a/spec/services/groups/update_service_spec.rb b/spec/services/groups/update_service_spec.rb
index 1d6cb62eee7..e88d729ea1f 100644
--- a/spec/services/groups/update_service_spec.rb
+++ b/spec/services/groups/update_service_spec.rb
@@ -32,7 +32,7 @@ require 'services/base_services/behaves_like_update_service'
describe Groups::UpdateService, type: :model do
it_behaves_like 'BaseServices update service' do
let(:add_service_result) do
- ServiceResult.new success: true
+ ServiceResult.success
end
let!(:add_users_service) do
add_service = instance_double(Groups::AddUsersService)
@@ -82,7 +82,7 @@ describe Groups::UpdateService, type: :model do
context 'with the AddUsersService being unsuccessful' do
let(:add_service_result) do
- ServiceResult.new success: false
+ ServiceResult.failure
end
it 'is failure' do
diff --git a/spec/services/notifications/create_from_journal_job_shared.rb b/spec/services/notifications/create_from_journal_job_shared.rb
index ee8f4549773..a77930027a7 100644
--- a/spec/services/notifications/create_from_journal_job_shared.rb
+++ b/spec/services/notifications/create_from_journal_job_shared.rb
@@ -85,7 +85,7 @@ shared_context 'with CreateFromJournalJob context' do
.and_return(notifications_service)
allow(notifications_service)
.to receive(:call)
- .and_return(ServiceResult.new(success: true, result: notification))
+ .and_return(ServiceResult.success(result: notification))
expect(call.all_results)
.to match_array([notification])
diff --git a/spec/services/relations/create_service_spec.rb b/spec/services/relations/create_service_spec.rb
index eed11b5f5ed..bd47eacd7e4 100644
--- a/spec/services/relations/create_service_spec.rb
+++ b/spec/services/relations/create_service_spec.rb
@@ -99,10 +99,10 @@ describe Relations::CreateService do
context 'if all valid and it is a follows relation' do
let(:set_schedule_service) { double('set schedule service') }
let(:set_schedule_work_package2_result) do
- ServiceResult.new success: true, result: work_package2, errors: work_package2.errors
+ ServiceResult.success result: work_package2, errors: work_package2.errors
end
let(:set_schedule_result) do
- sr = ServiceResult.new success: true, result: work_package2, errors: work_package2.errors
+ sr = ServiceResult.success result: work_package2, errors: work_package2.errors
sr.dependent_results << set_schedule_work_package2_result
sr
end
diff --git a/spec/services/relations/update_service_spec.rb b/spec/services/relations/update_service_spec.rb
index 848563e5cca..51ad3955294 100644
--- a/spec/services/relations/update_service_spec.rb
+++ b/spec/services/relations/update_service_spec.rb
@@ -94,10 +94,10 @@ describe Relations::UpdateService do
context 'when all valid and it is a follows relation' do
let(:set_schedule_service) { double('set schedule service') }
let(:set_schedule_work_package2_result) do
- ServiceResult.new success: true, result: work_package2, errors: work_package2.errors
+ ServiceResult.success result: work_package2, errors: work_package2.errors
end
let(:set_schedule_result) do
- sr = ServiceResult.new success: true, result: work_package2, errors: work_package2.errors
+ sr = ServiceResult.success result: work_package2, errors: work_package2.errors
sr.dependent_results << set_schedule_work_package2_result
sr
end
diff --git a/spec/services/shared/service_context_integration_spec.rb b/spec/services/shared/service_context_integration_spec.rb
index 106d2f8edec..7fea34e81a8 100644
--- a/spec/services/shared/service_context_integration_spec.rb
+++ b/spec/services/shared/service_context_integration_spec.rb
@@ -48,7 +48,7 @@ describe Shared::ServiceContext, 'integration', type: :model do
VALUES ('test_setting', 'abc')
SQL
- ServiceResult.new success: false
+ ServiceResult.failure
end
end
@@ -59,7 +59,7 @@ describe Shared::ServiceContext, 'integration', type: :model do
VALUES ('test_setting', 'abc')
SQL
- ServiceResult.new success: true
+ ServiceResult.success
end
end
end.new(user)
diff --git a/spec/services/shared_type_service.rb b/spec/services/shared_type_service.rb
index 79fe85ed8a7..e03e9a93ffd 100644
--- a/spec/services/shared_type_service.rb
+++ b/spec/services/shared_type_service.rb
@@ -133,7 +133,7 @@ shared_examples_for 'type service' do
end
let(:params) { { attribute_groups: [query_group_params] } }
let(:query) { create(:query, user_id: 0) }
- let(:service_result) { ServiceResult.new(success: true, result: query) }
+ let(:service_result) { ServiceResult.success(result: query) }
before do
allow(Query)
@@ -168,7 +168,7 @@ shared_examples_for 'type service' do
context 'when the query service reports an error' do
let(:success) { false }
- let(:service_result) { ServiceResult.new(success: false, result: nil) }
+ let(:service_result) { ServiceResult.failure(result: nil) }
it 'reports the error' do
expect(service_call).to be_failure
diff --git a/spec/services/users/register_user_service_spec.rb b/spec/services/users/register_user_service_spec.rb
index 73ae0a9a670..30380884ed0 100644
--- a/spec/services/users/register_user_service_spec.rb
+++ b/spec/services/users/register_user_service_spec.rb
@@ -100,7 +100,7 @@ describe Users::RegisterUserService do
# Assuming the next returns a result
expect(instance)
.to(receive(:ensure_user_limit_not_reached!))
- .and_return(ServiceResult.new(success: false, result: user, message: 'test stop'))
+ .and_return(ServiceResult.failure(result: user, message: 'test stop'))
expect(user).not_to receive(:activate)
expect(user).not_to receive(:save)
@@ -137,7 +137,7 @@ describe Users::RegisterUserService do
# Assuming the next returns a result
expect(instance)
.to(receive(:register_by_email_activation))
- .and_return(ServiceResult.new(success: false, result: user, message: 'test stop'))
+ .and_return(ServiceResult.failure(result: user, message: 'test stop'))
call = instance.call
expect(call.result).to eq user
@@ -173,7 +173,7 @@ describe Users::RegisterUserService do
# Assuming the next returns a result
expect(instance)
.to(receive(:register_automatically))
- .and_return(ServiceResult.new(success: false, result: user, message: 'test stop'))
+ .and_return(ServiceResult.failure(result: user, message: 'test stop'))
expect(user).not_to receive(:activate)
expect(user).not_to receive(:save)
@@ -211,7 +211,7 @@ describe Users::RegisterUserService do
# Assuming the next returns a result
expect(instance)
.to(receive(:register_manually))
- .and_return(ServiceResult.new(success: false, result: user, message: 'test stop'))
+ .and_return(ServiceResult.failure(result: user, message: 'test stop'))
expect(user).not_to receive(:activate)
expect(user).not_to receive(:save)
diff --git a/spec/services/work_packages/delete_service_spec.rb b/spec/services/work_packages/delete_service_spec.rb
index 072ecfbeafc..587d4198c24 100644
--- a/spec/services/work_packages/delete_service_spec.rb
+++ b/spec/services/work_packages/delete_service_spec.rb
@@ -102,13 +102,10 @@ describe WorkPackages::DeleteService do
let(:expect_inherited_attributes_service_calls) do
inherited_service_instance = double(WorkPackages::UpdateAncestorsService)
- service_result = ServiceResult.new(success: true,
- result: work_package)
+ service_result = ServiceResult.success(result: work_package)
- service_result.dependent_results += [ServiceResult.new(success: true,
- result: parent),
- ServiceResult.new(success: true,
- result: grandparent)]
+ service_result.dependent_results += [ServiceResult.success(result: parent),
+ ServiceResult.success(result: grandparent)]
expect(WorkPackages::UpdateAncestorsService)
.to receive(:new)
diff --git a/spec/workers/work_packages/exports/export_job_spec.rb b/spec/workers/work_packages/exports/export_job_spec.rb
index ed35dc3042d..9f21b14fa63 100644
--- a/spec/workers/work_packages/exports/export_job_spec.rb
+++ b/spec/workers/work_packages/exports/export_job_spec.rb
@@ -82,7 +82,7 @@ describe WorkPackages::ExportJob do
expect(File.basename(file))
.to end_with ".#{mime_type}"
- ServiceResult.new(result: attachment, success: true)
+ ServiceResult.success(result: attachment)
end
allow(exporter).to receive(:new).and_return exporter_instance