Set og:image:alt OpenGraph property

This commit is contained in:
Anton Khorev 2024-08-02 18:48:04 +03:00
parent 69a2d5f4d4
commit 243557a31a
4 changed files with 47 additions and 7 deletions

View file

@ -657,6 +657,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
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
@ -668,6 +671,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
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
@ -679,6 +685,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
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
@ -690,6 +699,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
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
@ -701,6 +713,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
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
@ -712,6 +727,21 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
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_hide