From 82351a790c47ad5459593c1311087cf8d2c92920 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 7 Aug 2019 16:59:34 -0400 Subject: [PATCH] FIX: An error would be raised if fewer than "skip_messages" existed --- lib/discourse_chat/provider/slack/slack_transcript.rb | 1 + .../discourse_chat/provider/slack/slack_transcript_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/discourse_chat/provider/slack/slack_transcript.rb b/lib/discourse_chat/provider/slack/slack_transcript.rb index ed32619..a69c6a1 100644 --- a/lib/discourse_chat/provider/slack/slack_transcript.rb +++ b/lib/discourse_chat/provider/slack/slack_transcript.rb @@ -34,6 +34,7 @@ module DiscourseChat::Provider::SlackProvider # Apply a heuristic to decide which is the first message in the current conversation def guess_first_message(skip_messages: 5) # Can skip the last n messages return true if @requested_thread_ts # Always start thread on first message + return false if @messages.blank? || @messages.size < skip_messages possible_first_messages = @messages[0..-skip_messages] diff --git a/spec/lib/discourse_chat/provider/slack/slack_transcript_spec.rb b/spec/lib/discourse_chat/provider/slack/slack_transcript_spec.rb index 83d5107..36e0545 100644 --- a/spec/lib/discourse_chat/provider/slack/slack_transcript_spec.rb +++ b/spec/lib/discourse_chat/provider/slack/slack_transcript_spec.rb @@ -96,6 +96,11 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do SiteSetting.chat_integration_slack_access_token = "abcde" end + it "doesn't raise an error when there are no messages to guess" do + transcript.instance_variable_set(:@messages, []) + expect(transcript.guess_first_message(skip_messages: 1)).to eq(false) + end + describe 'loading users' do it 'loads users correctly' do stub_request(:post, "https://slack.com/api/users.list")