Skip to content

Commit

Permalink
Fix #68: matches was displaying matches from other teams.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Dec 30, 2015
1 parent 457fa74 commit 5890e9a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
6 changes: 3 additions & 3 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 2015-12-30 16:25:29 -0700 using RuboCop version 0.34.2.
# on 2015-12-30 16:45:17 -0700 using RuboCop version 0.34.2.
# 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 @@ -46,10 +46,10 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 12

# Offense count: 409
# Offense count: 415
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 193
Max: 195

# Offense count: 27
# Configuration parameters: CountComments.
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

* [#68](https://github.com/dblock/slack-gamebot/issues/68): Fix: `matches` was displaying matches from other teams - [@dblock](https://github.com/dblock).
* [#69](https://github.com/dblock/slack-gamebot/issues/69): Allow storing and scoring ties - [@dblock](https://github.com/dblock).
* [#58](https://github.com/dblock/slack-gamebot/issues/58): Automatically purge teams inactive for two weeks - [@dblock](https://github.com/dblock).
* [#66](https://github.com/dblock/slack-gamebot/issues/66): Added `script/console` - [@dblock](https://github.com/dblock).
Expand Down
9 changes: 5 additions & 4 deletions slack-gamebot/commands/matches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ def self.call(client, data, match)
totals = {}
totals.default = 0
arguments = match['expression'].split.reject(&:blank?) if match.names.include?('expression')
users = ::User.find_many_by_slack_mention!(client.team, arguments) if arguments && arguments.any?
team = client.team
users = ::User.find_many_by_slack_mention!(team, arguments) if arguments && arguments.any?
user_ids = users.map(&:id) if users && users.any?
matches = user_ids && user_ids.any? ? ::Match.any_of({ :winner_ids.in => user_ids }, :loser_ids.in => user_ids) : ::Match.all
matches = matches.where(:challenge_id.in => ::Challenge.current.pluck(:_id))
matches = user_ids && user_ids.any? ? team.matches.any_of({ :winner_ids.in => user_ids }, :loser_ids.in => user_ids) : team.matches
matches = matches.where(:challenge_id.in => team.challenges.current.pluck(:_id))
matches.includes(:challenge).each do |m|
next if m.challenge.season_id
totals[m.to_s] += 1
Expand All @@ -24,7 +25,7 @@ def self.call(client, data, match)
end
end.join("\n")
send_message client, data.channel, message
logger.info "MATCHES: #{client.team} - #{data.user}"
logger.info "MATCHES: #{team} - #{data.user}"
end
end
end
Expand Down
43 changes: 43 additions & 0 deletions spec/slack-gamebot/commands/matches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
"#{match1} 3 times"
)
end
context 'with another team' do
let!(:team2) { Fabricate(:team) }
let!(:team2_match) { Fabricate(:match, team: team2) }
it 'displays only matches for requested users' do
expect(message: "#{SlackRubyBot.config.user} matches #{match1.challenge.challenged.first.user_name}", user: user.user_id, channel: match1.challenge.channel).to respond_with_slack_message(
"#{match1} 3 times"
)
end
end
end
context 'with a doubles match' do
let!(:match) { Fabricate(:match, challenge: doubles_challenge) }
Expand All @@ -30,6 +39,15 @@
"#{match} once"
)
end
context 'with another team' do
let!(:team2) { Fabricate(:team) }
let!(:team2_match) { Fabricate(:match, team: team2) }
it 'displays user matches' do
expect(message: "#{SlackRubyBot.config.user} matches", user: user.user_id, channel: match.challenge.channel).to respond_with_slack_message(
"#{match} once"
)
end
end
end
context 'with a singles match' do
let!(:match) { Fabricate(:match, challenge: singles_challenge) }
Expand All @@ -38,11 +56,27 @@
"#{match} once"
)
end
context 'with another team' do
let!(:team2) { Fabricate(:team) }
let!(:team2_match) { Fabricate(:match, team: team2) }
it 'displays user matches' do
expect(message: "#{SlackRubyBot.config.user} matches", user: user.user_id, channel: match.challenge.channel).to respond_with_slack_message(
"#{match} once"
)
end
end
end
context 'without matches' do
it 'displays' do
expect(message: "#{SlackRubyBot.config.user} matches", user: user.user_id, channel: 'channel').to respond_with_slack_message('Nothing to see here.')
end
context 'with another team' do
let!(:team2) { Fabricate(:team) }
let!(:team2_match) { Fabricate(:match, team: team2) }
it 'displays matches for team 1' do
expect(message: "#{SlackRubyBot.config.user} matches", user: user.user_id, channel: 'channel').to respond_with_slack_message('Nothing to see here.')
end
end
end
context 'matches in prior seasons' do
let!(:match1) { Fabricate(:match, challenge: singles_challenge) }
Expand All @@ -54,5 +88,14 @@
"#{match2} once"
)
end
context 'with another team' do
let!(:team2) { Fabricate(:team) }
let!(:team2_match) { Fabricate(:match, team: team2) }
it 'displays user matches in current season only' do
expect(message: "#{SlackRubyBot.config.user} matches", user: user.user_id, channel: match2.challenge.channel).to respond_with_slack_message(
"#{match2} once"
)
end
end
end
end

0 comments on commit 5890e9a

Please sign in to comment.