Skip to content

Commit febc7fc

Browse files
authored
Merge pull request #1785 from coderdojo-japan/sync-shared-event-dates
同じイベントサービスを共有する道場の開催日を同期
2 parents ec7f4c6 + f8697c2 commit febc7fc

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

app/controllers/dojos_controller.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ def activity
143143
}
144144
end
145145

146+
# 同じイベントサービスを共有している道場の開催日を同期
147+
# 生駒 (ID: 36) と平群 (ID: 294) は奈良 (ID: 35) と同じ connpass を使用
148+
sync_event_date(36, 35) # 生駒は奈良の開催日を参照
149+
sync_event_date(294, 35) # 平群は奈良の開催日を参照
150+
146151
# アクティブな道場と非アクティブな道場を分けてソート
147152
active_dojos = @latest_event_by_dojos.select { |d| d[:is_active] }
148153
inactive_dojos = @latest_event_by_dojos.reject { |d| d[:is_active] }
@@ -165,6 +170,19 @@ def activity
165170

166171
private
167172

173+
# 指定された道場の開催日を別の道場の開催日と同期する
174+
# @param target_dojo_id [Integer] 更新対象の道場ID
175+
# @param source_dojo_id [Integer] 参照元の道場ID
176+
def sync_event_date(target_dojo_id, source_dojo_id)
177+
source_dojo = @latest_event_by_dojos.find { |d| d[:id] == source_dojo_id }
178+
target_dojo = @latest_event_by_dojos.find { |d| d[:id] == target_dojo_id }
179+
180+
if source_dojo && target_dojo
181+
target_dojo[:latest_event_at] = source_dojo[:latest_event_at]
182+
target_dojo[:latest_event_url] = source_dojo[:latest_event_url]
183+
end
184+
end
185+
168186
def parse_date_from_note(date_match)
169187
return nil if date_match.nil?
170188

app/helpers/dojo_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def truncate_with_preserved_links(text, length: 60)
2828
display_text = display_text.gsub(/\Ahttps?:\/\//, '')
2929
# www. を削除(\A で文字列の先頭のみマッチ)
3030
display_text = display_text.gsub(/\Awww\./, '')
31+
# facebook.com を fb.com に置換(Facebook の公式短縮ドメイン)
32+
display_text = display_text.gsub(/\Afacebook\.com/, 'fb.com')
3133
# 末尾のスラッシュを削除(\z で文字列の末尾のみマッチ)
3234
display_text = display_text.gsub(/\/\z/, '')
3335
link.content = display_text

spec/requests/dojos_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,31 @@
472472
expect(test_cell.to_html).to include('href="https://www.example.com/"')
473473
expect(test_cell.to_html).to include('href="http://www.example.net/"')
474474
end
475+
476+
it "displays Facebook URLs as fb.com in note column" do
477+
# Facebook URLを含むnoteを持つ道場を作成
478+
create(:dojo,
479+
name: "Test Dojo with Facebook",
480+
note: "Check out https://www.facebook.com/groups/coderdojo and https://facebook.com/events/123",
481+
inactivated_at: nil
482+
)
483+
484+
get activity_dojos_path
485+
486+
# ノート欄の表示テキストで facebook.com が fb.com に短縮されていることを確認
487+
doc = Nokogiri::HTML(response.body)
488+
note_cells = doc.css('td.url-cell')
489+
490+
fb_cell = note_cells.find { |cell| cell.text.include?("fb.com") }
491+
expect(fb_cell).not_to be_nil
492+
expect(fb_cell.text).to include("fb.com/groups/coderdojo")
493+
expect(fb_cell.text).to include("fb.com/events/123")
494+
expect(fb_cell.text).not_to include("facebook.com")
495+
expect(fb_cell.text).not_to include("www.")
496+
# 元のリンクは保持されていることを確認
497+
expect(fb_cell.to_html).to include('href="https://www.facebook.com/groups/coderdojo"')
498+
expect(fb_cell.to_html).to include('href="https://facebook.com/events/123"')
499+
end
475500
end
476501

477502
describe "GET /dojos/activity - note date priority" do

0 commit comments

Comments
 (0)