Skip to content

Commit

Permalink
Fix: allow help statements from classes that do not directly inherit …
Browse files Browse the repository at this point in the history
…from Base classes to appear in `bot help`
  • Loading branch information
maclover7 authored and dblock committed Sep 24, 2016
1 parent 3259141 commit 2fb9790
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ Style/FileName:
# Offense count: 1
Style/ModuleFunction:
Enabled: false

# Offense count: 1
Style/StringLiterals:
Enabled: false
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [#95](https://github.com/slack-ruby/slack-ruby-bot/pull/95): Log team name and ID on successful connection - [@dblock](https://github.com/dblock).
* [#94](https://github.com/slack-ruby/slack-ruby-bot/pull/94): Use the slack-ruby-danger gem - [@dblock](https://github.com/dblock).
* Your contribution here.
* [#86](https://github.com/dblock/slack-ruby-bot/pull/86): Fix: allow help statements from classes that do not directly inherit from Base classes to appear in `bot help` - [@maclover7](https://github.com/maclover7).

### 0.9.0 (8/29/2016)

Expand Down
4 changes: 2 additions & 2 deletions lib/slack-ruby-bot/support/commands_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def help_attrs_with_present_names(help_attrs)
end

def bot_help_attrs
commands_help_attrs.select { |k| k.class_name.constantize.superclass == SlackRubyBot::Bot }
commands_help_attrs.select { |k| k.class_name.constantize.ancestors.include?(SlackRubyBot::Bot) }
end

def other_commands_help_attrs
commands_help_attrs.select { |k| k.class_name.constantize.superclass == SlackRubyBot::Commands::Base }
commands_help_attrs.select { |k| k.class_name.constantize.ancestors.include?(SlackRubyBot::Commands::Base) }
end
end
end
26 changes: 26 additions & 0 deletions spec/slack-ruby-bot/support/commands_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,41 @@
it 'do not show description for command without description' do
expect(bot_desc).to include("*command_without_description*\n")
end

class AnotherBotBase < SlackRubyBot::Bot
end

class AnotherBot < AnotherBotBase
help do
title 'Creating your own base class works too!'
end
end

it 'includes commands who do not directly inherit from the provided base class' do
expect(commands_helper.bot_desc_and_commands).to include("*Creating your own base class works too!*\n\n*Commands:*\n")
end
end

describe '#other_commands_descs' do
class AnotherCommandBase < SlackRubyBot::Commands::Base
end

class AnotherCommand < AnotherCommandBase
help do
title 'Creating your own base class works too!'
end
end

let(:commands_desc) { commands_helper.other_commands_descs }
let(:hello_command_desc) { commands_desc.find { |desc| desc =~ /\*hello\*/ } }

it 'returns command name and description' do
expect(hello_command_desc).to eq('*hello* - Says hello.')
end

it 'includes commands who do not directly inherit from provided base class' do
expect(commands_desc).to include('*Creating your own base class works too!*')
end
end

describe '#command_full_desc' do
Expand Down

0 comments on commit 2fb9790

Please sign in to comment.