diff --git a/modules/meeting/spec/factories/recurring_meeting_factory.rb b/modules/meeting/spec/factories/recurring_meeting_factory.rb new file mode 100644 index 000000000000..94ae8a616ec8 --- /dev/null +++ b/modules/meeting/spec/factories/recurring_meeting_factory.rb @@ -0,0 +1,54 @@ +#-- 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. +#++ + +FactoryBot.define do + factory :recurring_meeting, class: "RecurringMeeting" do |m| + author factory: :user + project + start_time { Date.tomorrow + 10.hours } + end_date { 1.year.from_now } + duration { 1.0 } + frequency { "weekly" } + interval { 1 } + iterations { 10 } + end_after { "specific_date" } + + location { "https://some-url.com" } + m.sequence(:title) { |n| "Meeting series #{n}" } + + after(:create) do |recurring_meeting, evaluator| + recurring_meeting.project = evaluator.project if evaluator.project + recurring_meeting.template = create(:meeting, recurring_meeting:) + end + + after(:stub) do |recurring_meeting, evaluator| + recurring_meeting.project = evaluator.project if evaluator.project + recurring_meeting.template = build_stubbed(:meeting, recurring_meeting:) + end + end +end diff --git a/modules/meeting/spec/models/recurring_meeting_spec.rb b/modules/meeting/spec/models/recurring_meeting_spec.rb index 51386b89bf4b..59fdd04eebed 100644 --- a/modules/meeting/spec/models/recurring_meeting_spec.rb +++ b/modules/meeting/spec/models/recurring_meeting_spec.rb @@ -1,5 +1,29 @@ -require 'rails_helper' +require "spec_helper" +require_module_spec_helper -RSpec.describe RecurringMeeting, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +RSpec.describe RecurringMeeting, + with_settings: { + date_format: "%Y-%m-%d" + } do + describe "end_date" do + subject { build(:recurring_meeting, start_date: (Date.current + 2.days).iso8601, end_date:) } + + context "with end_date before start_date" do + let(:end_date) { Date.current + 1.day } + + it "is invalid" do + expect(subject).not_to be_valid + expect(subject.errors[:end_date]).to include("must be after #{subject.start_date}.") + end + end + + context "with end_date in the past" do + let(:end_date) { Date.yesterday } + + it "is invalid" do + expect(subject).not_to be_valid + expect(subject.errors[:end_date]).to include("must be in the future.") + end + end + end end