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
@@ -12,26 +12,37 @@ Instructions for GitHub Copilot and other automated contributors working in this
12
12
13
13
## Setup
14
14
- Environment runs a setup script that installs Ruby 3.4.4, Node 20, Postgres + PostGIS, and ES7, then prepares databases.
15
+
-**Docker Environment**: All commands requiring database access must use `bin/dc-run` to execute within the containerized environment.
16
+
-**Dummy App Commands**: Use `bin/dc-run-dummy` for Rails commands that need the dummy app context (e.g., `bin/dc-run-dummy rails console`, `bin/dc-run-dummy rails db:migrate`).
15
17
- Databases:
16
18
- development: `community_engine_development`
17
19
- test: `community_engine_test`
18
20
- Use `DATABASE_URL` to connect (overrides fallback host in `config/database.yml`).
- Multiple specific lines: `bin/dc-run bundle exec rspec spec/file1_spec.rb:123 spec/file2_spec.rb:456`
30
+
-**Important**: RSpec does NOT support hyphenated line numbers (e.g., `spec/file_spec.rb:123-456` is INVALID)
31
+
-**Do NOT use `-v` flag**: The `-v` flag displays RSpec version information, NOT verbose output. Use `--format documentation` for detailed test descriptions.
32
+
-**Rails Console:**`bin/dc-run-dummy rails console` (runs console in the dummy app context)
33
+
-**Rails Commands in Dummy App:**`bin/dc-run-dummy rails [command]` for any Rails commands that need the dummy app environment
-**For reflection-based features**: Create concerns with `included_in_models` class methods for safe dynamic class resolution
44
-
-**Post-generation security check**: Run `bundle exec brakeman --quiet --no-pager -c UnsafeReflection,SQL,CrossSiteScripting` after major code changes
55
+
-**Post-generation security check**: Run `bin/dc-run bundle exec brakeman --quiet --no-pager -c UnsafeReflection,SQL,CrossSiteScripting` after major code changes
45
56
46
57
## Conventions
47
58
- Make incremental changes with passing tests.
48
-
-**Security first**: Run `bundle exec brakeman --quiet --no-pager` before committing code changes.
59
+
-**Security first**: Run `bin/dc-run bundle exec brakeman --quiet --no-pager` before committing code changes.
49
60
-**Test every change**: Generate RSpec tests for all code modifications, including models, controllers, mailers, jobs, and JavaScript.
50
61
-**Test coverage requirements**: All new features, bug fixes, and refactors must include comprehensive test coverage.
51
62
- Avoid introducing new external services in tests; stub where possible.
@@ -150,14 +161,14 @@ We use the `i18n-tasks` gem to ensure all translation keys are present, normaliz
150
161
151
162
## Example Commands
152
163
```bash
153
-
i18n-tasks normalize
154
-
i18n-tasks missing
155
-
i18n-tasks add-missing
156
-
i18n-tasks health
164
+
bin/dc-run i18n-tasks normalize
165
+
bin/dc-run i18n-tasks missing
166
+
bin/dc-run i18n-tasks add-missing
167
+
bin/dc-run i18n-tasks health
157
168
```
158
169
159
170
## CI Note
160
-
- The i18n GitHub Action installs dev/test gem groups to make `i18n-tasks` available. Locally, you can mirror CI with `bin/i18n`, which sets `BUNDLE_WITH=development:test` automatically.
171
+
- The i18n GitHub Action installs dev/test gem groups to make `i18n-tasks` available. Locally, you can mirror CI with `bin/dc-run bin/i18n`, which sets `BUNDLE_WITH=development:test` automatically.
161
172
162
173
See `.github/instructions/i18n-mobility.instructions.md` for additional translation rules.
163
174
@@ -199,6 +210,22 @@ For every implementation plan, create acceptance criteria covering relevant stak
199
210
-**Test all layers**: models (validations, associations, methods), controllers (actions, authorization), services, mailers, jobs, and view components.
200
211
-**JavaScript/Stimulus testing**: Include feature specs that exercise dynamic behaviors like form interactions and AJAX updates.
201
212
213
+
## Test Environment Requirements
214
+
-**Host Platform Configuration**: All controller, request, and feature tests MUST configure the host platform/community before testing.
215
+
-**Use `configure_host_platform`**: Call this helper method in a `before` block for any test that makes HTTP requests or tests authentication/authorization.
216
+
-**DeviseSessionHelpers**: Include this module and use authentication helpers like `login('[email protected]', 'password')` for authenticated tests.
217
+
-**Platform Setup Pattern**:
218
+
```ruby
219
+
RSpec.describe BetterTogether::SomeControllerdo
220
+
before do
221
+
configure_host_platform # Creates host platform with community
### Critical Testing Pattern: Request Specs vs Controller Specs
343
+
- **Project Standard**: All tests use request specs (`type: :request`) for consistency with Rails engine routing
344
+
- **Exception Handling**: Controller specs (`type: :controller`) require special URL helper configuration in Rails engines
345
+
- **Why This Matters**: Request specs handle Rails engine routing automatically through the full HTTP stack, while controller specs test in isolation and need explicit configuration
346
+
- **Debugging Indicator**: If you see `default_url_options` errors only in one spec while others pass, check if it's a controller spec in a request spec codebase
347
+
348
+
### Rails Engine URL Helper Configuration
349
+
- **Problem**: Controller specs in Rails engines throw `default_url_options` errors that request specs don't encounter
350
+
- **Root Cause**: Engines need special URL helper setup for controller specs but not request specs
351
+
- **Solution Patterns**:
352
+
```ruby
353
+
# For controller spec assertions, use pattern matching instead of path helpers:
354
+
expect(response.location).to include('/person_blocks') # Good
355
+
expect(response).to redirect_to(person_blocks_path) # Problematic in controller specs
-**Special Cases**: If controller specs are needed, prepare for URL helper configuration complexity
391
+
-**Debugging Approach**: When testing errors occur in only one spec, compare its type and setup to working specs
392
+
393
+
## Docker Environment Usage
394
+
-**All database-dependent commands must use `bin/dc-run`**: This includes tests, generators, and any command that connects to PostgreSQL, Redis, or Elasticsearch
395
+
-**Dummy app commands use `bin/dc-run-dummy`**: For Rails commands that need the dummy app context (console, migrations specific to dummy app)
396
+
-**Examples of commands requiring `bin/dc-run`**:
397
+
- Tests: `bin/dc-run bundle exec rspec`
398
+
- Generators: `bin/dc-run rails generate model User`
399
+
- Brakeman: `bin/dc-run bundle exec brakeman`
400
+
- RuboCop: `bin/dc-run bundle exec rubocop`
401
+
-**Examples of commands requiring `bin/dc-run-dummy`**:
0 commit comments