|
346 | 346 | expect(response.body).to include("道場別の活動状況まとめ") |
347 | 347 | end |
348 | 348 |
|
349 | | - it "includes only active dojos" do |
| 349 | + it "includes both active and inactive dojos" do |
350 | 350 | get activity_dojos_path |
351 | 351 | expect(response.body).to include(@active_dojo.name) |
352 | | - expect(response.body).not_to include(@inactive_dojo.name) |
| 352 | + expect(response.body).to include(@inactive_dojo.name) |
| 353 | + end |
| 354 | + |
| 355 | + it "displays inactive dojos with inactive-item class" do |
| 356 | + get activity_dojos_path |
| 357 | + doc = Nokogiri::HTML(response.body) |
| 358 | + |
| 359 | + # 非アクティブな道場の行を探す(リンク内にある名前を探す) |
| 360 | + inactive_link = doc.xpath("//a[contains(., '#{@inactive_dojo.name}')]").first |
| 361 | + expect(inactive_link).not_to be_nil |
| 362 | + |
| 363 | + # そのリンクを含む行(tr)を取得 |
| 364 | + inactive_row = inactive_link.xpath("ancestor::tr").first |
| 365 | + expect(inactive_row).not_to be_nil |
| 366 | + |
| 367 | + # その行のすべてのセルに inactive-item クラスがあることを確認 |
| 368 | + inactive_cells = inactive_row.css('td') |
| 369 | + expect(inactive_cells.all? { |cell| cell['class']&.include?('inactive-item') }).to be true |
| 370 | + end |
| 371 | + |
| 372 | + it "sorts inactive dojos by latest event date in descending order" do |
| 373 | + # 複数の非アクティブな道場を作成(異なる作成日で) |
| 374 | + older_inactive_dojo = create(:dojo, |
| 375 | + name: "Older Inactive Dojo", |
| 376 | + created_at: 2.years.ago, # より古い作成日 |
| 377 | + inactivated_at: 6.months.ago |
| 378 | + ) |
| 379 | + |
| 380 | + newer_inactive_dojo = create(:dojo, |
| 381 | + name: "Newer Inactive Dojo", |
| 382 | + created_at: 1.year.ago, # より新しい作成日 |
| 383 | + inactivated_at: 3.months.ago |
| 384 | + ) |
| 385 | + |
| 386 | + # db/static_event_histories.yml の形式に合わせてEventHistory を作成 |
| 387 | + # より古いイベント |
| 388 | + EventHistory.create!( |
| 389 | + dojo_id: older_inactive_dojo.id, |
| 390 | + dojo_name: older_inactive_dojo.name, |
| 391 | + event_url: 'https://example.com/event1', |
| 392 | + evented_at: 8.months.ago, |
| 393 | + participants: 10, |
| 394 | + service_name: 'static_yml', |
| 395 | + service_group_id: 'static', |
| 396 | + event_id: 1 |
| 397 | + ) |
| 398 | + |
| 399 | + # より新しいイベント |
| 400 | + EventHistory.create!( |
| 401 | + dojo_id: newer_inactive_dojo.id, |
| 402 | + dojo_name: newer_inactive_dojo.name, |
| 403 | + event_url: 'https://example.com/event2', |
| 404 | + evented_at: 4.months.ago, # より最近のイベント |
| 405 | + participants: 15, |
| 406 | + service_name: 'static_yml', |
| 407 | + service_group_id: 'static', |
| 408 | + event_id: 2 |
| 409 | + ) |
| 410 | + |
| 411 | + get activity_dojos_path |
| 412 | + doc = Nokogiri::HTML(response.body) |
| 413 | + |
| 414 | + # 全ての道場の名前を取得(テーブルの最初のセルのリンクから) |
| 415 | + dojo_links = doc.css('table tr td:first-child a') |
| 416 | + dojo_names = dojo_links.map(&:text).map(&:strip) |
| 417 | + |
| 418 | + # 非アクティブな道場の中で、newer_inactive_dojo が older_inactive_dojo より先に表示されることを確認 |
| 419 | + newer_index = dojo_names.find_index { |name| name.include?(newer_inactive_dojo.name) } |
| 420 | + older_index = dojo_names.find_index { |name| name.include?(older_inactive_dojo.name) } |
| 421 | + |
| 422 | + expect(newer_index).not_to be_nil |
| 423 | + expect(older_index).not_to be_nil |
| 424 | + expect(newer_index).to be < older_index |
353 | 425 | end |
354 | 426 |
|
355 | 427 | it "redirects from old URL /events/latest" do |
|
0 commit comments