Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/models/news.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def formatted_title
return title if has_custom_emoji

# Add preset Emoji to its prefix if title does not have Emoji.
emoji = case url
when %r{/podcasts/\d+}
emoji = if url.match?(%r{/podcasts/\d+})
'📻'
when %r{prtimes\.jp}
elsif url.match?(%r{prtimes\.jp})
'📢'
elsif title.include?('寄贈')
'🎁'
else
'📰'
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/news_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@
end

context '先頭文字が絵文字でない場合' do
it 'タイトルに「寄贈」が含まれる場合は🎁を付与する' do
news = build(:news, title: 'ノートPC 233台を寄贈しました', url: 'https://news.coderdojo.jp/2025/12/18/pc-donation')
expect(news.formatted_title).to eq '🎁 ノートPC 233台を寄贈しました'
end

it 'ポッドキャストURLはタイトルの「寄贈」より優先される' do
news = build(:news, title: 'ポッドキャストで寄贈について話しました', url: 'https://coderdojo.jp/podcasts/50')
expect(news.formatted_title).to eq '📻 ポッドキャストで寄贈について話しました'
end

it 'ポッドキャストのURLには📻を付与する' do
news = build(:news, title: 'エピソード33', url: 'https://coderdojo.jp/podcasts/33')
expect(news.formatted_title).to eq '📻 エピソード33'
Expand Down