]> git.openstreetmap.org Git - rails.git/commitdiff
Merge pull request #5056 from AntonKhorev/diary-og-description
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 14 Aug 2024 13:38:28 +0000 (14:38 +0100)
committerGitHub <noreply@github.com>
Wed, 14 Aug 2024 13:38:28 +0000 (14:38 +0100)
Set og:description meta tag to diary entry description

1  2 
test/controllers/diary_entries_controller_test.rb

index ced241a7f8456072532b3906986565831b070fec,1ea183400c2ea549f5bf629cd1b69c7e596ee21f..e98342e10a041d04cec90f4a05810a8ec63e23d7
@@@ -163,7 -163,7 +163,7 @@@ class DiaryEntriesControllerTest < Acti
                                                  :longitude => "2.2", :language_code => "en" })
      end
      assert_redirected_to :action => :index, :display_name => user.display_name
 -    entry = DiaryEntry.order(:id).last
 +    entry = DiaryEntry.last
      assert_equal user.id, entry.user_id
      assert_equal "New Title", entry.title
      assert_equal "This is a new body for the diary entry", entry.body
                                                  :longitude => "2.2", :language_code => "de" })
      end
      assert_redirected_to :action => :index, :display_name => user.display_name
 -    entry = DiaryEntry.order(:id).last
 +    entry = DiaryEntry.last
      assert_equal user.id, entry.user_id
      assert_equal "New Title", entry.title
      assert_equal "This is a new body for the diary entry", entry.body
                                :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" })
      end
      assert_redirected_to :action => :index, :display_name => user.display_name
 -    entry = DiaryEntry.order(:id).last
 +    entry = DiaryEntry.last
      assert_equal user.id, entry.user_id
      assert_equal spammy_title, entry.title
      assert_equal spammy_body, entry.body
      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_hide
      user = create(:user)
      diary_entry = create(:diary_entry, :user => user)