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
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,7 @@ This repository contains the **Better Together Community Engine** (an isolated R
116
116
- **Use allow-lists for dynamic class resolution**: Follow the `joatu_source_class` pattern with concern-based allow-lists
117
117
- **Validate user inputs**: Always sanitize and validate parameters, especially for file uploads and dynamic queries
118
118
- **Strong parameters**: Use Rails strong parameters in all controllers
119
+
- **Model-level permitted attributes**: Prefer defining a class method `self.permitted_attributes` on models that returns the permitted attribute array (including nested attributes). Controllers and shared resource code should call `Model.permitted_attributes` rather than hard-coding permit lists. Compose nested permitted attributes by referencing other models' `permitted_attributes` (for example: `Conversation.permitted_attributes` may include `{ messages_attributes: Message.permitted_attributes }`).
119
120
- **Authorization everywhere**: Implement Pundit policy checks on all actions
120
121
- **SQL injection prevention**: Use parameterized queries, avoid string interpolation in SQL
121
122
- **XSS prevention**: Use Rails auto-escaping, sanitize HTML inputs with allowlists
@@ -205,6 +206,35 @@ This repository contains the **Better Together Community Engine** (an isolated R
205
206
- **Rails-Controller-Testing**: Add `gem 'rails-controller-testing'` to Gemfile for `assigns` method in controller tests.
206
207
- Toggle requires_invitation and provide invitation_code when needed for registration tests.
207
208
209
+
### Automatic test configuration & auth helper patterns
210
+
211
+
This repository provides an automatic test-configuration layer (see `spec/support/automatic_test_configuration.rb`) that sets up the host `Platform` and, where appropriate, performs authentication for request, controller, and feature specs so most specs do NOT need to call `configure_host_platform` manually.
212
+
213
+
- Automatic setup applies to specs with `type: :request`, `type: :controller`, and `type: :feature` by default.
214
+
- Use these example metadata tags to control authentication explicitly:
215
+
- `:as_platform_manager` or `:platform_manager` — login as the platform manager (elevated privileges)
216
+
- `:as_user`, `:authenticated`, or `:user` — login as a regular user
217
+
- `:no_auth` or `:unauthenticated` — ensure no authentication is performed for the example
218
+
- `:skip_host_setup` — skip host platform creation/configuration for this example
219
+
220
+
How it works:
221
+
- The test helper inspects example metadata and description text (describe/context). If the description contains keywords such as "platform manager", "admin", "authenticated", or "signed in", it will automatically set appropriate tags and perform the corresponding authentication.
222
+
- The helper creates a host `Platform` if one does not exist and marks the default setup wizard as completed.
223
+
- For request specs it uses HTTP login helpers (`login(email, password)`); for controller specs it uses Devise test helpers (`sign_in`); for feature specs it uses Capybara UI login flows.
224
+
225
+
Recommended usage:
226
+
- Prefer using metadata tags (`:as_platform_manager`, `:as_user`, `:skip_host_setup`) in the `describe` or `context` header when a test needs a specific authentication state. Example:
227
+
228
+
```ruby
229
+
RSpec.describe 'Creating a conversation', type: :request, :as_user do
230
+
# host platform and user login are automatically configured
231
+
end
232
+
```
233
+
234
+
- Avoid calling `configure_host_platform` manually in most specs; reserve manual calls for special cases (use `:skip_host_setup` to opt out of automatic config).
235
+
236
+
Note: The helper set lives under `spec/support/automatic_test_configuration.rb` and provides helpers like `configure_host_platform`, `find_or_create_test_user`, and `capybara_login_as_platform_manager` to use directly if needed by unusual tests.
237
+
208
238
### Testing Architecture Standards
209
239
- **Project Standard**: Use request specs (`type: :request`) for all controller testing to maintain consistency
210
240
- **Request Specs Advantages**: Handle Rails engine routing automatically through full HTTP stack
Copy file name to clipboardExpand all lines: AGENTS.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Instructions for GitHub Copilot and other automated contributors working in this
4
4
5
5
## Project
6
6
- Ruby: 3.4.4 (installed via rbenv in setup)
7
-
- Rails: 7.1
7
+
- Rails: 7.2
8
8
- Node: 20
9
9
- DB: PostgreSQL + PostGIS
10
10
- Search: Elasticsearch 7.17.23
@@ -50,6 +50,7 @@ Instructions for GitHub Copilot and other automated contributors working in this
50
50
- Use allow-lists for dynamic class resolution (see `joatu_source_class` pattern)
51
51
- Sanitize and validate all user inputs
52
52
- Use strong parameters in controllers
53
+
- Define model-level permitted attributes: prefer a class method `self.permitted_attributes` on models that returns the permitted attribute list (including nested attribute structures). Controllers should call `Model.permitted_attributes` to build permit lists instead of hard-coding them. When composing nested attributes, reference other models' `permitted_attributes` (for example: `Conversation.permitted_attributes` may include `{ messages_attributes: Message.permitted_attributes }`).
- **For reflection-based features**: Create concerns with `included_in_models` class methods for safe dynamic class resolution
55
56
- **Post-generation security check**: Run `bin/dc-run bundle exec brakeman --quiet --no-pager -c UnsafeReflection,SQL,CrossSiteScripting` after major code changes
@@ -226,6 +227,35 @@ For every implementation plan, create acceptance criteria covering relevant stak
226
227
- **Required for**: Controller specs, request specs, feature specs, and any integration tests that involve routing or authentication.
227
228
- **Locale Parameters**: Engine controller tests require locale parameters (e.g., `params: { locale: I18n.default_locale }`) due to routing constraints.
228
229
230
+
### Automatic test configuration & auth helper patterns
231
+
232
+
This repository provides an automatic test-configuration layer (see `spec/support/automatic_test_configuration.rb`) that sets up the host `Platform` and, where appropriate, performs authentication for request, controller, and feature specs so most specs do NOT need to call `configure_host_platform` manually.
233
+
234
+
- Automatic setup applies to specs with `type: :request`, `type: :controller`, and `type: :feature` by default.
235
+
- Use these example metadata tags to control authentication explicitly:
236
+
- `:as_platform_manager` or `:platform_manager` — login as the platform manager (elevated privileges)
237
+
- `:as_user`, `:authenticated`, or `:user` — login as a regular user
238
+
- `:no_auth` or `:unauthenticated` — ensure no authentication is performed for the example
239
+
- `:skip_host_setup` — skip host platform creation/configuration for this example
240
+
241
+
How it works:
242
+
- The test helper inspects example metadata and description text (describe/context). If the description contains keywords such as "platform manager", "admin", "authenticated", or "signed in", it will automatically set appropriate tags and perform the corresponding authentication.
243
+
- The helper creates a host `Platform` if one does not exist and marks the default setup wizard as completed.
244
+
- For request specs it uses HTTP login helpers (`login(email, password)`); for controller specs it uses Devise test helpers (`sign_in`); for feature specs it uses Capybara UI login flows.
245
+
246
+
Recommended usage:
247
+
- Prefer using metadata tags (`:as_platform_manager`, `:as_user`, `:skip_host_setup`) in the `describe` or `context` header when a test needs a specific authentication state. Example:
248
+
249
+
```ruby
250
+
RSpec.describe 'Creating a conversation', type: :request, :as_user do
251
+
# host platform and user login are automatically configured
252
+
end
253
+
```
254
+
255
+
- Avoid calling `configure_host_platform` manually in most specs; reserve manual calls for special cases (use `:skip_host_setup` to opt out of automatic config).
256
+
257
+
Note: The helper set lives under `spec/support/automatic_test_configuration.rb` and provides helpers like `configure_host_platform`, `find_or_create_test_user`, and `capybara_login_as_platform_manager` to use directly if needed by unusual tests.
258
+
229
259
## Test Coverage Standards
230
260
- **Models**: Test validations, associations, scopes, instance methods, class methods, and callbacks.
231
261
- **Controllers**: Test all actions, authorization policies, parameter handling, and response formats.
0 commit comments