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

attachment create service more in line with general layout

ulferts056b6f45af57
diff --git a/app/services/add_attachment_service.rb b/app/services/attachments/create_service.rb
similarity index 96%
rename from app/services/add_attachment_service.rb
rename to app/services/attachments/create_service.rb
index 6f7d5b9638b..6f51a82f7bb 100644
--- a/app/services/add_attachment_service.rb
+++ b/app/services/attachments/create_service.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class AddAttachmentService
+class Attachments::CreateService
attr_reader :container, :author
def initialize(container, author:)
@@ -39,7 +39,7 @@ class AddAttachmentService
# In case the container supports it, a journal will be written.
#
# An ActiveRecord::RecordInvalid error is raised if any record can't be saved.
- def add_attachment(uploaded_file:, description:)
+ def call(uploaded_file:, description:)
attachment = Attachment.new(file: uploaded_file,
container: container,
description: description,
diff --git a/config/initializers/register_renderer.rb b/config/initializers/register_renderer.rb
index 8368b5c6085..03b401fd9df 100644
--- a/config/initializers/register_renderer.rb
+++ b/config/initializers/register_renderer.rb
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
diff --git a/lib/api/v3/attachments/attachments_by_container_api.rb b/lib/api/v3/attachments/attachments_by_container_api.rb
index ff31ef96e32..3f41ee9c868 100644
--- a/lib/api/v3/attachments/attachments_by_container_api.rb
+++ b/lib/api/v3/attachments/attachments_by_container_api.rb
@@ -79,11 +79,11 @@ module API
file[:type],
file_name: metadata.file_name.to_s
- service = AddAttachmentService.new(container, author: current_user)
+ service = Attachments::CreateService.new(container, author: current_user)
with_handled_create_errors do
- service.add_attachment uploaded_file: uploaded_file,
- description: metadata.description
+ service.call uploaded_file: uploaded_file,
+ description: metadata.description
end
end
diff --git a/spec/services/add_attachment_service_spec.rb b/spec/services/attachments/create_service_spec.rb
similarity index 93%
rename from spec/services/add_attachment_service_spec.rb
rename to spec/services/attachments/create_service_spec.rb
index 98dec524b2c..9ccc80f74f0 100644
--- a/spec/services/add_attachment_service_spec.rb
+++ b/spec/services/attachments/create_service_spec.rb
@@ -28,7 +28,7 @@
require 'spec_helper'
-describe AddAttachmentService do
+describe Attachments::CreateService do
let(:user) { FactoryBot.create(:user) }
let(:work_package) { FactoryBot.create(:work_package) }
let(:container) { work_package }
@@ -36,10 +36,10 @@ describe AddAttachmentService do
subject { described_class.new(work_package, author: user) }
- describe '#add_attachment' do
+ describe '#call' do
def call_tested_method
- subject.add_attachment uploaded_file: FileHelpers.mock_uploaded_file(name: 'foobar.txt'),
- description: description
+ subject.call uploaded_file: FileHelpers.mock_uploaded_file(name: 'foobar.txt'),
+ description: description
end
shared_examples 'successful creation' do