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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
add specs for after_* updates to start/end date of meeting items
ulferts5da6e265c68f
diff --git a/modules/meeting/spec/models/meeting_agenda_item_spec.rb b/modules/meeting/spec/models/meeting_agenda_item_spec.rbindex 78183c4cfeb..f838c731817 100644--- a/modules/meeting/spec/models/meeting_agenda_item_spec.rb+++ b/modules/meeting/spec/models/meeting_agenda_item_spec.rb@@ -30,6 +30,8 @@require_relative "../spec_helper"+RSpec::Matchers.define_negated_matcher :not_change, :change+RSpec.describe MeetingAgendaItem dolet(:meeting_attributes) { {} }let(:meeting) { build_stubbed(:meeting, **meeting_attributes) }@@ -324,4 +326,130 @@ RSpec.describe MeetingAgendaItem doendendend++ describe "automatic updates to the start and end time", :aggregate_failures do+ let(:user) { create(:user) }+ let(:meeting) { create(:meeting, start_time: Time.current) }+ let(:section) { create(:meeting_section, meeting:) }+ let(:first_agenda_item) do+ described_class.create(+ title: "First item",+ meeting:,+ author: user,+ duration_in_minutes: 15+ )+ end+ let(:second_agenda_item) do+ described_class.create(+ title: "First item",+ meeting:,+ author: user,+ duration_in_minutes: 10+ )+ end+ let(:meeting_time) { meeting.start_time }++ context "when creating agenda items" do+ before do+ first_agenda_item.reload+ second_agenda_item.reload+ end++ it "updates time slots" do+ expect(first_agenda_item.start_time).to eq(meeting_time)+ expect(first_agenda_item.end_time).to eq(meeting_time + first_agenda_item.duration_in_minutes.minutes)+ expect(second_agenda_item.start_time).to eq(meeting_time + first_agenda_item.duration_in_minutes.minutes)+ expect(second_agenda_item.end_time).to eq(meeting_time ++ first_agenda_item.duration_in_minutes.minutes ++ second_agenda_item.duration_in_minutes.minutes)+ end+ end++ context "when updating agenda items" do+ before do+ first_agenda_item.reload+ second_agenda_item.reload+ end++ context "when changing duration" do+ it "updates time slots" do+ expect do+ first_agenda_item.update(duration_in_minutes: 30)+ first_agenda_item.reload+ second_agenda_item.reload+ end+ .to not_change { first_agenda_item.start_time }+ .and change(first_agenda_item, :end_time)+ .from(meeting_time + 15.minutes)+ .to(meeting_time + 30.minutes)+ .and change(second_agenda_item, :start_time)+ .from(meeting_time + 15.minutes)+ .to(meeting_time + 30.minutes)+ .and change(second_agenda_item, :end_time)+ .from(meeting_time + 15.minutes + second_agenda_item.duration_in_minutes.minutes)+ .to(meeting_time + 30.minutes + second_agenda_item.duration_in_minutes.minutes)+ end+ end++ context "when changing position" do+ it "updates time slots for all items" do+ expect do+ second_agenda_item.update(position: 1)++ first_agenda_item.reload+ second_agenda_item.reload+ end+ .to change(first_agenda_item, :start_time)+ .from(meeting_time)+ .to(meeting_time + second_agenda_item.duration_in_minutes.minutes)+ .and change(first_agenda_item, :end_time)+ .from(meeting_time + first_agenda_item.duration_in_minutes.minutes)+ .to(meeting_time ++ second_agenda_item.duration_in_minutes.minutes ++ first_agenda_item.duration_in_minutes.minutes)+ .and change(second_agenda_item, :start_time)+ .from(meeting_time + first_agenda_item.duration_in_minutes.minutes)+ .to(meeting_time)+ .and change(second_agenda_item, :end_time)+ .from(meeting_time ++ second_agenda_item.duration_in_minutes.minutes ++ first_agenda_item.duration_in_minutes.minutes)+ .to(meeting_time + second_agenda_item.duration_in_minutes.minutes)+ end+ end++ context "when changing other attributes" do+ it "does not update time slots" do+ expect do+ first_agenda_item.update(title: "New title")+ first_agenda_item.reload+ end+ .to not_change { first_agenda_item.start_time }+ .and(not_change { first_agenda_item.end_time })+ end+ end+ end++ context "when destroying an agenda item" do+ before do+ first_agenda_item.reload+ second_agenda_item.reload+ end++ it "updates time slots for remaining items" do+ expect do+ first_agenda_item.destroy+ second_agenda_item.reload+ end+ .to change(second_agenda_item, :start_time)+ .from(meeting_time + first_agenda_item.duration_in_minutes.minutes)+ .to(meeting_time)+ .and change(second_agenda_item, :end_time)+ .from(meeting_time ++ first_agenda_item.duration_in_minutes.minutes ++ second_agenda_item.duration_in_minutes.minutes)+ .to(meeting_time + second_agenda_item.duration_in_minutes.minutes)+ end+ end+ endend