diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/support_specs/graphql/arguments_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/support_specs/graphql/arguments_spec.rb')
-rw-r--r-- | spec/support_specs/graphql/arguments_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/support_specs/graphql/arguments_spec.rb b/spec/support_specs/graphql/arguments_spec.rb new file mode 100644 index 00000000000..ffb58503a0e --- /dev/null +++ b/spec/support_specs/graphql/arguments_spec.rb @@ -0,0 +1,71 @@ +# 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({}) + + expect("#{args}").to be_blank + 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 }) + + expect("#{args}").to eq('temp: 180, time: 45, units: {temp: CELSIUS, time: MINUTES}') + 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, + null: nil, # we expect this to be omitted - absence is the same as explicit nullness + 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', + 'boolTrue: true, boolFalse: false', + 'var: $x' + ].join(', ')) + end +end |