FIX: Make Discobot image tutorial accept URL that points to images.

This commit is contained in:
Guo Xiang Tan 2018-11-15 10:51:17 +08:00
parent 6556a87629
commit 6fde58ff90
2 changed files with 11 additions and 3 deletions

View File

@ -302,7 +302,6 @@ module DiscourseNarrativeBot
post_topic_id = @post.topic_id
return unless valid_topic?(post_topic_id)
@post.post_analyzer.cook(@post.raw, {})
transition = true
attempted_count = get_state_data(:attempted) || 0
@ -313,7 +312,9 @@ module DiscourseNarrativeBot
@data[:skip_attempted] = false
end
if @post.post_analyzer.image_count > 0
cooked = @post.post_analyzer.cook(@post.raw, {})
if Nokogiri::HTML.fragment(cooked).css("img").size > 0
set_state_data(:post_id, @post.id)
if get_state_data(:liked)

View File

@ -434,12 +434,19 @@ describe DiscourseNarrativeBot::NewUserNarrative do
described_class.any_instance.expects(:enqueue_timeout_job).with(user)
url = "https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg"
stub_request(:head, url).to_return(
status: 200, body: file_from_fixtures("smallest.png").read
)
new_post = Fabricate(:post,
user: user,
topic: topic,
raw: "<img src='https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg'>"
raw: url
)
CookedPostProcessor.new(new_post).post_process
DiscourseNarrativeBot::TrackSelector.new(:reply, user, post_id: new_post.id).select
expected_raw = <<~RAW