Skip to content

Commit

Permalink
Fix: disable club when removed from channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Nov 10, 2024
1 parent 2105ec2 commit 1bddd46
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 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-30 10:38:36 UTC using RuboCop version 1.67.0.
# on 2024-11-10 14:55:31 UTC using RuboCop version 1.67.0.
# 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 @@ -72,7 +72,7 @@ Naming/HeredocDelimiterNaming:
- 'slack-strava/info.rb'
- 'slack-strava/models/team.rb'

# Offense count: 15
# Offense count: 16
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Expand Down Expand Up @@ -185,7 +185,7 @@ RSpec/MessageChain:
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 203
# Offense count: 204
RSpec/MultipleExpectations:
Max: 11

Expand Down Expand Up @@ -356,7 +356,7 @@ Style/StringConcatenation:
- 'slack-strava/api/helpers/error_helpers.rb'
- 'slack-strava/models/team.rb'

# Offense count: 188
# Offense count: 189
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
8 changes: 8 additions & 0 deletions slack-strava/models/club.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def sync_strava_activities!(options = {})
logger.debug "Activity #{self}, team_id=#{team_id}, #{club_activity}"
club_activity
end
rescue Slack::Web::Api::Errors::NotInChannel => e
handle_slack_error e
rescue Faraday::ResourceNotFound => e
handle_not_found_error e
rescue Strava::Errors::Fault => e
Expand All @@ -172,6 +174,12 @@ def handle_not_found_error(e)
raise e
end

def handle_slack_error(e)
set sync_activities: false
logger.error e
raise e
end

def handle_strava_error(e)
logger.error e
case e.message
Expand Down
7 changes: 7 additions & 0 deletions spec/models/club_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@
expect(club.sync_activities?).to be false
end

it 'disables sync on not_in_channel' do
expect(club.sync_activities?).to be true
allow(club.strava_client).to receive(:club_activities).and_raise(Slack::Web::Api::Errors::NotInChannel.new('not_in_channel'))
expect { club.sync_last_strava_activity! }.to raise_error Slack::Web::Api::Errors::NotInChannel
expect(club.sync_activities?).to be false
end

context 'without a refresh token (until October 2019)', vcr: { cassette_name: 'strava/refresh_access_token' } do
before do
club.update_attributes!(refresh_token: nil, token_expires_at: nil)
Expand Down

0 comments on commit 1bddd46

Please sign in to comment.