Sha256: 0d43d62813ddb24380628c841b5221a2a0a49f49adbbfbf68b278f39d5ddbe0d

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require "spec_helper"

describe GraphQL::Define::AssignArgument do
  it "it accepts default_value" do
    arg = define_argument(:a, GraphQL::STRING_TYPE, default_value: 'Default')

    assert_equal "Default", arg.default_value
    assert arg.default_value?
  end

  it "default_value is optional" do
    arg = define_argument(:a, GraphQL::STRING_TYPE)

    assert arg.default_value.nil?
    assert !arg.default_value?
  end

  it "default_value can be explicitly set to nil" do
    arg = define_argument(:a, GraphQL::STRING_TYPE, default_value: nil)

    assert arg.default_value.nil?
    assert arg.default_value?
  end

  it "passing unknown keyword arguments will raise" do
    err = assert_raises ArgumentError do
      define_argument(:a, GraphQL::STRING_TYPE, blah: nil)
    end

    assert_equal 'unknown keyword: blah', err.message

    err = assert_raises ArgumentError do
      define_argument(:a, GraphQL::STRING_TYPE, blah: nil, blah2: nil)
    end

    assert_equal 'unknown keywords: blah, blah2', err.message
  end

  def define_argument(*args)
    type = GraphQL::ObjectType.define do
      field :a, types.String do
        argument(*args)
      end
    end

    type.fields['a'].arguments[args.first.to_s]
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/define/assign_argument_spec.rb
graphql-1.2.5 spec/graphql/define/assign_argument_spec.rb
graphql-1.2.4 spec/graphql/define/assign_argument_spec.rb
graphql-1.2.3 spec/graphql/define/assign_argument_spec.rb
graphql-1.2.2 spec/graphql/define/assign_argument_spec.rb
graphql-1.2.1 spec/graphql/define/assign_argument_spec.rb
graphql-1.2.0 spec/graphql/define/assign_argument_spec.rb