Module: ActiveShopifyGraphQL::Testing

Defined in:
lib/active_shopify_graphql/testing.rb,
lib/active_shopify_graphql/testing/hook.rb,
lib/active_shopify_graphql/testing/store.rb,
lib/active_shopify_graphql/testing/test_loader.rb

Overview

Testing support module that provides an in-memory store for test data, allowing developers to register records using Ruby-level attributes and have find, where, includes, and connections work transparently without real API calls.

Examples:

In spec_helper.rb

require 'active_shopify_graphql/testing'

RSpec.configure do |config|
  config.before(:each) { ActiveShopifyGraphQL::Testing.enable! }
  config.after(:each)  { ActiveShopifyGraphQL::Testing.reset! }
end

In tests

ActiveShopifyGraphQL::Testing.register(Customer, [
  { id: 1, email: "[email protected]", display_name: "John" }
])
Customer.find(1) # => Customer instance from the store

Defined Under Namespace

Modules: AttributesHook, FinderMethodsHook, GraphqlTypeResolverHook, LoaderSwitchableHook Classes: Store, TestLoader

Class Method Summary collapse

Class Method Details

.enable!Object



29
30
31
# File 'lib/active_shopify_graphql/testing.rb', line 29

def enable!
  @enabled = true
end

.enabled?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/active_shopify_graphql/testing.rb', line 38

def enabled?
  @enabled == true
end

.register(model_class, records) ⇒ Object

Convenience delegate to store.register



47
48
49
# File 'lib/active_shopify_graphql/testing.rb', line 47

def register(model_class, records)
  store.register(model_class, records)
end

.reset!Object



33
34
35
36
# File 'lib/active_shopify_graphql/testing.rb', line 33

def reset!
  @enabled = false
  store.clear
end

.storeObject



42
43
44
# File 'lib/active_shopify_graphql/testing.rb', line 42

def store
  @store ||= Store.new
end