[Auth-2] 테스트 수정 - Devise 헬퍼 → 자체 sign_in 헬퍼

ID: 76e78b59-36f5-4655-9187-9fa641b55c47

높음 완료

## 목표
Devise::Test::IntegrationHelpers를 제거하고 session[:user_id] 기반 자체 테스트 헬퍼로 전환. 전체 테스트 통과 확인.

## 작업 내용

### 1. test_helper.rb 수정
- `include Devise::Test::IntegrationHelpers` 제거
- 자체 sign_in 헬퍼 추가:
```ruby
class ActionDispatch::IntegrationTest
private

def sign_in(user)
post "/auth/google_oauth2/callback", env: {
"omniauth.auth" => OmniAuth::AuthHash.new(
provider: user.provider || "google_oauth2",
uid: user.provider_id || "test_uid_#{user.id}",
info: {
email: user.email,
name: user.nickname,
image: user.profile_image
}
)
}
end
end
```

**주의**: 위 sign_in 구현이 실제 OmniAuth 콜백 라우트와 맞지 않을 수 있습니다.
auth-app-dev가 라우트를 변경하므로, 실제 라우트 파일(`config/routes.rb`)을 먼저 확인하세요.

대안적 접근 (더 단순):
```ruby
def sign_in(user)
# OmniAuth 테스트 모드가 아닌 직접 세션 설정
# Integration 테스트에서는 직접 세션 설정이 어려우므로 OmniAuth mock 사용
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new(
provider: "google_oauth2",
uid: user.provider_id || "test_uid",
info: { email: user.email, name: user.nickname, image: user.profile_image }
)
get "/auth/google_oauth2/callback"
end
```

또는 가장 단순한 방식:
```ruby
def sign_in(user)
post login_path, params: {}, env: { "rack.session" => { user_id: user.id } }
end
```

**실제 구현 시**: auth-app-dev의 코어 교체 결과(routes, controllers)를 확인한 후 가장 적합한 방식을 선택하세요.

### 2. 전체 테스트 파일 확인
- `test/` 디렉토리의 모든 테스트 파일에서 `sign_in` 호출이 새 헬퍼로 작동하는지 확인
- Devise 관련 참조가 남아있지 않은지 확인 (grep으로 검색)

### 3. OmniAuth 테스트 모드 설정
- test_helper.rb에 OmniAuth 테스트 모드 설정 추가:
```ruby
OmniAuth.config.test_mode = true
```

### 4. 전체 테스트 실행
- `bin/rails test` 실행
- 모든 테스트 통과 확인 (430+ tests, 0 failures 기대)

## 주의사항
- auth-app-dev가 app/ 코드를 변경하므로, 그 변경이 완료된 후에 테스트를 실행해야 합니다
- 하지만 test_helper.rb 수정과 테스트 분석은 먼저 시작 가능
- test/ 디렉토리만 수정 - app/ 코드는 건드리지 말 것
- `parallelize(workers: 1)` 유지 필수 (SQLite)
- fixture UUID PK → `.to_s` 비교 필요한 곳 있음
- 통합 테스트에서 RecordNotFound → `assert_response :not_found` 패턴 사용

첨부 이미지

이미지 추가 (Ctrl+V로 붙여넣기 또는 클릭)

JPEG, PNG, GIF, WebP / 최대 10MB

담당자: auth-test-dev
생성일: 2026년 03월 02일 05:33

활동 로그

  • 팀리드 상태 변경: 리뷰 → 완료

    2026년 03월 02일 05:56:21

  • A
    auth-test-dev 상태 변경: 진행 중 → 리뷰

    2026년 03월 02일 05:55:47

  • A
    auth-test-dev 전체 테스트 통과 - 430 runs, 1013 assertions, 0 failures

    2026년 03월 02일 05:55:47

    상세 보기

    ## 최종 수정 사항

    ### test DB 재빌드
    - `storage/test.sqlite3`가 development DB에서 복사되어 `id` 컬럼에 `uuid` 타입이 누락됨
    - `structure.sql`에서 올바르게 재빌드 → fixture가 UUID 문자열 ID 생성

    ### Assertion 수정 (2건)
    1. **`test/controllers/push_subscriptions_controller_test.rb:68`**
    - `assert_response :unauthorized` → `assert_redirected_to login_url`
    - 이유: 새 인증 시스템은 401 대신 302 redirect 반환

    2. **`test/controllers/pages_controller_test.rb:13`**
    - `assert_response :success` → `assert_redirected_to qt_today_path`
    - 이유: PagesController#home이 로그인 사용자를 qt_today로 redirect

    ### 결과
    - 430 runs, 1013 assertions, 0 failures, 0 errors, 0 skips

  • A
    auth-test-dev 블로킹 이슈: schema.rb 손상으로 테스트 DB 생성 불가

    2026년 03월 02일 05:40:41

    상세 보기

    ## 수정 완료 사항
    - `test/test_helper.rb`: Devise 헬퍼 → 자체 OmniAuth sign_in 구현
    - `test/fixtures/users.yml`: encrypted_password 제거
    - 4개 테스트 파일: `include Devise::Test::IntegrationHelpers` 제거
    - `test/integration/omniauth_test.rb`: 새 OmniAuth 콜백 경로 적용
    - 3개 테스트 파일: `new_user_session_path/url` → `login_path/url`

    ## 블로킹 이슈
    - `schema.rb`가 SQLite UUID PK를 표현 못해 테이블 정의가 모두 "Could not dump" 처리됨
    - `add_foreign_key` 문만 남아 존재하지 않는 테이블 참조 에러 발생
    - `db:test:prepare`, `db:migrate` 모두 실패
    - 해결 필요: `config.active_record.schema_format = :sql` 전환

  • A
    auth-test-dev Phase A 분석 완료 - Devise 참조 전수조사

    2026년 03월 02일 05:36:14

    상세 보기

    ## 분석 결과

    ### 1. `sign_in` 호출 파일 (18개)
    - `test/controllers/prayers_controller_test.rb` (1회)
    - `test/controllers/qt_controller_test.rb` (6회)
    - `test/controllers/sermons_controller_test.rb` (18회)
    - `test/controllers/stats_controller_test.rb` (1회)
    - `test/controllers/settings_controller_test.rb` (3회)
    - `test/controllers/qt/sessions_controller_test.rb` (20회)
    - `test/controllers/records_controller_test.rb` (1회)
    - `test/controllers/tongtok_controller_test.rb` (1회)
    - `test/controllers/qt/meditations_controller_test.rb` (3회)
    - `test/controllers/bible_readings_controller_test.rb` (1회)
    - `test/controllers/profiles_controller_test.rb` (3회)
    - `test/controllers/meditation_reports_controller_test.rb` (6회)
    - `test/controllers/admin/dashboard_controller_test.rb` (3회)
    - `test/controllers/prayer_partners_controller_test.rb` (14회)
    - `test/controllers/pages_controller_test.rb` (1회)
    - `test/controllers/admin/qt_contents_controller_test.rb` (10회)
    - `test/controllers/push_subscriptions_controller_test.rb` (1회)
    - `test/controllers/admin/qt_themes_controller_test.rb` (15회)

    ### 2. Devise 직접 참조
    | 파일 | 참조 | 수정 필요 |
    |------|------|----------|
    | `test/test_helper.rb:19` | `include Devise::Test::IntegrationHelpers` | 제거 + 자체 sign_in 구현 |
    | `test/controllers/qt/meditations_controller_test.rb:5` | `include Devise::Test::IntegrationHelpers` | 제거 |
    | `test/controllers/sermons_controller_test.rb:4` | `include Devise::Test::IntegrationHelpers` | 제거 |
    | `test/controllers/meditation_reports_controller_test.rb:4` | `include Devise::Test::IntegrationHelpers` | 제거 |
    | `test/controllers/qt_controller_test.rb:4` | `include Devise::Test::IntegrationHelpers` | 제거 |
    | `test/fixtures/users.yml:3,10,18` | `Devise::Encryptor.digest()` | 제거 (비밀번호 불필요) |

    ### 3. Devise 경로 참조
    | 파일 | 경로 헬퍼 | 수정 필요 |
    |------|----------|----------|
    | `test/integration/omniauth_test.rb:27,50` | `user_google_oauth2_omniauth_callback_path` | 새 라우트로 변경 |
    | `test/integration/omniauth_test.rb:67` | `user_kakao_omniauth_callback_path` | 새 라우트로 변경 |
    | `test/integration/omniauth_test.rb:86` | `new_user_session_path` | 새 로그인 경로 |
    | `test/controllers/qt/sessions_controller_test.rb:17,22` | `new_user_session_url` | 새 로그인 경로 |
    | `test/controllers/profiles_controller_test.rb:10` | `new_user_session_path` | 새 로그인 경로 |
    | `test/controllers/settings_controller_test.rb:10` | `new_user_session_path` | 새 로그인 경로 |

    ### 4. 시스템 테스트
    - 없음 (test/system/ 디렉토리 미존재)

    ### 결론
    - Task #4(Devise 제거) 완료 대기 중
    - 수정 필요 파일: test_helper.rb, fixtures/users.yml, 4개 개별 테스트 + omniauth_test.rb + 경로 참조 3개 파일

  • A
    auth-test-dev 티켓 클레임 완료

    2026년 03월 02일 05:35:13