File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,10 @@ def index
13
13
end
14
14
15
15
@selected_year = year
16
- end_of_year = Time . zone . local ( @selected_year ) . end_of_year
16
+ year_end = Time . zone . local ( @selected_year ) . end_of_year
17
17
18
18
# その年末時点でアクティブだった道場を取得
19
- dojos_scope = Dojo . active_at ( end_of_year )
19
+ dojos_scope = Dojo . active_at ( year_end )
20
20
@page_title = "#{ @selected_year } 年末時点のCoderDojo一覧"
21
21
rescue ArgumentError
22
22
flash [ :inline_alert ] = "無効な年が指定されました"
@@ -58,8 +58,20 @@ def index
58
58
59
59
# 年が選択されている場合、統計情報を含むメッセージを設定
60
60
if @selected_year
61
- active_dojos_count = @dojos . count
62
- flash . now [ :inline_info ] = "#{ @selected_year } 年末時点のアクティブな道場を表示中<br>(開設道場数: #{ active_dojos_count } / 合計道場数: #{ @counter_sum } )" . html_safe
61
+ # /statsページと同じ計算方法を使用
62
+ # 開設数 = その年に新規開設されたDojoのcounter合計
63
+ year_begin = Time . zone . local ( @selected_year ) . beginning_of_year
64
+ year_end = Time . zone . local ( @selected_year ) . end_of_year
65
+ new_dojos_count = Dojo . where ( created_at : year_begin ..year_end ) . sum ( :counter )
66
+
67
+ # 合計数 = その年末時点でアクティブだったDojoのcounter合計
68
+ total_dojos_count = Dojo . active_at ( year_end ) . sum ( :counter )
69
+
70
+ # 表示用の日付テキスト
71
+ display_date = "#{ @selected_year } 年末"
72
+ display_date = Date . current . strftime ( '%Y年%m月%d日' ) if @selected_year == Date . current . year
73
+
74
+ flash . now [ :inline_info ] = "#{ display_date } 時点のアクティブな道場を表示中<br>(開設数: #{ new_dojos_count } / 合計数: #{ total_dojos_count } )" . html_safe
63
75
end
64
76
65
77
respond_to do |format |
Original file line number Diff line number Diff line change 58
58
expect ( flash [ :inline_alert ] ) . to include ( "2012年から" )
59
59
end
60
60
61
- it "rejects years after current year " do
61
+ it "rejects future years " do
62
62
future_year = Date . current . year + 1
63
63
get dojos_path ( year : future_year , format : :json )
64
64
expect ( response ) . to redirect_to ( dojos_path ( anchor : 'table' ) )
294
294
expect ( response . body ) . to include ( '2020年末時点' )
295
295
expect ( response . body ) . to include ( 'アクティブな道場を表示中' )
296
296
# 統計情報が含まれていることを確認(/statsページとの比較検証用)
297
- expect ( response . body ) . to include ( '開設道場数 :' )
298
- expect ( response . body ) . to include ( '合計道場数 :' )
297
+ expect ( response . body ) . to include ( '開設数 :' )
298
+ expect ( response . body ) . to include ( '合計数 :' )
299
299
# inline_infoメッセージが表示されることを確認
300
300
expect ( response . body ) . to include ( 'alert-info' )
301
301
end
You can’t perform that action at this time.
0 commit comments