Skip to content

Commit

Permalink
Fix: S'Up runs on time a week after being delayed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Run Cron committed Feb 3, 2025
1 parent aeec760 commit 237a5ae
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-10-31 16:40:34 UTC using RuboCop version 1.66.1.
# on 2025-02-03 12:44:50 UTC using RuboCop version 1.66.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -90,7 +90,7 @@ Naming/VariableNumber:
RSpec/AnyInstance:
Enabled: false

# Offense count: 157
# Offense count: 165
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand Down Expand Up @@ -190,10 +190,10 @@ RSpec/MessageSpies:
RSpec/MultipleExpectations:
Max: 10

# Offense count: 52
# Offense count: 75
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 13
Max: 15

# Offense count: 13
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
Expand All @@ -204,7 +204,7 @@ RSpec/NamedSubject:
- 'spec/api/endpoints/teams_endpoint_spec.rb'
- 'spec/slack-sup/app_spec.rb'

# Offense count: 72
# Offense count: 82
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 6
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Changelog

* 2025/02/03: Fix: S'Up runs on time a week after being delayed - [@dblock](https://github.com/dblock).
* 2024/10/31: Fix: subscribe and change cc for teams with special characters in name - [@dblock](https://github.com/dblock).
* 2024/10/27: Replaced gcal link by a button - [@dblock](https://github.com/dblock).
* 2024/10/27: Added collections of missed and matched users to rounds API - [@dblock](https://github.com/dblock).
Expand Down
7 changes: 4 additions & 3 deletions slack-sup/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ def sup?
# only sup on a certain day of the week
now_in_tz = Time.now.utc.in_time_zone(sup_tzone)
return false unless now_in_tz.wday == sup_wday
# sup after 9am by default

# sup after sup_time_of_day, 9am by default
return false if now_in_tz < now_in_tz.beginning_of_day + sup_time_of_day

# don't sup more than once a week
time_limit = Time.now.utc - sup_every_n_weeks.weeks
# don't sup more than sup_every_n_weeks, once a week by default
time_limit = now_in_tz.end_of_day - sup_every_n_weeks.weeks
(last_round_at || time_limit) <= time_limit
end

Expand Down
112 changes: 104 additions & 8 deletions spec/models/team_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@
context 'team' do
let(:tz) { 'Eastern Time (US & Canada)' }
let(:t_in_time_zone) { Time.now.utc.in_time_zone(tz) }
let(:eight_am) { 8 * 60 * 60 }
let(:wday) { t_in_time_zone.wday }
let(:beginning_of_day) { t_in_time_zone.beginning_of_day }
let(:team) { Fabricate(:team, sup_wday: wday, sup_time_of_day: 0, sup_tz: tz) }
let(:team) { Fabricate(:team, sup_wday: wday, sup_time_of_day: eight_am, sup_tz: tz) }
let(:on_time_sup) { beginning_of_day + team.sup_time_of_day }

describe '#sync!' do
let(:member_default_attr) do
Expand Down Expand Up @@ -353,7 +355,7 @@

describe '#sup?' do
before do
Timecop.travel(beginning_of_day + (8 * 60 * 60))
Timecop.travel(on_time_sup)
allow(team).to receive(:sync!)
end

Expand All @@ -363,7 +365,7 @@
end
end

context 'with a round' do
context 'with a round on time' do
before do
team.sup!
end
Expand All @@ -374,7 +376,7 @@

context 'after less than a week' do
before do
Timecop.travel(Time.now.utc + 6.days)
Timecop.travel(on_time_sup + 6.days)
end

it 'is false' do
Expand All @@ -384,7 +386,101 @@

context 'after more than a week' do
before do
Timecop.travel(Time.now.utc + 7.days)
Timecop.travel(on_time_sup + 7.days)
end

it 'is true' do
expect(team.sup?).to be true
end

context 'and another round' do
before do
team.sup!
end

it 'is false' do
expect(team.sup?).to be false
end
end
end

context 'with a custom sup_every_n_weeks' do
before do
team.update_attributes!(sup_every_n_weeks: 2)
end

context 'after more than a week' do
before do
Timecop.travel(on_time_sup + 7.days)
end

it 'is true' do
expect(team.sup?).to be false
end
end

context 'after more than two weeks' do
before do
Timecop.travel(on_time_sup + 14.days)
end

it 'is true' do
expect(team.sup?).to be true
end
end
end

context 'after more than a week on the wrong day of the week' do
before do
Timecop.travel(on_time_sup + 8.days)
end

it 'is false' do
expect(team.sup?).to be false
end
end
end

context 'with a round delayed by an hour' do
before do
Timecop.freeze(on_time_sup + 1.hour) do
team.sup!
end
end

context 'after less than a week' do
before do
Timecop.travel(on_time_sup + 6.days)
end

it 'is false' do
expect(team.sup?).to be false
end
end

context 'before sup time a week later' do
before do
Timecop.travel(on_time_sup + 7.days - 1.hour)
end

it 'is false' do
expect(team.sup?).to be false
end
end

context 'on time a week later' do
before do
Timecop.travel(on_time_sup + 7.days)
end

it 'is true' do
expect(team.sup?).to be true
end
end

context 'after more than a week' do
before do
Timecop.travel(on_time_sup + 7.days + 1.hour)
end

it 'is true' do
Expand All @@ -409,7 +505,7 @@

context 'after more than a week' do
before do
Timecop.travel(Time.now.utc + 7.days)
Timecop.travel(on_time_sup + 7.days)
end

it 'is true' do
Expand All @@ -419,7 +515,7 @@

context 'after more than two weeks' do
before do
Timecop.travel(Time.now.utc + 14.days)
Timecop.travel(on_time_sup + 14.days)
end

it 'is true' do
Expand All @@ -430,7 +526,7 @@

context 'after more than a week on the wrong day of the week' do
before do
Timecop.travel(Time.now.utc + 8.days)
Timecop.travel(on_time_sup + 8.days)
end

it 'is false' do
Expand Down

0 comments on commit 237a5ae

Please sign in to comment.