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
1313 end
1414
1515 @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
1717
1818 # その年末時点でアクティブだった道場を取得
19- dojos_scope = Dojo . active_at ( end_of_year )
19+ dojos_scope = Dojo . active_at ( year_end )
2020 @page_title = "#{ @selected_year } 年末時点のCoderDojo一覧"
2121 rescue ArgumentError
2222 flash [ :inline_alert ] = "無効な年が指定されました"
@@ -58,8 +58,20 @@ def index
5858
5959 # 年が選択されている場合、統計情報を含むメッセージを設定
6060 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
6375 end
6476
6577 respond_to do |format |
Original file line number Diff line number Diff line change 5858 expect ( flash [ :inline_alert ] ) . to include ( "2012年から" )
5959 end
6060
61- it "rejects years after current year " do
61+ it "rejects future years " do
6262 future_year = Date . current . year + 1
6363 get dojos_path ( year : future_year , format : :json )
6464 expect ( response ) . to redirect_to ( dojos_path ( anchor : 'table' ) )
294294 expect ( response . body ) . to include ( '2020年末時点' )
295295 expect ( response . body ) . to include ( 'アクティブな道場を表示中' )
296296 # 統計情報が含まれていることを確認(/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 ( '合計数 :' )
299299 # inline_infoメッセージが表示されることを確認
300300 expect ( response . body ) . to include ( 'alert-info' )
301301 end
You can’t perform that action at this time.
0 commit comments