Skip to content

Commit de34c9e

Browse files
preserve selected event types when disabling and reenabling sync uni events (#512)
1 parent dc58e23 commit de34c9e

2 files changed

Lines changed: 74 additions & 7 deletions

File tree

app/models/user_extension_config.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,10 @@ class UserExtensionConfig < ApplicationRecord
3232

3333
belongs_to :user
3434

35-
before_save :clear_categories_when_sync_disabled
3635
after_update :sync_calendar_if_settings_changed
3736

3837
private
3938

40-
def clear_categories_when_sync_disabled
41-
return unless will_save_change_to_sync_university_events? && !sync_university_events
42-
43-
self.university_event_categories = []
44-
end
45-
4639
def sync_calendar_if_settings_changed
4740
return unless saved_change_to_default_color_lecture? || saved_change_to_default_color_lab? ||
4841
saved_change_to_sync_university_events? || saved_change_to_university_event_categories?
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# frozen_string_literal: true
2+
3+
# == Schema Information
4+
#
5+
# Table name: user_extension_configs
6+
#
7+
# id :bigint not null, primary key
8+
# advanced_editing :boolean default(FALSE), not null
9+
# default_color_lab :string default("#f6bf26"), not null
10+
# default_color_lecture :string default("#039be5"), not null
11+
# enrolled_terms :jsonb not null
12+
# military_time :boolean default(FALSE), not null
13+
# show_historic_terms :boolean default(TRUE), not null
14+
# sync_university_events :boolean default(FALSE), not null
15+
# university_event_categories :jsonb
16+
# created_at :datetime not null
17+
# updated_at :datetime not null
18+
# user_id :bigint not null
19+
#
20+
require "rails_helper"
21+
22+
RSpec.describe UserExtensionConfig, type: :model do
23+
let(:user) do
24+
User.create!(
25+
email: "config-spec@example.com",
26+
password: "password123",
27+
password_confirmation: "password123"
28+
)
29+
end
30+
31+
# The user model creates a UserExtensionConfig on create; reuse it.
32+
let(:config) { user.user_extension_config }
33+
34+
before do
35+
allow(GoogleCalendarSyncJob).to receive(:perform_later)
36+
end
37+
38+
describe "toggling sync_university_events" do
39+
before do
40+
config.update!(
41+
sync_university_events: true,
42+
university_event_categories: %w[campus_event deadline]
43+
)
44+
end
45+
46+
it "preserves selected event types when sync is disabled" do
47+
config.update!(sync_university_events: false)
48+
49+
expect(config.reload.university_event_categories).to eq(%w[campus_event deadline])
50+
end
51+
52+
it "retains selected event types after disabling and re-enabling sync" do
53+
config.update!(sync_university_events: false)
54+
config.update!(sync_university_events: true)
55+
56+
expect(config.reload.university_event_categories).to eq(%w[campus_event deadline])
57+
end
58+
end
59+
60+
describe "sync_calendar_if_settings_changed" do
61+
it "enqueues a forced calendar sync when sync_university_events changes" do
62+
config.update!(sync_university_events: true)
63+
64+
expect(GoogleCalendarSyncJob).to have_received(:perform_later).with(user, force: true)
65+
end
66+
67+
it "enqueues a forced calendar sync when university_event_categories changes" do
68+
config.update!(sync_university_events: true)
69+
config.update!(university_event_categories: %w[finals])
70+
71+
expect(GoogleCalendarSyncJob).to have_received(:perform_later).with(user, force: true).twice
72+
end
73+
end
74+
end

0 commit comments

Comments
 (0)