From e7822e00fd759b6171eab92781e59b086aefe377 Mon Sep 17 00:00:00 2001 From: computermacgyver Date: Wed, 28 Aug 2024 15:39:04 +0900 Subject: [PATCH] Working tests and return false not nil for no urls Actual ran tests locally :-) --- app/models/bot/smooch.rb | 2 +- test/models/bot/smooch_test.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/bot/smooch.rb b/app/models/bot/smooch.rb index 288f1036e..362a26ef7 100644 --- a/app/models/bot/smooch.rb +++ b/app/models/bot/smooch.rb @@ -546,7 +546,7 @@ def self.is_a_shortcut_for_submission?(state, message) self.is_v2? && (state == 'main' || state == 'waiting_for_message') && ( !message['mediaUrl'].blank? || ::Bot::Alegre.get_number_of_words(message['text'].to_s) > CheckConfig.get('min_number_of_words_for_tipline_submit_shortcut', 10, :integer) || - URI.regexp =~ message['text'].to_s # URL in message? + URI.regexp.match(message['text'].to_s)!=nil # URL in message? ) end diff --git a/test/models/bot/smooch_test.rb b/test/models/bot/smooch_test.rb index 17c0b04dc..ee1a0eef8 100644 --- a/test/models/bot/smooch_test.rb +++ b/test/models/bot/smooch_test.rb @@ -791,21 +791,21 @@ def teardown end test "should submit message for factchecking" do - Bot::Smooch.stubs(:is_v2?).returns{true} + Bot::Smooch.stubs(:is_v2?).returns(true) state='main' # Should not be a submission shortcut - message = {"text": "abc"} - assert_equal(false, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Unexpected shortcut") + message = {"text"=>"abc"} + assert_equal(false, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Unexpected shortcut") # Should be a submission shortcut - message = {"text": "abc http://example.com"} - assert_equal(true, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Missed URL shortcut") + message = {"text"=>"abc http://example.com"} + assert_equal(true, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Missed URL shortcut") # Should be a submission shortcut - message = {"text": "abc", "mediaUrl": "not blank"} - assert_equal(true, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Missed media shortcut") + message = {"text"=>"abc", "mediaUrl"=>"not blank"} + assert_equal(true, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Missed media shortcut") - Bot::Smooch.unstubs(:is_v2?) + Bot::Smooch.unstub(:is_v2?) end end