Add RSpec test suite for existing functionality - #2
Merged
Conversation
Set up RSpec from scratch (the gem had no test infrastructure) and cover the pure-Ruby and model-level units: - Configuration: defaults, mount_strategy validation, authentication_enabled? - ActiveAdminMcp module: config memoization and configure - RequestHandler: JSON-RPC dispatch, both tools, limit capping, error paths - ResourceRegistry: sensitive-attribute filtering, resource discovery guards - ApiToken: digest/token generation, validations, find_by_raw_token, throttle ApiToken specs run against an in-memory SQLite schema; everything else is pure unit tests with stubs. Controller/engine request specs are omitted as they require a full Rails/ActiveAdmin host app. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Runs bundle exec rspec on push to main and on pull requests, across Ruby 3.1–3.4. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lloydwatkin
added a commit
that referenced
this pull request
Aug 14, 2026
## Summary
Adds a basic `update` MCP tool — the first write operation — that
modifies a single record while enforcing the **same three rules as the
ActiveAdmin UI**:
1. **Editable resources only** — refused unless the resource exposes the
`:update` action (`resource.defined_actions`). Resources registered
`actions :index, :show` stay read-only.
2. **Authorization** — the update runs through the resource namespace's
authorization adapter (`adapter.new(config,
current_user).authorized?(:update, record)`), so CanCanCan/Pundit rules
apply for the authenticated MCP user.
3. **Permitted fields only** — attributes are filtered through the
resource's `permit_params` by driving ActiveAdmin's own
`permitted_params`, so only fields the admin form accepts are written.
Anything else is dropped (fails closed if permit params can't be
resolved).
Validation failures return the record's `full_messages`; unknown
resource / missing record / missing args return clear errors.
## Usage
```
update(resource: "User", id: 42, attributes: { name: "New name" })
```
## Changes
- `lib/active_admin_mcp/record_updater.rb` *(new)* — the gating + update
logic
- `lib/active_admin_mcp/request_handler.rb` — new `update` tool schema +
dispatch; threads `current_user` in via the constructor
- `lib/active_admin_mcp/resource_registry.rb` — `find` now also returns
the ActiveAdmin resource `config` so the updater can inspect
actions/authorization
- `app/controllers/active_admin_mcp/mcp_controller.rb` — passes
`current_mcp_user` to the handler
- `README.md` — documents the tool and its rules
## Tests
**59 examples, 0 failures.**
- New `record_updater_spec.rb` (8 examples) covering each gate,
validation failures, permitted-field filtering, and an
`error`-named-attribute regression
- Updated `request_handler_spec.rb` — `tools/list` now includes
`update`, plus dispatch coverage; updated `resource_registry_spec.rb`
for the new `find` contract
## Note — stacked on #2
This branch is built on top of the RSpec suite from #2, so the diff
currently also includes those spec-infrastructure commits. Once #2 is
merged to `main`, this diff will reduce to just the `update` feature.
Please merge #2 first.
## Follow-up
The permit-params path is unit-tested against a controller double, not a
live ActiveAdmin controller (booting a full AA dummy app is a larger
lift and needs its own harness). A dummy-app-backed integration spec for
`permitted_params` and the end-to-end update flow is a sensible
follow-up before relying on this in production.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The gem had no test infrastructure. This sets up RSpec from scratch and adds coverage for the existing pure-Ruby and model-level units — 46 examples, all passing.
Run with
bundle exec rspec.What's covered
Configurationmount_strategy=validation (raises + lists valid values),authentication_enabled?ActiveAdminMcpmoduleconfigmemoization,configureyields and persistsRequestHandlerinitialize,ping,tools/list,notifications/initialized→nil, unknown method→-32601), both tools, limit defaulting/capping (25/100), empty-Ransack default, resource-not-found, unknown-toolResourceRegistry:adminnamespace,ActiveAdminundefined,findhits/missesApiTokendigest, token generation + digest-only storage, validations,find_by_raw_token(match/miss/blank),touch_last_used!throttleSetup
rspecandsqlite3as dev dependencies.ApiTokenspecs run against an in-memory SQLite schema; everything else is pure unit tests with stubs/doubles.spec_helperresets the memoized global config between examples so config-touching specs don't leak state.Notes / gaps
McpControllerorEnginerequest-level specs — those need a full Rails/ActiveAdmin host app to test meaningfully. The controller's auth path is indirectly covered by theApiTokenandConfigurationunit tests. Worth adding a dummy-app-backed request spec later for end-to-end coverage of the Bearer-token flow.🤖 Generated with Claude Code