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

Extract cleanup_body spec into newly introduced handlers spec

Oliver Günther0e2142640ae1
diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb
index 6a4a553fd50..ecddc7f31e1 100644
--- a/spec/models/mail_handler_spec.rb
+++ b/spec/models/mail_handler_spec.rb
@@ -1567,29 +1567,6 @@ RSpec.describe IncomingEmails::MailHandler do
end
end
- describe "#cleanup_body" do
- skip "move to handler spec"
- let(:input) do
- "Subject:foo\nDescription:bar\n" \
- ">>> myserver.example.org 2016-01-27 15:56 >>>\n... (Email-Body) ..."
- end
- let(:mail_stub) { instance_double(Mail, from: ["[email protected]"]) }
- let(:service) { IncomingEmails::DispatchService.new(mail_stub, options: {}) }
-
- context "with regex delimiter" do
- before do
- allow(Setting).to receive(:mail_handler_body_delimiter_regex).and_return(">>>.+?>>>.*")
- allow(service).to receive(:plain_text_body).and_return(input)
- allow(service).to receive(:cleaned_up_text_body).and_call_original
- end
-
- it "removes the irrelevant lines" do
- expect(service.send(:cleaned_up_text_body)).to eq("Subject:foo\nDescription:bar")
- expect(service).to have_received(:cleaned_up_text_body)
- end
- end
- end
-
private
def read_email(filename)
diff --git a/spec/services/incoming_emails/handlers/base_spec.rb b/spec/services/incoming_emails/handlers/base_spec.rb
new file mode 100644
index 00000000000..4ad4d7f2a98
--- /dev/null
+++ b/spec/services/incoming_emails/handlers/base_spec.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+
+RSpec.describe IncomingEmails::Handlers::Base do
+ let(:user) { build_stubbed(:user) }
+ let(:reference) { nil }
+ let(:options) { {} }
+ let(:plain_text_body) { "Test body" }
+
+ subject do
+ described_class.new(nil, user:, reference:, plain_text_body:, options:)
+ end
+
+ describe "#cleanup_body" do
+ let(:plain_text_body) do
+ "Subject:foo\nDescription:bar\n" \
+ ">>> myserver.example.org 2016-01-27 15:56 >>>\n... (Email-Body) ..."
+ end
+
+ context "with regex delimiter" do
+ before do
+ allow(Setting).to receive(:mail_handler_body_delimiter_regex).and_return(">>>.+?>>>.*")
+ end
+
+ it "removes the irrelevant lines" do
+ expect(subject.cleaned_up_text_body).to eq("Subject:foo\nDescription:bar")
+ end
+ end
+ end
+end