Skip to content

Commit aa2307d

Browse files
authored
Merge branch 'main' into feature/new-content-blocks
Signed-off-by: Robert Smith <[email protected]>
2 parents dec06f7 + 79e1717 commit aa2307d

File tree

169 files changed

+5010
-494
lines changed

Some content is hidden

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

169 files changed

+5010
-494
lines changed

.github/copilot-instructions.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ This repository contains the **Better Together Community Engine** (an isolated R
116116
- **Use allow-lists for dynamic class resolution**: Follow the `joatu_source_class` pattern with concern-based allow-lists
117117
- **Validate user inputs**: Always sanitize and validate parameters, especially for file uploads and dynamic queries
118118
- **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 }`).
119120
- **Authorization everywhere**: Implement Pundit policy checks on all actions
120121
- **SQL injection prevention**: Use parameterized queries, avoid string interpolation in SQL
121122
- **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
205206
- **Rails-Controller-Testing**: Add `gem 'rails-controller-testing'` to Gemfile for `assigns` method in controller tests.
206207
- Toggle requires_invitation and provide invitation_code when needed for registration tests.
207208

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+
208238
### Testing Architecture Standards
209239
- **Project Standard**: Use request specs (`type: :request`) for all controller testing to maintain consistency
210240
- **Request Specs Advantages**: Handle Rails engine routing automatically through full HTTP stack

.github/workflows/rubyonrails.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ jobs:
1111
matrix:
1212
include:
1313
- ruby: '3.4.4'
14-
rails: '7.1.5.2'
14+
rails: '7.2.2.2'
1515
allowed_failure: false # ✅ required
16-
- ruby: '3.4.4'
17-
rails: '7.2.2.1'
18-
allowed_failure: false # ⚠️ allowed to fail
1916
- ruby: '3.4.4'
2017
rails: '8.0.2'
2118
allowed_failure: true # ⚠️ allowed to fail
@@ -52,18 +49,18 @@ jobs:
5249
with:
5350
ruby-version: ${{ matrix.ruby }}
5451

55-
# Run the automatic bundle-install only on 7.1.
52+
# Run the automatic bundle-install only on 7.2.
5653
# For 7.2 / 8.0 it just sets up Ruby *and* restores a cache layer
5754
# that we’ll reuse in the later manual install.
58-
bundler-cache: ${{ matrix.rails == '7.1.5.2' }}
55+
bundler-cache: ${{ matrix.rails == '7.2.2.2' }}
5956

6057
# One cache bucket per Rails version so they don’t clobber each other.
6158
cache-version: rails-${{ matrix.rails }}
6259

6360
# Updating Rails can legitimately blow up on the experimental tracks,
6461
# so we allow that *step* to error out without failing the job.
6562
- name: Update Rails & install gems
66-
if: matrix.rails != '7.1.5.2'
63+
if: matrix.rails != '7.2.2.2'
6764
id: update
6865
run: |
6966
# turn off deployment mode
@@ -75,21 +72,21 @@ jobs:
7572
continue-on-error: ${{ matrix.allowed_failure }}
7673

7774
- name: Prepare DB schema
78-
if: (matrix.rails == '7.1.5.2') || steps.update.outcome == 'success'
75+
if: (matrix.rails == '7.2.2.2') || steps.update.outcome == 'success'
7976
run: |
8077
rm -f spec/dummy/tmp/pids/server.pid
8178
bundle exec rake -f spec/dummy/Rakefile db:schema:load
8279
continue-on-error: ${{ matrix.allowed_failure }}
8380

8481
- name: Wait for Elasticsearch
85-
if: (matrix.rails == '7.1.5.2') || steps.update.outcome == 'success'
82+
if: (matrix.rails == '7.2.2.2') || steps.update.outcome == 'success'
8683
run: |
8784
echo "Waiting for Elasticsearch to be healthy..."
8885
curl -s "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=60s" || (echo "Elasticsearch not healthy" && exit 1)
8986

9087

9188
- name: Run RSpec
92-
if: (matrix.rails == '7.1.5.2') || steps.update.outcome == 'success'
89+
if: (matrix.rails == '7.2.2.2') || steps.update.outcome == 'success'
9390
env:
9491
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
9592
run: |

AGENTS.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Instructions for GitHub Copilot and other automated contributors working in this
44

55
## Project
66
- Ruby: 3.4.4 (installed via rbenv in setup)
7-
- Rails: 7.1
7+
- Rails: 7.2
88
- Node: 20
99
- DB: PostgreSQL + PostGIS
1010
- Search: Elasticsearch 7.17.23
@@ -50,6 +50,7 @@ Instructions for GitHub Copilot and other automated contributors working in this
5050
- Use allow-lists for dynamic class resolution (see `joatu_source_class` pattern)
5151
- Sanitize and validate all user inputs
5252
- 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 }`).
5354
- Implement proper authorization checks (Pundit policies)
5455
- **For reflection-based features**: Create concerns with `included_in_models` class methods for safe dynamic class resolution
5556
- **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
226227
- **Required for**: Controller specs, request specs, feature specs, and any integration tests that involve routing or authentication.
227228
- **Locale Parameters**: Engine controller tests require locale parameters (e.g., `params: { locale: I18n.default_locale }`) due to routing constraints.
228229

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+
229259
## Test Coverage Standards
230260
- **Models**: Test validations, associations, scopes, instance methods, class methods, and callbacks.
231261
- **Controllers**: Test all actions, authorization policies, parameter handling, and response formats.

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ gem 'pundit-resources', '~> 1.1.4', github: 'better-together-org/pundit-resource
2727

2828
# Core Rails gem
2929
gem 'rack-protection'
30-
gem 'rails', ENV.fetch('RAILS_VERSION', '7.1.5.2')
30+
gem 'rails', ENV.fetch('RAILS_VERSION', '7.2.2.2')
3131

3232
# Redis for ActionCable and background jobs
3333
gem 'redis', '~> 5.4'

0 commit comments

Comments
 (0)