Skip to content

Commit 38ff377

Browse files
committed
test: inactivated_atを持つDojoが必ずis_activeカラムを持つことを確認するテストを追加
YAMLファイルのデータ整合性を検証するテスト。 DBではコールバックで自動設定されるが、YAMLファイル(マスターデータ)では 手動編集時にis_activeカラムを忘れる可能性があるため重要。 再活性化されたDojo(is_active: true)の存在も考慮し、 カラムの存在のみをチェック(値は問わない)。
1 parent 5a548c7 commit 38ff377

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

spec/models/dojo_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@
124124
end
125125
end
126126
end
127+
128+
it 'ensures all dojos with inactivated_at have is_active column' do
129+
yaml_data = Dojo.load_attributes_from_yaml
130+
dojos_with_inactivated_at = yaml_data.select { |dojo| dojo['inactivated_at'].present? }
131+
132+
dojos_with_inactivated_at.each do |dojo|
133+
# inactivated_atがあるDojoは必ずis_activeカラムを持つべき
134+
# (再活性化されたDojoはis_active: trueの可能性があるため、値は問わない)
135+
unless dojo.key?('is_active')
136+
fail "ID: #{dojo['id']} (#{dojo['name']}) はinactivated_atを持っていますが、is_activeカラムがありません"
137+
end
138+
end
139+
140+
# 統計情報として表示
141+
if dojos_with_inactivated_at.any?
142+
reactivated_count = dojos_with_inactivated_at.count { |d| d['is_active'] == true }
143+
inactive_count = dojos_with_inactivated_at.count { |d| d['is_active'] == false }
144+
145+
# テスト出力には表示されないが、デバッグ時に有用
146+
# puts "inactivated_atを持つDojo数: #{dojos_with_inactivated_at.count}"
147+
# puts " - 現在非アクティブ: #{inactive_count}"
148+
# puts " - 再活性化済み: #{reactivated_count}"
149+
150+
expect(dojos_with_inactivated_at.count).to eq(inactive_count + reactivated_count)
151+
end
152+
end
127153
end
128154

129155
# inactivated_at カラムの基本的なテスト

0 commit comments

Comments
 (0)