mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-27 10:35:36 +08:00
This commit removes the `include_expired` param and its associated site setting `include_expired_events_on_calendar`. Since recent changes this performance optimisation doesn’t make sense anymore as we only load the events needed for a specific before/after range. The rules are the following: Non recurring events: - They have to have a start date between before/after range Recurring events: - they don't have event_dates, so we don't rely on it for them - what's important for recurring_event, is the recurring_until property and the original starts at - we want to return recurring events when their start date is is after the after param and the before param is before the recurring_until - if recurring_until is NULL we just look at the start date It's done this way as the serializer only sends the rrule to the front, and this is the frontend which will compute the recurring events, but if you want to have all the events of august, and your recurring event is starting in june, you need to also fetch this june event. This commit ensures we can now deal properly with nil dates as it makes no sense to have dates for an expired recurring event.
35 lines
1 KiB
Ruby
Vendored
35 lines
1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe TopicViewSerializer do
|
|
subject(:serializer) do
|
|
described_class.new(TopicView.new(topic), scope: Guardian.new, root: false)
|
|
end
|
|
|
|
let(:topic) { Fabricate(:topic) }
|
|
let(:first_post) { Fabricate(:post, topic:) }
|
|
let(:parsed_json) { JSON.parse(serializer.to_json) }
|
|
|
|
before do
|
|
freeze_time(Time.utc(2020, 4, 24, 14, 10))
|
|
Jobs.run_immediately!
|
|
SiteSetting.calendar_enabled = true
|
|
SiteSetting.discourse_post_event_enabled = true
|
|
DiscoursePostEvent::Event.create!(
|
|
id: first_post.id,
|
|
original_starts_at: 1.hour.from_now,
|
|
original_ends_at: 2.hours.from_now,
|
|
)
|
|
end
|
|
|
|
describe "#event_starts_at" do
|
|
it "returns the start time of the event in proper format" do
|
|
expect(parsed_json["event_starts_at"]).to eq("2020-04-24T15:10:00.000Z")
|
|
end
|
|
end
|
|
|
|
describe "#event_ends_at" do
|
|
it "returns the end time of the event in proper format" do
|
|
expect(parsed_json["event_ends_at"]).to eq("2020-04-24T16:10:00.000Z")
|
|
end
|
|
end
|
|
end
|