Skip to content

Commit

Permalink
fix(slack): hide slack link button in setup when linked (#714)
Browse files Browse the repository at this point in the history
* fix(slack): hide slack link button in setup when linked

* fix: specs
  • Loading branch information
wJoenn authored Dec 1, 2024
1 parent 4daf326 commit 86cad0a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/jobs/buddies/generate_daily_pairs_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def perform(day)
private

def retrieve_users_with_slack_linked
@user_ids = User.slack_linked.order(:id).pluck(:id)
@user_ids = User.slack_linked.where(synced: true).order(:id).pluck(:id)
end

def handle_odd_number_of_users
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class User < ApplicationRecord
scope :admins, -> { where_roles(:admin) }
scope :confirmed, -> { where(accepted_coc: true, synced: true).where.not(aoc_id: nil) }
scope :insanity, -> { where(entered_hardcore: true) } # All users are 'hardcore' since 2024 edition
scope :slack_linked, -> { where(synced: true).where.not(slack_id: nil) }
scope :slack_linked, -> { where.not(slack_id: nil) }

def self.from_kitt(auth)
original_batch = auth.info.schoolings&.min_by { |batch| batch.camp.starts_at }
Expand All @@ -68,7 +68,7 @@ def confirmed?
end

def slack_linked?
synced && slack_id.present?
slack_id.present?
end

def slack_link
Expand Down
8 changes: 2 additions & 6 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,14 @@

describe "Slack linking scope" do
it "ensures slack_linked scope and slack_linked? method are in sync" do
user_with_slack = create(:user, slack_id: "ABC123", synced: true)
user_without_slack = create(:user, slack_id: nil, synced: true)
user_with_unsynced_slack = create(:user, slack_id: "DEF456", synced: false)
user_with_slack = create(:user, slack_id: "ABC123")
user_without_slack = create(:user, slack_id: nil)

expect(User.slack_linked).to include(user_with_slack)
expect(user_with_slack.slack_linked?).to be true

expect(User.slack_linked).not_to include(user_without_slack)
expect(user_without_slack.slack_linked?).to be false

expect(User.slack_linked).not_to include(user_with_unsynced_slack)
expect(user_with_unsynced_slack.slack_linked?).to be false
end
end

Expand Down

0 comments on commit 86cad0a

Please sign in to comment.