@@ -74,10 +74,19 @@ bin/rails dbconsole # Database console
7474- Monitor at ` /madmin/sidekiq ` in development
7575
7676### Testing Strategy
77- - Minitest for all tests (models, controllers, integration)
77+ - Minitest for all tests (models, controllers, integration, policies )
7878- WebMock for stubbing external HTTP requests
79- - Parallel test execution supported
80- - API integration tests for all endpoints
79+ - Parallel test execution supported (10 workers by default)
80+ - Comprehensive test coverage across all layers:
81+ - ** Model tests** : test/models/ - Validations, associations, callbacks, state machines
82+ - ** Policy tests** : test/policies/ - Authorization rules for all user roles
83+ - ** Controller tests** : test/controllers/ - API endpoints, authentication, authorization
84+ - ** Integration tests** : test/integration/ - End-to-end user flows
85+ - Test helpers:
86+ - ` json_response ` for parsing JSON API responses
87+ - ` create_new_auth_token ` for generating auth headers (Devise Token Auth)
88+ - Fixtures in test/fixtures/ and seed data in db/fixtures/test/
89+ - Run tests: ` bin/rails test ` (205 tests, 402 assertions)
8190
8291### Development Server Configuration
8392- Server binds to specific IP: ` 192.168.1.21:3000 ` (not localhost)
@@ -98,14 +107,55 @@ bin/rails dbconsole # Database console
98107- Web server: ` bin/render-start.sh `
99108- Background workers: ` bin/render-start-sidekiq.sh `
100109
110+ ## Code Quality Checks Before Committing
111+
112+ ** IMPORTANT** : Always run these checks and fix all errors before committing code:
113+
114+ ### 1. Lint Errors (RuboCop)
115+ ``` bash
116+ bin/rubocop
117+ ```
118+ - Fix all RuboCop offenses before committing
119+ - Run ` bin/rubocop -a ` to auto-correct safe offenses
120+ - Review and manually fix remaining issues
121+
122+ ### 2. Security Scan (Brakeman)
123+ ``` bash
124+ bin/brakeman
125+ ```
126+ - Fix all security vulnerabilities before committing
127+ - Review warnings and address potential security issues
128+ - Never commit code with security vulnerabilities
129+
130+ ### 3. Run Tests
131+ ``` bash
132+ bin/rails test
133+ ```
134+ - Ensure all tests pass before committing
135+ - Add tests for new features or bug fixes
136+
137+ ### Pre-Commit Checklist
138+ - [ ] ` bin/rubocop ` - No lint errors
139+ - [ ] ` bin/brakeman ` - No security issues
140+ - [ ] ` bin/rails test ` - All tests passing
141+ - [ ] Code reviewed for quality and security
142+
101143## Common Development Tasks
102144
103145### Creating New API Endpoints
1041461 . Add route in ` config/routes.rb ` under appropriate namespace
1051472 . Create controller inheriting from ` Api::V1::BaseController `
106- 3 . Add Pundit policy in ` app/policies/ `
148+ 3 . Add Pundit policy in ` app/policies/ ` with authorization rules
1071494 . Create serializer in ` app/serializers/ `
108- 5 . Write integration tests in ` test/integration/ `
150+ 5 . Write controller tests in ` test/controllers/ ` testing all actions and edge cases
151+
152+ ### Writing Tests
153+ - ** Model tests** : Test validations, associations, callbacks, scopes, and business logic
154+ - ** Policy tests** : Test authorization for all roles (admin, managers, members, guest)
155+ - ** Controller tests** : Test CRUD operations, authentication requirements, authorization checks
156+ - Use ` ActsAsTenant.with_tenant(@account) ` when testing multi-tenant models
157+ - Fixtures are loaded automatically from test/fixtures/* .yml
158+ - Test data seeds loaded from db/fixtures/test/* .rb in setup hook
109159
110160### Working with Multi-tenancy
111161- All models should include ` acts_as_tenant :account `
0 commit comments