Skip to content

Commit

Permalink
Fix #8: undefined method strip!' for nil:NilClass on nil message.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jul 21, 2015
1 parent ba5fbd5 commit 87e00ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.3.1 (Next)

* [#8](https://github.com/dblock/slack-ruby-bot/issues/8): Fix: `undefined method `strip!' for nil:NilClass` on nil message - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.3.0 (7/19/2015)
Expand Down
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/hooks/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Message

def message(data)
data = Hashie::Mash.new(data)
data.text.strip!
data.text.strip! if data.text
result = child_command_classes.detect { |d| d.invoke(data) }
result ||= built_in_command_classes.detect { |d| d.invoke(data) }
result ||= SlackRubyBot::Commands::Unknown.tap { |d| d.invoke(data) }
Expand Down
21 changes: 21 additions & 0 deletions spec/slack-ruby-bot/commands/nil_message_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe SlackRubyBot::Commands do
let! :command do
Class.new(SlackRubyBot::Commands::Base) do
command 'nil_text'

def self.call(data, _match)
send_message data.channel, nil
end
end
end
def app
SlackRubyBot::App.new
end
it 'ignores nil messages' do
allow(Giphy).to receive(:random)
expect(SlackRubyBot::Commands::Base).to_not receive(:send_message_with_gif)
app.send(:message, text: nil, channel: 'channel', user: 'user')
end
end

0 comments on commit 87e00ac

Please sign in to comment.