Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/models/posting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def article_with_image
return "#{figure_start}_#{figure_end}" if figure_start.nil? || figure_end.nil?

image_tags = body[figure_start...figure_end + 9]
# Avoid using magic numbers. 9 should be a constant with explanatory name
return 'not include <img' unless image_tags.include?('<img')

posting_image_params(image_tags)
Expand All @@ -26,9 +27,14 @@ def posting_image_params(html)
data = tag_parse.(html, attribute)
unless data.nil?
tag_attributes[attribute] = data[1] unless data.size < 2
# Avoid using magic numbers. 2 should be a constant with explanatory name
end
end
# tag_parse
tag_attributes
end
end
end

# In case if article contains the image, its snippet should contain image above the body -- was implemented.

# Doesn't handle the case when article has multiple images
6 changes: 5 additions & 1 deletion specs/posting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
expect(posting.article_with_image).to eq(response)
end
end
end
end

# missing case when posting body has no figure tag
# missing case when posting body has no image tag
# would be great to have test for covering the case of multiple images in the posting