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

Add specs for the AllMeetings generator

Klaus Zandersc74368317b25
diff --git a/modules/meeting/app/services/all_meetings/ical_service.rb b/modules/meeting/app/services/all_meetings/ical_service.rb
index a9e980d427d..677b70bd719 100644
--- a/modules/meeting/app/services/all_meetings/ical_service.rb
+++ b/modules/meeting/app/services/all_meetings/ical_service.rb
@@ -55,7 +55,7 @@ module AllMeetings
ServiceResult.success(result: calendar.to_ical)
end
rescue StandardError => e
- Rails.logger.error("Failed to generate ICS for meeting #{@meeting.id}: #{e.message}")
+ Rails.logger.error("Failed to generate ICS for all meetings: #{e.message}")
ServiceResult.failure(message: e.message)
end
diff --git a/modules/meeting/spec/services/all_meetings/ical_service_spec.rb b/modules/meeting/spec/services/all_meetings/ical_service_spec.rb
new file mode 100644
index 00000000000..b26494d87bc
--- /dev/null
+++ b/modules/meeting/spec/services/all_meetings/ical_service_spec.rb
@@ -0,0 +1,112 @@
+# 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 AllMeetings::ICalService, type: :model do # rubocop:disable RSpec/SpecFilePathFormat
+ let(:user) do
+ create(:user,
+ firstname: "Bob",
+ lastname: "Barker",
+ preferences: { time_zone: "America/New_York" },
+ member_with_permissions: { project => [:view_meetings] })
+ end
+ let(:user2) { create(:user, firstname: "Foo", lastname: "Fooer", mail: "[email protected]") }
+ let(:project) { create(:project, name: "My Project") }
+
+ let(:relevant_time) { Time.current.utc.change(hour: 10, minute: 0, second: 0) }
+
+ let!(:meeting) do
+ create(:meeting,
+ author: user,
+ project:,
+ title: "Important meeting",
+ participants: [
+ MeetingParticipant.new(user:),
+ MeetingParticipant.new(user: user2)
+ ],
+ location: "https://example.com/meet/important-meeting",
+ start_time: relevant_time + 1.week,
+ duration: 1.0)
+ end
+
+ let!(:past_meeting) do
+ create(:meeting,
+ author: user,
+ project:,
+ title: "Important meeting",
+ participants: [
+ MeetingParticipant.new(user:),
+ MeetingParticipant.new(user: user2)
+ ],
+ location: "https://example.com/meet/important-meeting",
+ start_time: relevant_time - 1.week,
+ duration: 1.0)
+ end
+
+ let(:service) { described_class.new(user:) }
+ let(:result) { service.call.result }
+
+ let(:entry) { Icalendar::Event.parse(result).first }
+
+ describe "#call" do
+ it "returns a success" do
+ expect(service.call).to be_success
+ end
+
+ context "when exception is raised" do
+ subject { service.call }
+
+ before do
+ allow(Meetings::CalendarWrapper).to receive(:new).and_raise StandardError.new("Oh noes")
+ end
+
+ it "returns a failure" do
+ expect(subject).to be_failure
+ expect(subject.message).to eq("Oh noes")
+ end
+ end
+
+ it "renders the ICS file", :aggregate_failures do
+ expect(result).to be_a String
+
+ expect(entry.organizer.to_s).to eq("mailto:#{Setting.mail_from}")
+ expect(entry.attendee.map(&:to_s)).to contain_exactly("mailto:[email protected]", "mailto:[email protected]")
+ expect(entry.dtstart.utc).to eq meeting.start_time
+ expect(entry.dtend.utc).to eq meeting.start_time + 1.hour
+ expect(entry.summary).to eq "[My Project] Important meeting"
+ expect(entry.description).to eq "[My Project] Meeting: Important meeting"
+ expect(entry.location).to eq(meeting.location.presence)
+ expect(entry.dtstart).to eq (relevant_time + 1.week).in_time_zone("Europe/Berlin")
+ expect(entry.dtend).to eq (relevant_time + 1.week + 1.hour).in_time_zone("Europe/Berlin")
+ end
+ end
+end