Skip to content

Commit

Permalink
Fix #23 that forced the bot name into the expression being evaluated.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Oct 29, 2015
1 parent 1be66e7 commit a0d61f9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
12 changes: 8 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-09-23 08:45:19 -0400 using RuboCop version 0.32.1.
# on 2015-10-28 17:37:44 -0700 using RuboCop version 0.32.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 All @@ -13,15 +13,15 @@ Lint/HandleExceptions:
Lint/UselessAccessModifier:
Enabled: false

# Offense count: 4
# Offense count: 5
Metrics/AbcSize:
Max: 23

# Offense count: 1
# Offense count: 2
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 85
# Offense count: 91
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 142
Expand All @@ -31,6 +31,10 @@ Metrics/LineLength:
Metrics/MethodLength:
Max: 21

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 15
Style/Documentation:
Enabled: false
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.4.5 (Next)

* [#23](https://github.com/dblock/slack-ruby-bot/pull/23): Fixed `match` that forced bot name into the expression being evaluated - [@dblock](https://github.com/dblock).
* [#22](https://github.com/dblock/slack-ruby-bot/issues/22), [slack-ruby-client#17](https://github.com/dblock/slack-ruby-client/issues/17): Do not respond to messages from self, override with `allow_message_loops` - [@dblock](https://github.com/dblock).
* Your contribution here.

Expand Down
5 changes: 3 additions & 2 deletions lib/slack-ruby-bot/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def self.command(*values, &block)

def self.invoke(client, data)
self.finalize_routes!
expression = parse(data)
expression, text = parse(data)
called = false
routes.each_pair do |route, method|
match = route.match(expression)
match ||= route.match(text) if text
next unless match
next if match.names.include?('bot') && !SlackRubyBot.config.name?(match['bot'])
called = true
Expand Down Expand Up @@ -88,7 +89,7 @@ def self.parse(data)
return text if td == name || td.starts_with?("#{name} ")
end
end
"#{SlackRubyBot.config.user} #{text}"
["#{SlackRubyBot.config.user} #{text}", text]
end

def self.finalize_routes!
Expand Down
17 changes: 17 additions & 0 deletions spec/slack-ruby-bot/commands/match_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe SlackRubyBot::Commands do
let! :command do
Class.new(SlackRubyBot::Commands::Base) do
match(/^Reticulate (?<spline_name>\w*)$/) do |client, data, match|
send_message client, data.channel, "Reticulated #{match[:spline_name]}."
end
end
end
def app
SlackRubyBot::App.new
end
it 'matches' do
expect(message: 'Reticulate spline').to respond_with_slack_message('Reticulated spline.')
end
end

0 comments on commit a0d61f9

Please sign in to comment.