Skip to content

Commit 7beb3b4

Browse files
committed
📝 Update: TDDアプローチによる依存箇所検出戦略を追加
- Phase 1.0 に NotImplementedError を使った依存箇所検出を追加 - 段階的移行戦略(エラー→警告→実装)を明確化 - 実装戦略セクションを追加して全体の流れを説明
1 parent ca2aa7a commit 7beb3b4

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

doc/plan_refactor_inactivated_at.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ before_save :sync_active_status
6363

6464
## 📝 実装計画
6565

66+
### 実装戦略: TDD による安全なリファクタリング
67+
68+
1. **検出フェーズ**: エラーを発生させて依存箇所を特定
69+
2. **修正フェーズ**: 特定された箇所を順次修正
70+
3. **移行フェーズ**: 新しい実装に切り替え
71+
4. **削除フェーズ**: 不要なコードとカラムを削除
72+
73+
この戦略により、見落としなく安全にリファクタリングを実施できます。
74+
6675
### Phase 0: 準備作業(30分)
6776

6877
#### 0.1 データ整合性の最終確認
@@ -94,6 +103,24 @@ git checkout -b refactor-to-merge-inactive-into-inactivated-columns
94103

95104
### Phase 1: テストファースト実装(45分)
96105

106+
#### 1.0 依存箇所の検出(TDDアプローチ)
107+
```ruby
108+
# app/models/dojo.rb
109+
# 一時的にエラーを発生させて、これらのスコープを使用している箇所を検出
110+
scope :active, -> {
111+
raise NotImplementedError,
112+
"DEPRECATED: Use `where(inactivated_at: nil)` instead of `.active` scope. Called from: #{caller.first}"
113+
}
114+
scope :inactive, -> {
115+
raise NotImplementedError,
116+
"DEPRECATED: Use `where.not(inactivated_at: nil)` instead of `.inactive` scope. Called from: #{caller.first}"
117+
}
118+
119+
# テストを実行して、どこでエラーが発生するか確認
120+
# bundle exec rspec
121+
# これにより、リファクタリングが必要な全ての箇所を特定できる
122+
```
123+
97124
#### 1.1 テストの更新
98125
```ruby
99126
# spec/models/dojo_spec.rb
@@ -139,11 +166,21 @@ end
139166

140167
### Phase 2: モデル層のリファクタリング(30分)
141168

142-
#### 2.1 スコープの更新
169+
#### 2.1 スコープの更新(段階的移行)
143170
```ruby
144171
# app/models/dojo.rb
145172
class Dojo < ApplicationRecord
146-
# 更新されたスコープ
173+
# Step 1: エラー検出フェーズ(Phase 1.0で実施)
174+
# scope :active, -> { raise NotImplementedError, "..." }
175+
# scope :inactive, -> { raise NotImplementedError, "..." }
176+
177+
# Step 2: 警告フェーズ(オプション)
178+
# scope :active, -> {
179+
# Rails.logger.warn "DEPRECATED: .active scope will be updated to use inactivated_at"
180+
# where(is_active: true)
181+
# }
182+
183+
# Step 3: 最終的な実装
147184
scope :active, -> { where(inactivated_at: nil) }
148185
scope :inactive, -> { where.not(inactivated_at: nil) }
149186

0 commit comments

Comments
 (0)