Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed: do not throw "Cannot return null for non-nullable" error when errors are manually rendered
* Added: allow to specify type error hooks in router
* Added: `response.context` in RSpec controller helpers
* Added: `dig` on the RSpec controller helpers test context, as on `GraphQL::Query::Context`

## [3.1.0](2025-05-26)

Expand Down
2 changes: 1 addition & 1 deletion docs/testing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ There are 3 helper methods:

* `mutation(:your_controller_action_name, params: {}, context: {})`. `params` and `context` are optional
* `query(:your_controller_action_name, params: {}, context: {})`. `params` and `context` are optional
* `response`. Response is set only after you call `mutation` or `query`. It exposes, among others, `result`, `errors`, `success?`, `controller`, `action_name` and `context`: the hash-like test context the action ran with, not a `GraphQL::Query::Context`
* `response`. Response is set only after you call `mutation` or `query`. It exposes, among others, `result`, `errors`, `success?`, `controller`, `action_name` and `context`: the hash-like test context the action ran with (it supports `[]`, `fetch`, `key?`, `dig` and `to_h`), not a `GraphQL::Query::Context`

### Test examples

Expand Down
2 changes: 1 addition & 1 deletion lib/graphql_rails/rspec_controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class FakeContext

attr_reader :schema

def_delegators :@provided_values, :[], :[]=, :to_h, :key?, :fetch
def_delegators :@provided_values, :[], :[]=, :to_h, :key?, :fetch, :dig

def initialize(values:, schema:)
@errors = []
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/graphql_rails/rspec_controller_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def boom
expect(runner.response.action_name).to eq :index
end

it 'lets the context be read with dig' do
runner.query(:index, params: action_params, context: { api: { version: 2 } })
expect(runner.response.context.dig(:api, :version)).to eq 2
end

it 'includes the context the action ran with' do
runner.query(:index, params: action_params, context: action_context)
expect(runner.response.context.to_h).to eq action_context
Expand Down
Loading