protobuf-cucumber 3.10.4 → 3.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d5f47cc32a8f84f7c2a2cd64f483ef150aea5a981ffc7cdca01481a8b94c75d
4
- data.tar.gz: 866f9b48ff06138d972914353fb94ee7d29a0a08e2318d204d79ae1f6be3d994
3
+ metadata.gz: fc5a3e75ddaabfabd15289e76ddf4c16ae40a5a8107c515d8cb605a90bf51716
4
+ data.tar.gz: 6feeaf6f26b112f74b117155eafd1219b2407e9b3c23b8bbdbcfe865498924a9
5
5
  SHA512:
6
- metadata.gz: f01a5f01d801feb5dfefc5ab246e8bca0c75b0a12780de746f7a76b8b8a8bc5bad0298d32946a79c4311adacce9cdc7293024a4582ffd0c3a1eecdd70153c2ec
7
- data.tar.gz: 6eddd168836a9e1f21658d75fe094868872fce43702e6254aee044e9fa2eb8fe0cf47e6222255ff18bdc6e687a19c6456c51ed5d7f96256cfdb2312f2b324a50
6
+ metadata.gz: 5f489187daae60da534b03eec2ba25e2cb5800d3e27496e5340e4a18bf3573f5dda1e0986bc87e79d3e85ccd477b8ce022c275135e4c863443b1accba1962cb9
7
+ data.tar.gz: cb46bbeeac294ba9a5dd7b70d2a01b9ebbd3e742ff64ca1ae72d78d36bef9afd1c4c4d417be19d8c1052416c952952ac0872c75f00347df45eb00e5a2819b882
@@ -29,6 +29,13 @@ module Protobuf
29
29
  return false
30
30
  end
31
31
 
32
+ def json_encode(value, options = {})
33
+ if options[:proto3]
34
+ value == 0 ? nil : value.to_s
35
+ else
36
+ value
37
+ end
38
+ end
32
39
  end
33
40
  end
34
41
  end
@@ -16,6 +16,13 @@ module Protobuf
16
16
  INT64_MIN
17
17
  end
18
18
 
19
+ def json_encode(value, options = {})
20
+ if options[:proto3]
21
+ value == 0 ? nil : value.to_s
22
+ else
23
+ value
24
+ end
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -16,6 +16,13 @@ module Protobuf
16
16
  0
17
17
  end
18
18
 
19
+ def json_encode(value, options = {})
20
+ if options[:proto3]
21
+ value == 0 ? nil : value.to_s
22
+ else
23
+ value
24
+ end
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -158,7 +158,7 @@ module Protobuf
158
158
  def to_json_hash(options = {})
159
159
  result = {}
160
160
 
161
- lower_camel_case = options[:lower_camel_case]
161
+ proto3 = options[:proto3] || options[:lower_camel_case]
162
162
 
163
163
  @values.each_key do |field_name|
164
164
  value = self[field_name]
@@ -169,13 +169,17 @@ module Protobuf
169
169
  hashed_value = if value.respond_to?(:to_json_hash_value) && !field.is_a?(::Protobuf::Field::EnumField)
170
170
  value.to_json_hash_value(options)
171
171
  elsif field.respond_to?(:json_encode)
172
- field.json_encode(value)
172
+ field.json_encode(value, options)
173
173
  else
174
174
  value
175
175
  end
176
176
 
177
- key = lower_camel_case ? field.name.to_s.camelize(:lower).to_sym : field.name
178
- result[key] = hashed_value
177
+ if proto3 && (hashed_value.nil? || value == field.default)
178
+ result.delete(field.name)
179
+ else
180
+ key = proto3 ? field.name.to_s.camelize(:lower).to_sym : field.name
181
+ result[key] = hashed_value
182
+ end
179
183
  end
180
184
 
181
185
  result
@@ -1,3 +1,3 @@
1
1
  module Protobuf
2
- VERSION = '3.10.4' # rubocop:disable Style/MutableConstant
2
+ VERSION = '3.10.5' # rubocop:disable Style/MutableConstant
3
3
  end
@@ -4,4 +4,30 @@ RSpec.describe Protobuf::Field::Fixed64Field do
4
4
 
5
5
  it_behaves_like :packable_field, described_class
6
6
 
7
+ let(:message) do
8
+ Class.new(::Protobuf::Message) do
9
+ optional :fixed64, :some_field, 1
10
+ end
11
+ end
12
+
13
+ # https://developers.google.com/protocol-buffers/docs/proto3#json
14
+ describe '.{to_json, from_json}' do
15
+ it 'serialises 0' do
16
+ instance = message.new(some_field: 0)
17
+ expect(instance.to_json(proto3: true)).to eq('{}')
18
+ expect(instance.to_json).to eq('{"some_field":0}')
19
+ end
20
+
21
+ it 'serialises max value' do
22
+ instance = message.new(some_field: described_class.max)
23
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"18446744073709551615"}')
24
+ expect(instance.to_json).to eq('{"some_field":18446744073709551615}')
25
+ end
26
+
27
+ it 'serialises min value' do
28
+ instance = message.new(some_field: described_class.min)
29
+ expect(instance.to_json(proto3: true)).to eq('{}')
30
+ expect(instance.to_json).to eq('{"some_field":0}')
31
+ end
32
+ end
7
33
  end
@@ -4,4 +4,30 @@ RSpec.describe Protobuf::Field::Int64Field do
4
4
 
5
5
  it_behaves_like :packable_field, described_class
6
6
 
7
+ let(:message) do
8
+ Class.new(::Protobuf::Message) do
9
+ optional :int64, :some_field, 1
10
+ end
11
+ end
12
+
13
+ # https://developers.google.com/protocol-buffers/docs/proto3#json
14
+ describe '.{to_json, from_json}' do
15
+ it 'serialises 0' do
16
+ instance = message.new(some_field: 0)
17
+ expect(instance.to_json(proto3: true)).to eq('{}')
18
+ expect(instance.to_json).to eq('{"some_field":0}')
19
+ end
20
+
21
+ it 'serialises max value' do
22
+ instance = message.new(some_field: described_class.max)
23
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"9223372036854775807"}')
24
+ expect(instance.to_json).to eq('{"some_field":9223372036854775807}')
25
+ end
26
+
27
+ it 'serialises min value' do
28
+ instance = message.new(some_field: described_class.min)
29
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"-9223372036854775808"}')
30
+ expect(instance.to_json).to eq('{"some_field":-9223372036854775808}')
31
+ end
32
+ end
7
33
  end
@@ -6,4 +6,30 @@ RSpec.describe Protobuf::Field::Sfixed64Field do
6
6
  let(:value) { [-1, 0, 1] }
7
7
  end
8
8
 
9
+ let(:message) do
10
+ Class.new(::Protobuf::Message) do
11
+ optional :sfixed64, :some_field, 1
12
+ end
13
+ end
14
+
15
+ # https://developers.google.com/protocol-buffers/docs/proto3#json
16
+ describe '.{to_json, from_json}' do
17
+ it 'serialises 0' do
18
+ instance = message.new(some_field: 0)
19
+ expect(instance.to_json(proto3: true)).to eq('{}')
20
+ expect(instance.to_json).to eq('{"some_field":0}')
21
+ end
22
+
23
+ it 'serialises max value' do
24
+ instance = message.new(some_field: described_class.max)
25
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"9223372036854775807"}')
26
+ expect(instance.to_json).to eq('{"some_field":9223372036854775807}')
27
+ end
28
+
29
+ it 'serialises min value as string' do
30
+ instance = message.new(some_field: described_class.min)
31
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"-9223372036854775808"}')
32
+ expect(instance.to_json).to eq('{"some_field":-9223372036854775808}')
33
+ end
34
+ end
9
35
  end
@@ -6,4 +6,30 @@ RSpec.describe Protobuf::Field::Sint64Field do
6
6
  let(:value) { [-1, 0, 1] }
7
7
  end
8
8
 
9
+ let(:message) do
10
+ Class.new(::Protobuf::Message) do
11
+ optional :sint64, :some_field, 1
12
+ end
13
+ end
14
+
15
+ # https://developers.google.com/protocol-buffers/docs/proto3#json
16
+ describe '.{to_json, from_json}' do
17
+ it 'serialises 0' do
18
+ instance = message.new(some_field: 0)
19
+ expect(instance.to_json(proto3: true)).to eq('{}')
20
+ expect(instance.to_json).to eq('{"some_field":0}')
21
+ end
22
+
23
+ it 'serialises max value as string' do
24
+ instance = message.new(some_field: described_class.max)
25
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"9223372036854775807"}')
26
+ expect(instance.to_json).to eq('{"some_field":9223372036854775807}')
27
+ end
28
+
29
+ it 'serialises min value as string' do
30
+ instance = message.new(some_field: described_class.min)
31
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"-9223372036854775808"}')
32
+ expect(instance.to_json).to eq('{"some_field":-9223372036854775808}')
33
+ end
34
+ end
9
35
  end
@@ -4,4 +4,30 @@ RSpec.describe Protobuf::Field::Uint64Field do
4
4
 
5
5
  it_behaves_like :packable_field, described_class
6
6
 
7
+ let(:message) do
8
+ Class.new(::Protobuf::Message) do
9
+ optional :uint64, :some_field, 1
10
+ end
11
+ end
12
+
13
+ # https://developers.google.com/protocol-buffers/docs/proto3#json
14
+ describe '.{to_json, from_json}' do
15
+ it 'serialises 0' do
16
+ instance = message.new(some_field: 0)
17
+ expect(instance.to_json(proto3: true)).to eq('{}')
18
+ expect(instance.to_json).to eq('{"some_field":0}')
19
+ end
20
+
21
+ it 'serialises max value' do
22
+ instance = message.new(some_field: described_class.max)
23
+ expect(instance.to_json(proto3: true)).to eq('{"someField":"18446744073709551615"}')
24
+ expect(instance.to_json).to eq('{"some_field":18446744073709551615}')
25
+ end
26
+
27
+ it 'serialises min value' do
28
+ instance = message.new(some_field: described_class.min)
29
+ expect(instance.to_json(proto3: true)).to eq('{}')
30
+ expect(instance.to_json).to eq('{"some_field":0}')
31
+ end
32
+ end
7
33
  end
@@ -438,14 +438,14 @@ RSpec.describe Protobuf::Message do
438
438
  specify { expect(subject.to_json).to eq '{"widget_bytes":["Bo0xSFAXOmI="]}' }
439
439
  end
440
440
 
441
- context 'using lower camel case field names' do
441
+ context 'using proto3 produces lower case field names' do
442
442
  let(:bytes) { "\x06\x8D1HP\x17:b".force_encoding(Encoding::ASCII_8BIT) }
443
443
 
444
444
  subject do
445
445
  ::Test::ResourceFindRequest.new(:widget_bytes => [bytes])
446
446
  end
447
447
 
448
- specify { expect(subject.to_json(:lower_camel_case => true)).to eq '{"widgetBytes":["Bo0xSFAXOmI="]}' }
448
+ specify { expect(subject.to_json(:proto3 => true)).to eq '{"widgetBytes":["Bo0xSFAXOmI="]}' }
449
449
  end
450
450
  end
451
451
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.4
4
+ version: 3.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Neilsen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-01-08 00:00:00.000000000 Z
14
+ date: 2020-02-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport