mirror of
https://github.com/discourse/discourse.git
synced 2026-08-09 12:38:21 -05:00
FIX: Don’t create empty event dates in calendar
Currently, there’s an edge case in the calendar plugin: when a recurring event (typically a daily one) ends on the next day, it can happen that we create a `event_date` record with no `starts_at` attribute. This is because `Event#calculate_next_date` doesn’t check the result from `RRuleGenerator.generate`. This patch addresses the issue simply by checking the value of `RRuleGenerator.generate` and returns early if the value is `nil`.
This commit is contained in:
committed by
Loïc Guitaut
parent
793c55aa58
commit
bf08512288
@@ -397,6 +397,7 @@ module DiscoursePostEvent
|
||||
recurrence:,
|
||||
recurrence_until:,
|
||||
).first
|
||||
return unless next_starts_at
|
||||
|
||||
if original_ends_at
|
||||
difference = original_ends_at - original_starts_at
|
||||
|
||||
@@ -501,4 +501,25 @@ describe DiscoursePostEvent::Event do
|
||||
expect(event_1.missing_users.pluck(:id)).to match_array([user_1.id, user_2.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#calculate_next_date" do
|
||||
subject(:next_date) { event.calculate_next_date }
|
||||
|
||||
context "when the event is recurring" do
|
||||
context "when the recurring ends on the next day" do
|
||||
let(:event) do
|
||||
Fabricate(
|
||||
:event,
|
||||
recurrence: "every_day",
|
||||
recurrence_until: "2020-04-25 06:59",
|
||||
original_starts_at: "2020-04-20 13:00",
|
||||
)
|
||||
end
|
||||
|
||||
it "returns nothing" do
|
||||
expect(next_date).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user