Sha256: 777bbaf467e35d739ef42ac1cbc4e27d1293ede1437b1e442cc64d5210f5ef62

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

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

class GraphQLGeneratorsLoaderGeneratorTest < BaseGeneratorTest
  tests Graphql::Generators::LoaderGenerator

  test "it generates an empty loader by name" do
    run_generator(["RecordLoader"])

    expected_content = <<-RUBY
class Loaders::RecordLoader < GraphQL::Batch::Loader
  # Define `initialize` to store grouping arguments, eg
  #
  #     Loaders::RecordLoader.for(group).load(value)
  #
  # def initialize()
  # end

  # `keys` contains each key from `.load(key)`.
  # Find the corresponding values, then
  # call `fulfill(key, value)` or `fulfill(key, nil)`
  # for each key.
  def perform(keys)
  end
end
RUBY

    assert_file "app/graphql/loaders/record_loader.rb", expected_content
  end

  test "it generates a namespaced loader by name" do
    run_generator(["active_record::record_loader"])

    expected_content = <<-RUBY
class Loaders::ActiveRecord::RecordLoader < GraphQL::Batch::Loader
  # Define `initialize` to store grouping arguments, eg
  #
  #     Loaders::ActiveRecord::RecordLoader.for(group).load(value)
  #
  # def initialize()
  # end

  # `keys` contains each key from `.load(key)`.
  # Find the corresponding values, then
  # call `fulfill(key, value)` or `fulfill(key, nil)`
  # for each key.
  def perform(keys)
  end
end
RUBY

    assert_file "app/graphql/loaders/active_record/record_loader.rb", expected_content
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
graphql-1.8.0.pre4 spec/generators/graphql/loader_generator_spec.rb
graphql-1.8.0.pre3 spec/generators/graphql/loader_generator_spec.rb
graphql-1.7.8 spec/generators/graphql/loader_generator_spec.rb
graphql-1.8.0.pre2 spec/generators/graphql/loader_generator_spec.rb
graphql-1.7.7 spec/generators/graphql/loader_generator_spec.rb