Display group rules correctly in slash commands

This commit is contained in:
David Taylor 2017-08-01 19:16:47 +01:00
parent c06a4aa4f6
commit 01d7fb47ef
3 changed files with 24 additions and 8 deletions

View File

@ -82,14 +82,25 @@ module DiscourseChat
i = 1
rules.each do |rule|
category_id = rule.category_id
if category_id.nil?
category_name = I18n.t("chat_integration.all_categories")
else
category = Category.find_by(id: category_id)
if category
category_name = category.slug
case rule.type
when "normal"
if category_id.nil?
category_name = I18n.t("chat_integration.all_categories")
else
category_name = I18n.t("chat_integration.deleted_category")
category = Category.find_by(id: category_id)
if category
category_name = category.slug
else
category_name = I18n.t("chat_integration.deleted_category")
end
end
when "group_mention", "group_message"
group = Group.find_by(id: rule.group_id)
if group
category_name = I18n.t("chat_integration.#{rule.type}_template", name: group.name)
else
category_name = I18n.t("chat_integration.deleted_group")
end
end

View File

@ -62,6 +62,9 @@ en:
deleted_category: "(deleted category)"
deleted_group: "(deleted group)"
group_mention_template: "mentions of: @%{name}"
group_message_template: "messages to: @%{name}"
provider:
#######################################

View File

@ -152,16 +152,18 @@ RSpec.describe DiscourseChat::Manager do
end
context 'with some rules' do
let(:group){Fabricate(:group)}
before do
DiscourseChat::Rule.create!(channel: chan1, filter:'watch', category_id:category.id, tags:nil)
DiscourseChat::Rule.create!(channel: chan1, filter:'mute', category_id:nil, tags:nil)
DiscourseChat::Rule.create!(channel: chan1, filter:'follow', category_id:nil, tags:[tag1.name])
DiscourseChat::Rule.create!(channel: chan1, filter:'watch', type: 'group_message', group_id:group.id)
DiscourseChat::Rule.create!(channel: chan2, filter:'watch', category_id:1, tags:nil)
end
it 'displays the correct rules' do
string = DiscourseChat::Helper.status_for_channel(chan1)
expect(string.scan('status.rule_string').size).to eq(3)
expect(string.scan('status.rule_string').size).to eq(4)
end
it 'only displays tags for rules with tags' do