FIX: Ensure calendar events are recreated when first post changes
This commit is contained in:
parent
bb973f6638
commit
0f922cdcb8
|
@ -22,17 +22,22 @@ module DiscourseCalendar
|
|||
|
||||
def self.update(post)
|
||||
calendar = extract(post)
|
||||
|
||||
return destroy(post) if calendar.size != 1
|
||||
calendar = calendar.first
|
||||
|
||||
post.custom_fields[DiscourseCalendar::CALENDAR_CUSTOM_FIELD] = calendar.delete("type") || "dynamic"
|
||||
post.save_custom_fields
|
||||
|
||||
Post.where(topic_id: post.topic_id).each { |p| CalendarEvent.update(p) }
|
||||
end
|
||||
|
||||
def self.destroy(post)
|
||||
return if post.custom_fields[DiscourseCalendar::CALENDAR_CUSTOM_FIELD].blank?
|
||||
|
||||
post.custom_fields.delete(DiscourseCalendar::CALENDAR_CUSTOM_FIELD)
|
||||
post.save_custom_fields
|
||||
|
||||
CalendarEvent.where(topic_id: post.topic_id).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,6 +74,17 @@ describe CalendarEvent do
|
|||
expect(post.deleted_at).to eq(nil)
|
||||
end
|
||||
|
||||
it "recreates calendar event for all posts" do
|
||||
post = create_post(raw: 'Rome [date="2018-06-05" time="10:20:00"]', topic: calendar_post.topic)
|
||||
expect(CalendarEvent.count).to eq(1)
|
||||
|
||||
PostDestroyer.new(Discourse.system_user, calendar_post.reload).destroy
|
||||
expect(CalendarEvent.count).to eq(0)
|
||||
|
||||
PostDestroyer.new(Discourse.system_user, calendar_post.reload).recover
|
||||
expect(CalendarEvent.count).to eq(1)
|
||||
end
|
||||
|
||||
describe "all day event site settings" do
|
||||
before do
|
||||
SiteSetting.all_day_event_start_time = "06:30"
|
||||
|
|
Loading…
Reference in New Issue