Repository navigation
Add testing support - #53
Merged
Merged
Conversation
Exclude the testing directory and entry point from Zeitwerk autoloading so it is only activated via explicit `require 'active_shopify_graphql/testing'`. This keeps the testing module out of production code paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Store holds test records keyed by model class with GID-normalized IDs. Supports find by ID, hash/string where filtering, and extracting inline connection data from parent records. Comparison uses .to_s for flexible ID matching between integers and strings. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TestLoader extends Loader and overrides load_attributes, load_paginated_collection, and load_connection_records to serve data from the testing Store. Supports eager-loaded and lazy-loaded connections, nested includes, inverse_of wiring, and cursor-based pagination. Raises if perform_graphql_query is ever called. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
LoaderSwitchableHook overrides default_loader_class to return TestLoader when testing is enabled (used by Relation#build_loader). FinderMethodsHook overrides default_loader to return fresh TestLoader instances (used by Connections for lazy loading), preventing memoization leaks between tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entry point that wires everything together: requires sub-files, defines the Testing module with enable!/reset!/register API, and applies the prepend hooks onto LoaderSwitchable and FinderMethods at load time. Only activated via explicit require. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Covers: enable!/reset!/enabled? lifecycle, ID normalization, find/where/find_by, search field filtering (non-attribute keys), eager-loaded and lazy-loaded connections, pagination, GraphQL query guard, test isolation, and disabled state fallback to AdminApiLoader. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add setup instructions, data registration examples, and usage patterns for the new in-memory testing module. Keeps the existing manual mocking approach as a simpler alternative. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Disable Lint/UnusedMethodArgument inline for sort_key and reverse params in load_paginated_collection — they must match the parent class signature but aren't used by the in-memory implementation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
nirebu
force-pushed
the
nirebu/testing-support
branch
from
March 25, 2026 15:19
3c67feb to
4d3cc1c
Compare
nirebu
marked this pull request as ready for review
March 25, 2026 15:39
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.
Closes #45
This pull request introduces a comprehensive, built-in testing framework for
active_shopify_graphql, enabling developers to register and use in-memory test data for models and their associations. It allows all major query patterns (find,where,find_by,includes, and connections) to work transparently in tests without making real API calls. The framework is modular, extensible, and integrates with RSpec or other test setups via simple enable/reset hooks.