From 64f72916cbeb47980dcadd0eaf72004397336838 Mon Sep 17 00:00:00 2001 From: Mantas Date: Thu, 17 Jun 2021 08:37:10 +0300 Subject: [PATCH] Fixes #3618 - Ensure to migrate old calendar URLs for google calendar sources --- ...051913_issue_3618_google_calendar_url_https.rb | 14 ++++++++++++++ .../issue_3618_google_calendar_url_https_spec.rb | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 db/migrate/20210617051913_issue_3618_google_calendar_url_https.rb create mode 100644 spec/db/migrate/issue_3618_google_calendar_url_https_spec.rb diff --git a/db/migrate/20210617051913_issue_3618_google_calendar_url_https.rb b/db/migrate/20210617051913_issue_3618_google_calendar_url_https.rb new file mode 100644 index 000000000..2d53227ed --- /dev/null +++ b/db/migrate/20210617051913_issue_3618_google_calendar_url_https.rb @@ -0,0 +1,14 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +class Issue3618GoogleCalendarUrlHttps < ActiveRecord::Migration[5.2] + def change + return if !Setting.exists?(name: 'system_init_done') + + Calendar + .where('ical_url LIKE ?', 'http://www.google.com/calendar/ical/%') + .each do |calendar| + calendar.ical_url.sub!(%r{^http://}, 'https://') + calendar.save + end + end +end diff --git a/spec/db/migrate/issue_3618_google_calendar_url_https_spec.rb b/spec/db/migrate/issue_3618_google_calendar_url_https_spec.rb new file mode 100644 index 000000000..05f526855 --- /dev/null +++ b/spec/db/migrate/issue_3618_google_calendar_url_https_spec.rb @@ -0,0 +1,15 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe Issue3618GoogleCalendarUrlHttps, type: :db_migration, db_strategy: :reset do + let(:url) { 'http://www.google.com/calendar/ical/en.lithuanian%%23holiday%%40group.v.calendar.google.com/public/basic.ics' } + let(:calendar) { create :calendar, ical_url: url } + + it 'migrates Google Calendar URLs' do + expect { migrate } + .to change { calendar.reload.ical_url.starts_with? 'https://' } + .from(false) + .to(true) + end +end