Skip to content

Commit

Permalink
Merge pull request #7990 from fjordllc/chore/truncate-qa-title-in-tit…
Browse files Browse the repository at this point in the history
…le-tag-logged-in

ログイン時のQ&A個別ページのtitleタグの文字数を制限
  • Loading branch information
komagata authored Aug 21, 2024
2 parents ceb3a2b + 2cc56bc commit c4519c7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/views/questions/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- title "Q&A: #{@question.title}"
- title "Q&A: #{truncate(@question.title, length: 35, omission: '...')}"
- set_meta_tags og: { title: "Q&A: #{@question.title}" }
- if @question.practice
- set_meta_tags description: "#{@question.user.long_name}さんが投稿した、プラクティス「#{@question.practice.title}」に関する質問「#{@question.title}」のページです。"
- else
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/questions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,11 @@ question15:
practice: practice12
created_at: "2022-01-17"
published_at: "2022-01-17"

question16:
title: 長いタイトルの質問長いタイトルの質問長いタイトルの質問長いタイトルの質問
description: タイトルが長い質問のtitleタグの文字数が制限されるかテストするための質問
user: kimura
practice: practice1
created_at: "2022-01-18"
published_at: "2022-01-18"
4 changes: 2 additions & 2 deletions test/system/practices_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ def wait_for_status_change
test 'add all questions to questions tab on practices page and display all questions default' do
practice = practices(:practice1)
visit_with_auth "/practices/#{practice.id}/questions", 'komagata'
assert_text '質問 (11)'
assert_text '質問 (12)'
assert_text '全ての質問'
assert_text '解決済み'
assert_text '未解決'
assert_equal practice.questions.length, 11
assert_equal practice.questions.length, 12
end

test 'show common description on each page' do
Expand Down
18 changes: 17 additions & 1 deletion test/system/questions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,23 @@ class QuestionsTest < ApplicationSystemTestCase
test 'show a question' do
question = questions(:question8)
visit_with_auth question_path(question), 'kimura'
assert_equal 'Q&A: テストの質問 | FBC', title
assert_equal 'Q&A: テストの質問 | FBC', title
end

test 'title of the title tag is truncated' do
question = questions(:question16)
visit_with_auth question_path(question), 'kimura'
assert_selector 'title', text: 'Q&A: 長いタイトルの質問長いタイトルの質問長いタイトルの質問長いタイト... | FBC', visible: false
end

test 'titles in og:title, og:description, twitter:description tags is not truncated' do
question = questions(:question16)
visit_with_auth question_path(question), 'kimura'
meta_title = '長いタイトルの質問長いタイトルの質問長いタイトルの質問長いタイトルの質問'
meta_description = "kimura (キムラ タダシ)さんが投稿した、プラクティス「OS X Mountain Lionをクリーンインストールする」に関する質問「#{meta_title}」のページです。"
assert_selector "meta[property='og:title'][content='Q&A: #{meta_title}']", visible: false
assert_selector "meta[property='og:description'][content='#{meta_description}']", visible: false
assert_selector "meta[name='twitter:description'][content='#{meta_description}']", visible: false
end

test 'create a question' do
Expand Down

0 comments on commit c4519c7

Please sign in to comment.