QT 테마 라우트 + 컨트롤러 + 테스트
ID: 39414c99-a7b1-49cf-bfbd-bea1ae6a7669
## 목표
Qt::ThemesController 생성 (index, show, subscribe) + 라우트 + 컨트롤러 테스트
## 1. 라우트 (config/routes.rb)
qt namespace 안에 추가:
```ruby
resources :themes, only: [:index, :show] do
member do
post :subscribe
end
end
```
## 2. 컨트롤러 (app/controllers/qt/themes_controller.rb)
- `index`: QtTheme.active 목록 (is_default 먼저, 나머지 최신순)
- `show`: @theme = QtTheme.active.find(params[:id]), @contents = @theme.qt_contents.order(:day_number), @existing_session 중복 체크
- `subscribe`:
- QtSession 생성 (title: theme.title, qt_theme: theme, creator: current_user, start_date: Date.current, end_date: Date.current + theme.total_day - 1, total_days: theme.total_day)
- QtParticipant 생성 (role: :creator, user: current_user)
- 이미 같은 테마로 active 세션 있으면 redirect with alert
- 성공 시 redirect_to qt_session_path(session), notice: "플랜이 시작되었습니다!"
## 3. 테스트 (test/controllers/qt/themes_controller_test.rb)
- GET /qt/themes - 로그인 필수, active 테마만 표시, inactive 미표시
- GET /qt/themes/:id - 테마 상세 표시, inactive 테마 404
- POST /qt/themes/:id/subscribe - 세션+참여자 생성, 중복 구독 방지
- 비로그인 시 redirect
## 참고 파일
- app/controllers/qt/sessions_controller.rb (패턴 참고)
- app/models/qt_theme.rb (scope :active)
- app/models/qt_session.rb (generate_invite_code)
- test/fixtures/qt_themes.yml (default_theme, ai_theme, inactive_theme)
## 완료 기준
- 라우트 동작, 컨트롤러 3개 액션, 테스트 전체 통과
첨부 이미지
이미지 추가 (Ctrl+V로 붙여넣기 또는 클릭)
JPEG, PNG, GIF, WebP / 최대 10MB
활동 로그
-
팀팀리드 상태 변경: 리뷰 → 완료
2026년 03월 03일 05:21:31
-
Ttheme-backend 상태 변경: 할 일 → 리뷰
2026년 03월 02일 12:24:38
-
Ttheme-backend QT 테마 라우트 + 컨트롤러 + 테스트 구현 완료
2026년 03월 02일 12:24:37
상세 보기
## 변경 사항
### 1. 라우트 (config/routes.rb)
- `namespace :qt` 안에 `resources :themes, only: [:index, :show]` 추가
- `member { post :subscribe }` 추가### 2. 컨트롤러 (app/controllers/qt/themes_controller.rb)
- `index`: `@default_themes` (is_default: true) + `@themes` (is_default: false) 분리
- `show`: active 테마만 find, contents 미리보기 3개, 기존 세션 중복 체크
- `subscribe`: 중복 방지, QtSession + QtParticipant 생성
- `set_theme` private 메서드로 active scope 적용 (inactive → 404)### 3. 테스트 (test/controllers/qt/themes_controller_test.rb)
- 8개 테스트, 29개 assertions, 0 failures
- 인증 (비로그인 → redirect) 3개
- index (active 테마만 표시) 1개
- show (active 표시 + inactive 404) 2개
- subscribe (생성 + 중복 방지) 2개### 참고
- 기존 뷰 파일 (index.html.erb, show.html.erb, _theme_card.html.erb) 활용
- 기존 컨트롤러를 팀리드 스펙에 맞게 업데이트
- SQLite BusyException은 다른 에이전트 동시 실행으로 인한 일시적 문제