377
377
expect ( response . body ) . to include ( "道場名 (ID 番号)" )
378
378
end
379
379
end
380
+
381
+ describe "GET /dojos/activity - note date priority" do
382
+ before do
383
+ # Create Wakayama-like dojo with old event history but newer note date
384
+ @test_dojo = create ( :dojo ,
385
+ name : "和歌山テスト" ,
386
+ created_at : Time . zone . parse ( "2016-11-01" ) ,
387
+ inactivated_at : nil ,
388
+ note : "Active for years - 2025-03-16 https://coderdojo-wakayama.hatenablog.com/entry/2025/03/16/230604"
389
+ )
390
+
391
+ # Create an old event history record for this dojo
392
+ @old_event = EventHistory . create! (
393
+ dojo_id : @test_dojo . id ,
394
+ dojo_name : @test_dojo . name ,
395
+ service_name : "facebook" ,
396
+ event_id : "1761517970842435" ,
397
+ participants : 10 ,
398
+ evented_at : Time . zone . parse ( "2017-03-12 14:30:00" ) ,
399
+ event_url : "https://www.facebook.com/events/1761517970842435"
400
+ )
401
+ end
402
+
403
+ it "should prioritize newer note date over older event history" do
404
+ get activity_dojos_path
405
+
406
+ # Find the dojo row in the response
407
+ dojo_row_match = response . body . match ( /#{ @test_dojo . name } .*?<\/ tr>/m )
408
+ expect ( dojo_row_match ) . not_to be_nil , "Could not find dojo row for #{ @test_dojo . name } "
409
+
410
+ dojo_row = dojo_row_match [ 0 ]
411
+
412
+ # The 開催日 (event date) column should show the newer note date (2025-03-16)
413
+ # not the older event history date (2017-03-12)
414
+ expect ( dojo_row ) . to include ( "2025-03-16" ) ,
415
+ "Expected to see note date 2025-03-16 in 開催日 column, but found: #{ dojo_row } "
416
+
417
+ expect ( dojo_row ) . not_to include ( "2017-03-12" ) ,
418
+ "Should not show old event history date 2017-03-12 when newer note date exists"
419
+ end
420
+
421
+ it "should link to note URL when displaying note date in 開催日 column" do
422
+ get activity_dojos_path
423
+
424
+ # Find the dojo row
425
+ dojo_row_match = response . body . match ( /#{ @test_dojo . name } .*?<\/ tr>/m )
426
+ expect ( dojo_row_match ) . not_to be_nil
427
+
428
+ dojo_row = dojo_row_match [ 0 ]
429
+
430
+ # Should contain a link to the note URL
431
+ expect ( dojo_row ) . to include ( "https://coderdojo-wakayama.hatenablog.com/entry/2025/03/16/230604" ) ,
432
+ "Expected to find note URL in the 開催日 column"
433
+ end
434
+
435
+ it "handles multiple date formats in note (YYYY-MM-DD and YYYY/MM/DD)" do
436
+ # Test with slash format
437
+ slash_format_dojo = create ( :dojo ,
438
+ name : "スラッシュ形式テスト" ,
439
+ created_at : Time . zone . parse ( "2016-01-01" ) ,
440
+ inactivated_at : nil ,
441
+ note : "Active - last event 2025/03/16 using Google Forms"
442
+ )
443
+
444
+ # Create old event history
445
+ EventHistory . create! (
446
+ dojo_id : slash_format_dojo . id ,
447
+ dojo_name : slash_format_dojo . name ,
448
+ service_name : "connpass" ,
449
+ event_id : "12345" ,
450
+ participants : 5 ,
451
+ evented_at : Time . zone . parse ( "2017-01-01" ) ,
452
+ event_url : "https://example.com"
453
+ )
454
+
455
+ get activity_dojos_path
456
+
457
+ # Should show the note date in standard format
458
+ expect ( response . body ) . to include ( "2025-03-16" ) ,
459
+ "Should parse YYYY/MM/DD format and display as YYYY-MM-DD"
460
+ end
461
+
462
+ it "handles Japanese date format in note (YYYY年MM月DD日)" do
463
+ # Test with Japanese date format
464
+ japanese_format_dojo = create ( :dojo ,
465
+ name : "日本語形式テスト" ,
466
+ created_at : Time . zone . parse ( "2016-01-01" ) ,
467
+ inactivated_at : nil ,
468
+ note : "最終開催日: 2025年8月24日 Peatixで申込受付中"
469
+ )
470
+
471
+ # Create old event history
472
+ EventHistory . create! (
473
+ dojo_id : japanese_format_dojo . id ,
474
+ dojo_name : japanese_format_dojo . name ,
475
+ service_name : "connpass" ,
476
+ event_id : "jp123" ,
477
+ participants : 8 ,
478
+ evented_at : Time . zone . parse ( "2017-01-01" ) ,
479
+ event_url : "https://example.com"
480
+ )
481
+
482
+ get activity_dojos_path
483
+
484
+ # Find the dojo row
485
+ dojo_row_match = response . body . match ( /#{ japanese_format_dojo . name } .*?<\/ tr>/m )
486
+ expect ( dojo_row_match ) . not_to be_nil
487
+
488
+ dojo_row = dojo_row_match [ 0 ]
489
+
490
+ # Should show the Japanese date in standard format (2025-08-24)
491
+ expect ( dojo_row ) . to include ( "2025-08-24" ) ,
492
+ "Should parse YYYY年MM月DD日 format and display as YYYY-MM-DD"
493
+ end
494
+
495
+ it "shows event history date when it's newer than note date" do
496
+ # Create dojo with older note date
497
+ newer_event_dojo = create ( :dojo ,
498
+ name : "イベント履歴が新しいテスト" ,
499
+ created_at : Time . zone . parse ( "2016-01-01" ) ,
500
+ inactivated_at : nil ,
501
+ note : "Last manual event - 2025-03-16 using Google Forms"
502
+ )
503
+
504
+ # Create newer event history (newer than note date)
505
+ newer_event = EventHistory . create! (
506
+ dojo_id : newer_event_dojo . id ,
507
+ dojo_name : newer_event_dojo . name ,
508
+ service_name : "connpass" ,
509
+ event_id : "67890" ,
510
+ participants : 15 ,
511
+ evented_at : Time . zone . parse ( "2025-08-01 19:00:00" ) , # Newer than note date
512
+ event_url : "https://example-newer.com"
513
+ )
514
+
515
+ get activity_dojos_path
516
+
517
+ # Find the dojo row
518
+ dojo_row_match = response . body . match ( /#{ newer_event_dojo . name } .*?<\/ tr>/m )
519
+ expect ( dojo_row_match ) . not_to be_nil
520
+
521
+ dojo_row = dojo_row_match [ 0 ]
522
+
523
+ # Extract just the 開催日 column to check the date display
524
+ td_matches = dojo_row . scan ( /<td[^>]*>(.*?)<\/ td>/m )
525
+
526
+ # Based on debug output: td_matches[1] is the 開催日 column
527
+ # (道場名 column seems to be skipped in regex due to complex link structure)
528
+ event_date_column = td_matches [ 1 ] &.first # 開催日 column
529
+
530
+ expect ( event_date_column ) . not_to be_nil , "Could not find 開催日 column"
531
+
532
+ # Should show the newer event history date (2025-08-01) in the 開催日 column
533
+ expect ( event_date_column ) . to include ( "2025-08-01" ) ,
534
+ "Expected to see newer event history date 2025-08-01 in 開催日 column, but found: #{ event_date_column } "
535
+
536
+ # The 開催日 column should not contain the older note date
537
+ expect ( event_date_column ) . not_to include ( "2025-03-16" ) ,
538
+ "Should not show older note date 2025-03-16 in 開催日 column when newer event history exists"
539
+ end
540
+ end
380
541
end
0 commit comments