From dc939b1572c9b54fd1aeb543eb2ef20183ef5f6f Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Tue, 16 Jun 2026 15:06:55 -0700 Subject: [PATCH] Cover warehouse factory extension no-block paths --- .../schema_definition/factory_extension.rb | 10 ---- .../factory_extension_spec.rb | 60 +++++++++++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 elasticgraph-warehouse/spec/unit/elastic_graph/warehouse/schema_definition/factory_extension_spec.rb diff --git a/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb b/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb index 72d4cf033..3d95d4cd7 100644 --- a/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb +++ b/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb @@ -28,9 +28,7 @@ module FactoryExtension def new_enum_type(name) super(name) do |type| type.extend EnumTypeExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -59,9 +57,7 @@ def new_index(name, settings, type, &block) def new_interface_type(name) super(name) do |type| type.extend ObjectInterfaceAndUnionExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -73,9 +69,7 @@ def new_interface_type(name) def new_object_type(name) super(name) do |type| type.extend ObjectInterfaceAndUnionExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -87,9 +81,7 @@ def new_object_type(name) def new_scalar_type(name) super(name) do |type| type.extend ScalarTypeExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -101,9 +93,7 @@ def new_scalar_type(name) def new_union_type(name) super(name) do |type| type.extend ObjectInterfaceAndUnionExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end diff --git a/elasticgraph-warehouse/spec/unit/elastic_graph/warehouse/schema_definition/factory_extension_spec.rb b/elasticgraph-warehouse/spec/unit/elastic_graph/warehouse/schema_definition/factory_extension_spec.rb new file mode 100644 index 000000000..e63a8072b --- /dev/null +++ b/elasticgraph-warehouse/spec/unit/elastic_graph/warehouse/schema_definition/factory_extension_spec.rb @@ -0,0 +1,60 @@ +# Copyright 2024 - 2026 Block, Inc. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. +# +# frozen_string_literal: true + +require "elastic_graph/spec_support/schema_definition_helpers" +require "elastic_graph/warehouse/schema_definition/api_extension" + +module ElasticGraph + module Warehouse + module SchemaDefinition + RSpec.describe FactoryExtension do + include_context "SchemaDefinitionHelpers" + + it "extends enum types created without customization blocks" do + define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api| + api.enum_type "Status" + + expect(api.state.enum_types_by_name.fetch("Status")).to be_a(EnumTypeExtension) + end + end + + it "extends interface types created without customization blocks" do + define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api| + api.interface_type "Identifiable" + + expect(api.state.object_types_by_name.fetch("Identifiable")).to be_a(ObjectInterfaceAndUnionExtension) + end + end + + it "extends object types created without customization blocks" do + define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api| + api.object_type "Widget" + + expect(api.state.object_types_by_name.fetch("Widget")).to be_a(ObjectInterfaceAndUnionExtension) + end + end + + it "allows scalar type validation to fail normally without a customization block" do + define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api| + expect { + api.scalar_type "Money" + }.to raise_error(Errors::SchemaError, a_string_including("Scalar types require `mapping` to be configured")) + end + end + + it "extends union types created without customization blocks" do + define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api| + api.union_type "SearchResult" + + expect(api.state.object_types_by_name.fetch("SearchResult")).to be_a(ObjectInterfaceAndUnionExtension) + end + end + end + end + end +end