-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from alexagranov/no_mongoid_exception_on_activ…
…erecord remove one more Mongoid dependency when rescuing from _invoke
- Loading branch information
Showing
7 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
lib/slack-ruby-bot-server/ext/activerecord/slack-ruby-bot/commands/base.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module SlackRubyBot | ||
module Commands | ||
class Base | ||
class << self | ||
alias _invoke invoke | ||
|
||
def invoke(client, data) | ||
_invoke client, data | ||
rescue StandardError => e | ||
logger.info "#{name.demodulize.upcase}: #{client.owner}, #{e.class}: #{e}" | ||
client.say(channel: data.channel, text: e.message, gif: 'error') | ||
true | ||
end | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
%w(client commands/base).each do |ext| | ||
require_relative "slack-ruby-bot/#{ext}" | ||
end | ||
require_relative 'slack-ruby-bot/client' | ||
require_relative "#{SlackRubyBotServer::Config.database_adapter}/slack-ruby-bot/commands/base" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
describe SlackRubyBot::Commands::Base do | ||
let(:client) { SlackRubyBot::Client.new } | ||
let(:message_hook) { SlackRubyBot::Hooks::Message.new } | ||
|
||
context 'exception handling' do | ||
context 'StandardError' do | ||
before do | ||
allow(SlackRubyBot::Commands::Base).to receive(:_invoke).and_raise('mock error') | ||
end | ||
|
||
it 'responds to channel with exception message' do | ||
expect(client).to receive(:say).with(channel: 'channel', text: 'mock error', gif: 'error') | ||
message_hook.call(client, Hashie::Mash.new(text: 'raising exception', channel: 'channel', user: 'user')) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
|
||
describe SlackRubyBot::Commands::Base do | ||
let(:client) { SlackRubyBot::Client.new } | ||
let(:message_hook) { SlackRubyBot::Hooks::Message.new } | ||
|
||
context 'exception handling' do | ||
context 'StandardError' do | ||
before do | ||
allow(SlackRubyBot::Commands::Base).to receive(:_invoke).and_raise('mock error') | ||
end | ||
|
||
it 'responds to channel with exception message' do | ||
expect(client).to receive(:say).with(channel: 'channel', text: 'mock error', gif: 'error') | ||
message_hook.call(client, Hashie::Mash.new(text: 'raising exception', channel: 'channel', user: 'user')) | ||
end | ||
end | ||
|
||
context 'Mongoid::Errors::Validations' do | ||
class MockDocument | ||
include Mongoid::Document | ||
validates_presence_of :mock_id | ||
end | ||
let(:mock_document) { MockDocument.new } | ||
|
||
before do | ||
allow(SlackRubyBot::Commands::Base).to receive(:_invoke) { mock_document.save! } | ||
end | ||
|
||
it 'responds to channel with exception message' do | ||
expect(client).to receive(:say).with(channel: 'channel', text: "undefined method `mock_id' for #{mock_document.inspect}", gif: 'error') | ||
message_hook.call(client, Hashie::Mash.new(text: 'raising exception', channel: 'channel', user: 'user')) | ||
end | ||
end | ||
end | ||
end |