+ def test_show_og_title
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :title => "The Important Blog Post")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:title']" do
+ assert_dom "> @content", "The Important Blog Post"
+ end
+ end
+
+ def test_show_og_image_with_no_image
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "nothing")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:image']" do
+ assert_dom "> @content", ActionController::Base.helpers.image_url("osm_logo_256.png", :host => root_url)
+ end
+ assert_dom "head meta[property='og:image:alt']" do
+ assert_dom "> @content", "OpenStreetMap logo"
+ end
+ end
+
+ def test_show_og_image
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "![some picture](https://example.com/picture.jpg)")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:image']" do
+ assert_dom "> @content", "https://example.com/picture.jpg"
+ end
+ assert_dom "head meta[property='og:image:alt']" do
+ assert_dom "> @content", "some picture"
+ end
+ end
+
+ def test_show_og_image_with_relative_uri
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "![some local picture](/picture.jpg)")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:image']" do
+ assert_dom "> @content", "#{root_url}picture.jpg"
+ end
+ assert_dom "head meta[property='og:image:alt']" do
+ assert_dom "> @content", "some local picture"
+ end
+ end
+
+ def test_show_og_image_with_spaces
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "![some picture](https://example.com/the picture.jpg)")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:image']" do
+ assert_dom "> @content", "https://example.com/the%20picture.jpg"
+ end
+ assert_dom "head meta[property='og:image:alt']" do
+ assert_dom "> @content", "some picture"
+ end
+ end
+
+ def test_show_og_image_with_relative_uri_and_spaces
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "![some local picture](/the picture.jpg)")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:image']" do
+ assert_dom "> @content", "#{root_url}the%20picture.jpg"
+ end
+ assert_dom "head meta[property='og:image:alt']" do
+ assert_dom "> @content", "some local picture"
+ end
+ end
+
+ def test_show_og_image_with_invalid_uri
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "![](:)")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:image']" do
+ assert_dom "> @content", ActionController::Base.helpers.image_url("osm_logo_256.png", :host => root_url)
+ end
+ assert_dom "head meta[property='og:image:alt']" do
+ assert_dom "> @content", "OpenStreetMap logo"
+ end
+ end
+
+ def test_show_og_image_without_alt
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "<img src='https://example.com/no_alt.gif'>")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:image']" do
+ assert_dom "> @content", "https://example.com/no_alt.gif"
+ end
+ assert_dom "head meta[property='og:image:alt']", :count => 0
+ end
+
+ def test_show_no_og_description
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "![nope](https://example.com/nope.jpg)")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:description']" do
+ assert_dom "> @content", I18n.t("layouts.intro_text")
+ end
+ end
+
+ def test_show_og_description
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :body => "# Hello\n\n![hello](https://example.com/hello.jpg)\n\nFirst paragraph.\n\nSecond paragraph.")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='og:description']" do
+ assert_dom "> @content", "First paragraph."
+ end
+ end
+
+ def test_show_article_published_time
+ user = create(:user)
+ diary_entry = create(:diary_entry, :user => user, :created_at => "2020-03-04")
+
+ get diary_entry_path(user, diary_entry)
+ assert_response :success
+ assert_dom "head meta[property='article:published_time']" do
+ assert_dom "> @content", "2020-03-04T00:00:00Z"
+ end
+ end
+