Skip to content

Commit c3a24db

Browse files
committed
docs: 重要なテストケースを追加 - 非アクティブ道場の扱い
yearパラメータ指定時: - HTML/JSON/CSVすべてで非アクティブ道場を含まないことを確認 yearパラメータなし: - CSV/JSONは全道場(非アクティブ含む)を確認 - HTMLはアクティブのみ(既存動作)を確認 これにより仕様が正しく実装されることを保証
1 parent 5194c45 commit c3a24db

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/plan_download_yearly_stats.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,30 @@ RSpec.describe DojosController, type: :controller do
381381
csv = CSV.parse(response.body)
382382
expect(csv[0]).to eq(['', '年末アクティブ道場数', '新規開設数', '非アクティブ化数', '累積合計', '純増減'])
383383
end
384+
385+
it 'yearパラメータなしの場合は非アクティブな道場も含む(CSV/JSON)' do
386+
active_dojo = create(:dojo, is_active: true)
387+
inactive_dojo = create(:dojo, is_active: false, inactivated_at: '2021-03-01')
388+
389+
# JSON形式: 全道場を含む
390+
get :index, format: :json
391+
json_response = JSON.parse(response.body)
392+
json_ids = json_response.map { |d| d['id'] }
393+
expect(json_ids).to include(active_dojo.id)
394+
expect(json_ids).to include(inactive_dojo.id)
395+
396+
# CSV形式: 全道場を含む
397+
get :index, format: :csv
398+
csv = CSV.parse(response.body, headers: true)
399+
csv_ids = csv.map { |row| row['ID'].to_i }
400+
expect(csv_ids).to include(active_dojo.id)
401+
expect(csv_ids).to include(inactive_dojo.id)
402+
403+
# HTML形式: アクティブな道場のみ(既存の動作を維持)
404+
get :index, format: :html
405+
expect(assigns(:dojos).map { |d| d[:id] }).to include(active_dojo.id)
406+
expect(assigns(:dojos).map { |d| d[:id] }).not_to include(inactive_dojo.id)
407+
end
384408
end
385409

386410
context '特定年のデータ(year=2020)' do
@@ -396,6 +420,30 @@ RSpec.describe DojosController, type: :controller do
396420
expect(csv[0]).to eq(['ID', '道場名', '都道府県', 'URL', '設立日', '状態'])
397421
expect(csv.size - 1).to eq(2) # ヘッダーを除いて2道場
398422
end
423+
424+
it 'yearパラメータ指定時は非アクティブな道場を含まない(全形式)' do
425+
# テストデータ: 2020年にアクティブ、2021年に非アクティブ化した道場
426+
inactive_dojo = create(:dojo,
427+
created_at: '2019-01-01',
428+
is_active: false,
429+
inactivated_at: '2021-03-01'
430+
)
431+
432+
# HTML形式
433+
get :index, params: { year: '2020' }, format: :html
434+
expect(assigns(:dojos).map { |d| d[:id] }).not_to include(inactive_dojo.id)
435+
436+
# JSON形式
437+
get :index, params: { year: '2020' }, format: :json
438+
json_response = JSON.parse(response.body)
439+
expect(json_response.map { |d| d['id'] }).not_to include(inactive_dojo.id)
440+
441+
# CSV形式
442+
get :index, params: { year: '2020' }, format: :csv
443+
csv = CSV.parse(response.body, headers: true)
444+
csv_ids = csv.map { |row| row['ID'].to_i }
445+
expect(csv_ids).not_to include(inactive_dojo.id)
446+
end
399447
end
400448

401449
context '無効な年が指定された場合' do

0 commit comments

Comments
 (0)