From d80aca048424e43ada26ee097c63c4171683b6c6 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 22 Dec 2017 15:46:46 +0800 Subject: [PATCH] FIX: Don't start discobot poll tutorial if polls are disabled. https://meta.discourse.org/t/discobot-dont-take-users-through-the-poll-tutorial-if-its-not-enabled/76604/3 --- .../advanced_user_narrative.rb | 1 + .../advanced_user_narrative_spec.rb | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb index b5fbe5bc732..a503392f95b 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb @@ -80,6 +80,7 @@ module DiscourseNarrativeBot }, tutorial_poll: { + prerequisite: Proc.new { SiteSetting.poll_enabled }, next_state: :tutorial_details, next_instructions: Proc.new { I18n.t("#{I18N_KEY}.details.instructions", i18n_post_args) }, reply: { diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb index c7ae6820614..81f0e011558 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb @@ -542,6 +542,29 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_poll) end end + + describe 'when poll is disabled' do + before do + SiteSetting.poll_enabled = false + end + + it 'should create the right reply' do + TopicUser.change( + user.id, + topic.id, + notification_level: TopicUser.notification_levels[:tracking] + ) + + expected_raw = <<~RAW + #{I18n.t('discourse_narrative_bot.advanced_user_narrative.change_topic_notification_level.reply', base_uri: '')} + + #{I18n.t('discourse_narrative_bot.advanced_user_narrative.details.instructions', base_uri: '')} + RAW + + expect(Post.last.raw).to eq(expected_raw.chomp) + expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_details) + end + end end context 'poll tutorial' do