You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance flex:case generator to auto-generate controllers, views, routes, and locales (#190)
## Changes
- Enhanced the `flex:case` generator to automatically generate
controllers, views, routes, and locales when creating a new case
- Added new generator methods: `handle_staff_controller_generation`,
`create_case_controller`, `create_case_views`, `update_routes`, and
`create_locale_file`
- Created template files for controller, 6 view files (index, show,
documents, tasks, notes, _case_layout), and locale files (en.yml,
es-US.yml)
- Added `--staff-controller` option to automatically generate
StaffController if it doesn't exist
- Added `source_root` configuration for template discovery
- Added comprehensive test coverage for all new functionality with
proper mocking
## Context
This enhancement addresses TSS-268 by eliminating the manual work
developers previously had to do after generating a case model. The
generator now creates a complete case management interface following
established patterns:
- **Controller**: Inherits from StaffController with standard actions
(index, closed, show, tasks, documents, notes)
- **Views**: Use delegation pattern to existing `flex/cases` templates
with proper locals and sidenav configuration
- **Routes**: Added under `/staff` scope with member and collection
actions matching the controller
- **Locales**: Created nested structure under
`config/locales/views/{case_name}/` with English and Spanish
translations
- **StaffController dependency**: Checks for existence and optionally
generates it via the existing `flex:staff` generator
The implementation follows established patterns from the existing
`staff_generator` and maintains consistency with the codebase's
generator architecture.
**Key implementation decisions:**
- View templates delegate to existing `flex/cases/show` and
`flex/cases/index` templates rather than duplicating logic
- Locale files use nested structure matching the view hierarchy
- Controller uses `before_action` pattern consistent with existing
controllers
- Route generation uses Rails' `route` method for proper integration
## Testing
**Unit Tests**: All 798 tests pass with comprehensive coverage of the
new functionality
```
798 examples, 0 failures, 1 pending
Line Coverage: 98.11% (5453 / 5558)
Branch Coverage: 84.55% (383 / 453)
```
**Linting**: Code passes all RuboCop checks with auto-corrections
applied
**Manual Generator Testing**: Successfully tested the enhanced
generator:
```bash
bin/rails generate flex:case TestWorking name:string --staff-controller
```
Generated files include:
- `app/controllers/test_workings_controller.rb` - Controller with proper
inheritance and actions
- `app/views/test_workings/` - Complete view structure with delegation
patterns
- Routes under `/staff` scope with member and collection actions
- Locale files with English and Spanish translations
**Human Review Checklist:**
1. **Template Syntax**: Verify ERB template syntax is correct,
especially variable interpolation (`<%= class_name %>`, `<%= file_name
%>`)
2. **Route Safety**: Check that generated routes don't conflict with
existing routes and use correct syntax
3. **View Delegation**: Confirm view templates properly delegate to
`flex/cases` templates with correct locals
4. **Locale Structure**: Validate nested locale file structure matches
Rails i18n expectations
5. **Controller Pattern**: Review controller inheritance from
StaffController and before_action usage
6. **StaffController Logic**: Verify the safe_constantize logic for
checking StaffController existence
7. **File Naming**: Check that `file_name.pluralize` works correctly for
edge cases and irregular plurals
---
**Link to Devin run**:
https://app.devin.ai/sessions/d98a0a4475134e8183013380682f7b49
**Requested by**: @baonguyenNava
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Bao Nguyen <baonguyen@navapbc.com>
0 commit comments