Skip to content

Commit b9bb70b

Browse files
committed
🎨 /news ページでもformat_news_titleヘルパーを使用
- ホームページの#newsセクションと同じようにニュースタイトルを表示 - プリセット絵文字の自動追加機能を適用 - テストを更新して絵文字追加に対応
1 parent 738bc76 commit b9bb70b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

app/controllers/news_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ def index
33
@title = 'CoderDojo ニュース'
44
@desc = 'CoderDojo に関する最新のニュースや<br class="ignore-pc">お知らせをまとめたページです。'
55
@url = request.url
6-
6+
77
# データベースからニュースデータを取得(最新順)
88
@news_items = News.recent
99
end
10-
end
10+
end

app/views/news/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<% @news_items.each do |news| %>
1717
<article class="news-item" style="margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid #e0e0e0;">
1818
<h3 style="margin-bottom: 10px;">
19-
<%= link_to news.title, news.url, target: '_blank', rel: 'noopener' %>
19+
<%= link_to format_news_title(news), news.url, target: '_blank', rel: 'noopener' %>
2020
</h3>
2121
<p class="news-meta" style="color: #666; font-size: 14px;">
2222
<i class="fa fa-calendar"></i>

spec/requests/news_spec.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
get news_index_path
3636

3737
# 新しい順に表示されることを確認
38-
news2_pos = response.body.index(@news2.title)
39-
news1_pos = response.body.index(@news1.title)
40-
news3_pos = response.body.index(@news3.title)
38+
# format_news_title によってプリセット絵文字が追加される可能性があるため、
39+
# タイトルの主要部分で位置を確認
40+
news2_pos = response.body.index("テストニュース2")
41+
news1_pos = response.body.index("テストニュース1")
42+
news3_pos = response.body.index("テストニュース3")
4143

4244
expect(news2_pos).to be < news1_pos
4345
expect(news1_pos).to be < news3_pos
@@ -46,9 +48,11 @@
4648
it "ニュースのタイトルとリンクを表示する" do
4749
get news_index_path
4850

49-
expect(response.body).to include(@news1.title)
51+
# format_news_title によってプリセット絵文字が追加される可能性があるため、
52+
# タイトルの主要部分が含まれていることを確認
53+
expect(response.body).to include("テストニュース1")
5054
expect(response.body).to include(@news1.url)
51-
expect(response.body).to include(@news2.title)
55+
expect(response.body).to include("テストニュース2")
5256
expect(response.body).to include(@news2.url)
5357
end
5458

0 commit comments

Comments
 (0)