Skip to content

Commit 89df488

Browse files
authored
Merge pull request #1776 from coderdojo-japan/add-donation-emoji
✉️ News タイトルに「寄贈」が含まれる場合は 🎁 絵文字を付与
2 parents 87d2f49 + 2bb368c commit 89df488

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

app/models/news.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ def formatted_title
1212
return title if has_custom_emoji
1313

1414
# Add preset Emoji to its prefix if title does not have Emoji.
15-
emoji = case url
16-
when %r{/podcasts/\d+}
15+
emoji = if url.match?(%r{/podcasts/\d+})
1716
'📻'
18-
when %r{prtimes\.jp}
17+
elsif url.match?(%r{prtimes\.jp})
1918
'📢'
19+
elsif title.include?('寄贈')
20+
'🎁'
2021
else
2122
'📰'
2223
end

spec/models/news_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
end
8585

8686
context '先頭文字が絵文字でない場合' do
87+
it 'タイトルに「寄贈」が含まれる場合は🎁を付与する' do
88+
news = build(:news, title: 'ノートPC 233台を寄贈しました', url: 'https://news.coderdojo.jp/2025/12/18/pc-donation')
89+
expect(news.formatted_title).to eq '🎁 ノートPC 233台を寄贈しました'
90+
end
91+
92+
it 'ポッドキャストURLはタイトルの「寄贈」より優先される' do
93+
news = build(:news, title: 'ポッドキャストで寄贈について話しました', url: 'https://coderdojo.jp/podcasts/50')
94+
expect(news.formatted_title).to eq '📻 ポッドキャストで寄贈について話しました'
95+
end
96+
8797
it 'ポッドキャストのURLには📻を付与する' do
8898
news = build(:news, title: 'エピソード33', url: 'https://coderdojo.jp/podcasts/33')
8999
expect(news.formatted_title).to eq '📻 エピソード33'

0 commit comments

Comments
 (0)