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 @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added/Changed/Deprecated/Removed/Fixed/Security: YOUR CHANGE HERE
* 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

## [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`
* `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`

### Test examples

Expand Down
4 changes: 4 additions & 0 deletions lib/graphql_rails/rspec_controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def action_name
request.action_name
end

def context
request.context
end

private

attr_reader :request
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 '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
end

context 'when request was successful' do
it 'sets status to success' do
runner.query(:index, params: action_params, context: action_context)
Expand Down
Loading