Skip to content

Commit

Permalink
Add spec for date validation
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Nov 28, 2024
1 parent d5aa2b9 commit 5a72451
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
54 changes: 54 additions & 0 deletions modules/meeting/spec/factories/recurring_meeting_factory.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 27 additions & 3 deletions modules/meeting/spec/models/recurring_meeting_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5a72451

Please sign in to comment.