Skip to content

Commit 111b152

Browse files
authored
Merge pull request #13 from nativeapptemplate/add_tests
Add comprehensive test coverage across models, policies, and controllers
2 parents 8622778 + 0c01db6 commit 111b152

54 files changed

Lines changed: 4116 additions & 141 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,19 @@ yarn-debug.log*
5050
*~
5151

5252
# Claude
53-
.claude/
53+
# Personal Claude Code settings
54+
.claude/settings.local.json
55+
.claude/CLAUDE.local.md
56+
57+
# Sensitive data and generated files within skills
58+
.claude/skills/*/.venv/
59+
.claude/skills/*/venv/
60+
.claude/skills/*/node_modules/
61+
.claude/skills/*/data/
62+
.claude/skills/*/auth_info.json
63+
.claude/skills/*/__pycache__/
64+
65+
# Logs and temporary files
66+
.claude/logs/
67+
.claude/tmp/
68+
.claude/*.log

CLAUDE.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
104146
1. Add route in `config/routes.rb` under appropriate namespace
105147
2. 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
107149
4. 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`

Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
44
ruby file: ".ruby-version"
55

66
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7-
gem "rails", "7.1.5.1"
7+
gem "rails", "~> 7.2.3"
88

99
gem "propshaft", "~> 1.0"
1010

@@ -78,6 +78,9 @@ group :development, :test do
7878

7979
gem "mailbin"
8080

81+
# Constrain minitest to 5.x for Rails 7.2 compatibility
82+
gem "minitest", "~> 5.0"
83+
8184
# Optional debugging tools
8285
# gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
8386
# gem "pry-rails"

0 commit comments

Comments
 (0)