From a8f35dfd22246d0754e4445e15bd8cbd93c9972c Mon Sep 17 00:00:00 2001 From: Povilas Jurcys Date: Mon, 19 Oct 2026 06:56:44 +0300 Subject: [PATCH 1/3] Refs #BAC-530: Expose the request context on the RSpec controller helpers response Matchers that judge a response need the context the action ran with, e.g. to call model fields that read graphql_context. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + docs/testing/testing.md | 2 +- lib/graphql_rails/rspec_controller_helpers.rb | 4 ++++ spec/lib/graphql_rails/rspec_controller_helpers_spec.rb | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9deb379c..e7dda393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/docs/testing/testing.md b/docs/testing/testing.md index 49a5f4aa..645ad5ca 100644 --- a/docs/testing/testing.md +++ b/docs/testing/testing.md @@ -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 `result`, `errors`, `controller`, `action_name` and the request's `context` ### Test examples diff --git a/lib/graphql_rails/rspec_controller_helpers.rb b/lib/graphql_rails/rspec_controller_helpers.rb index d519b8ff..2e77fb1f 100644 --- a/lib/graphql_rails/rspec_controller_helpers.rb +++ b/lib/graphql_rails/rspec_controller_helpers.rb @@ -54,6 +54,10 @@ def action_name request.action_name end + def context + request.context + end + private attr_reader :request diff --git a/spec/lib/graphql_rails/rspec_controller_helpers_spec.rb b/spec/lib/graphql_rails/rspec_controller_helpers_spec.rb index bd1583fe..cbf90762 100644 --- a/spec/lib/graphql_rails/rspec_controller_helpers_spec.rb +++ b/spec/lib/graphql_rails/rspec_controller_helpers_spec.rb @@ -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) From 1b6e82400baa34e4bbf27e4900f8e9546abdfe64 Mon Sep 17 00:00:00 2001 From: Povilas Jurcys Date: Mon, 19 Oct 2026 07:15:15 +0300 Subject: [PATCH 2/3] Refs #BAC-530: Say response.context is the hash-like test context Co-Authored-By: Claude Opus 5.5 --- docs/testing/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/testing/testing.md b/docs/testing/testing.md index 645ad5ca..0ddd7c67 100644 --- a/docs/testing/testing.md +++ b/docs/testing/testing.md @@ -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 `result`, `errors`, `controller`, `action_name` and the request's `context` +* `response`. Response is set only after you call `mutation` or `query`. It exposes `result`, `errors`, `controller`, `action_name` and `context`: the hash-like test context the action ran with, not a `GraphQL::Query::Context` ### Test examples From 497b80e5f2aaba55420509efd0412a14d44a4dc2 Mon Sep 17 00:00:00 2001 From: Povilas Jurcys Date: Mon, 19 Oct 2026 07:18:43 +0300 Subject: [PATCH 3/3] Refs #BAC-530: List response predicates in the testing docs Co-Authored-By: Claude Opus 5.5 --- docs/testing/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/testing/testing.md b/docs/testing/testing.md index 0ddd7c67..c538a385 100644 --- a/docs/testing/testing.md +++ b/docs/testing/testing.md @@ -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 `result`, `errors`, `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, not a `GraphQL::Query::Context` ### Test examples