spec/generators/graphql/install_generator_spec.rb in graphql-1.6.3 vs spec/generators/graphql/install_generator_spec.rb in graphql-1.6.4

- old
+ new

@@ -1,24 +1,23 @@ # frozen_string_literal: true require "spec_helper" require "generators/graphql/install_generator" class GraphQLGeneratorsInstallGeneratorTest < Rails::Generators::TestCase - tests Graphql::Generators::InstallGenerator destination File.expand_path("../../../tmp/dummy", File.dirname(__FILE__)) setup do prepare_destination - FileUtils.cd(File.expand_path("../../../tmp", File.dirname(__FILE__))) do - `rm -rf dummy` + + FileUtils.cd(File.join(destination_root, '..')) do `rails new dummy --skip-active-record --skip-test-unit --skip-spring --skip-bundle` end end test "it generates a folder structure" do - run_generator([]) + run_generator assert_file "app/graphql/types/.keep" assert_file "app/graphql/mutations/.keep" expected_query_route = %|post "/graphql", to: "graphql#execute"| expected_graphiql_route = %| @@ -91,10 +90,22 @@ assert_file "app/graphql/types/query_type.rb", expected_query_type assert_file "app/graphql/dummy_schema.rb", EXPECTED_RELAY_BATCH_SCHEMA end + test "it doesn't install graphiql when API Only" do + run_generator(['--api']) + + assert_file "Gemfile" do |contents| + refute_includes contents, "graphiql-rails" + end + + assert_file "config/routes.rb" do |contents| + refute_includes contents, "GraphiQL::Rails" + end + end + test "it can skip keeps, skip graphiql and customize schema name" do run_generator(["--skip-keeps", "--skip-graphiql", "--schema=CustomSchema"]) assert_no_file "app/graphql/types/.keep" assert_no_file "app/graphql/mutations/.keep" assert_file "app/graphql/types" @@ -114,14 +125,15 @@ EXPECTED_GRAPHQLS_CONTROLLER = <<-RUBY class GraphqlController < ApplicationController def execute variables = ensure_hash(params[:variables]) query = params[:query] + operation_name = params[:operationName] context = { # Query context goes here, for example: # current_user: current_user, } - result = DummySchema.execute(query, variables: variables, context: context) + result = DummySchema.execute(query, variables: variables, context: context, operation_name: operation_name) render json: result end private