Sha256: 5a0ec76bdb5ce026c91781c632171769e6db2937310d93ba83cfb3bdb58245f8

Contents?: true

Size: 1.39 KB

Versions: 20

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true
require "spec_helper"
require "generators/graphql/function_generator"

class GraphQLGeneratorsFunctionGeneratorTest < BaseGeneratorTest
  tests Graphql::Generators::FunctionGenerator

  test "it generates an empty function by name" do
    run_generator(["FindRecord"])

    expected_content = <<-RUBY
class Functions::FindRecord < GraphQL::Function
  # Define `initialize` to store field-level options, eg
  #
  #     field :myField, function: Functions::FindRecord.new(type: MyType)
  #
  # attr_reader :type
  # def initialize(type:)
  #   @type = type
  # end

  # add arguments by type:
  # argument :id, !types.ID

  # Resolve function:
  def call(obj, args, ctx)
  end
end
RUBY

    assert_file "app/graphql/functions/find_record.rb", expected_content
  end

  test "it generates a namespaced function by name" do
    run_generator(["finders::find_record"])

    expected_content = <<-RUBY
class Functions::Finders::FindRecord < GraphQL::Function
  # Define `initialize` to store field-level options, eg
  #
  #     field :myField, function: Functions::Finders::FindRecord.new(type: MyType)
  #
  # attr_reader :type
  # def initialize(type:)
  #   @type = type
  # end

  # add arguments by type:
  # argument :id, !types.ID

  # Resolve function:
  def call(obj, args, ctx)
  end
end
RUBY

    assert_file "app/graphql/functions/finders/find_record.rb", expected_content
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
graphql-1.8.1 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre11 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre10 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.14 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre9 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre8 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.13 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre7 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.12 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.11 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.10 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre6 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre5 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.9 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre4 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre3 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.8 spec/generators/graphql/function_generator_spec.rb
graphql-1.8.0.pre2 spec/generators/graphql/function_generator_spec.rb
graphql-1.7.7 spec/generators/graphql/function_generator_spec.rb