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