debian-mirror-gitlab/spec/support_specs/graphql/arguments_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.8 KiB
Ruby
Raw Permalink Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Graphql::Arguments do
it 'returns a blank string if the arguments are blank' do
args = described_class.new({})
2023-01-13 00:05:48 +05:30
expect(args.to_s).to be_blank
2021-02-22 17:27:13 +05:30
end
it 'returns a serialized arguments if the arguments are not blank' do
units = described_class.new({ temp: :CELSIUS, time: :MINUTES })
args = described_class.new({ temp: 180, time: 45, units: units })
2023-01-13 00:05:48 +05:30
expect(args.to_s).to eq('temp: 180, time: 45, units: {temp: CELSIUS, time: MINUTES}')
2021-02-22 17:27:13 +05:30
end
it 'supports merge with +' do
lhs = described_class.new({ a: 1, b: 2 })
rhs = described_class.new({ b: 3, c: 4 })
expect(lhs + rhs).to eq({ a: 1, b: 3, c: 4 })
end
it 'supports merge with + and a string' do
lhs = described_class.new({ a: 1, b: 2 })
rhs = 'x: no'
expect(lhs + rhs).to eq('a: 1, b: 2, x: no')
end
it 'supports merge with + and a string when empty' do
lhs = described_class.new({})
rhs = 'x: no'
expect(lhs + rhs).to eq('x: no')
end
it 'supports merge with + and an empty string' do
lhs = described_class.new({ a: 1 })
rhs = ''
expect(lhs + rhs).to eq({ a: 1 })
end
it 'serializes all values correctly' do
args = described_class.new({
array: [1, 2.5, "foo", nil, true, false, :BAR, { power: :on }],
hash: { a: 1, b: 2, c: 3 },
int: 42,
float: 2.7,
string: %q[he said "no"],
enum: :OFF,
2022-08-13 15:12:31 +05:30
null: nil,
2021-02-22 17:27:13 +05:30
bool_true: true,
bool_false: false,
var: ::Graphql::Var.new('x', 'Int')
})
expect(args.to_s).to eq([
%q(array: [1,2.5,"foo",null,true,false,BAR,{power: on}]),
%q(hash: {a: 1, b: 2, c: 3}),
'int: 42, float: 2.7',
%q(string: "he said \\"no\\""),
'enum: OFF',
2022-08-13 15:12:31 +05:30
'null: null',
2021-02-22 17:27:13 +05:30
'boolTrue: true, boolFalse: false',
'var: $x'
].join(', '))
end
end