Skip to content

Commit

Permalink
Add spec for recursive messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fetburner committed Sep 6, 2023
1 parent bfb28a5 commit 9760257
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/examples/recursive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
RSpec.describe 'recursive models' do
module self::Sandbox
class StringListSerializer < Pb::Serializer::Base
message TestFixture::Recursive::StringList

attribute :car
attribute :cdr, allow_nil: true, serializer: StringListSerializer
end

StringList = Struct.new(:car, :cdr)
end

let(:sandbox) { self.class::Sandbox }

it "serializes recursive ruby object into protobuf type" do
l = sandbox::StringList.new(
"Alpha",
sandbox::StringList.new(
"Bravo",
sandbox::StringList.new(
"Charlie",
nil,
),
),
)
pb = sandbox::StringListSerializer.new(l).to_pb

expect(pb).to be_a(TestFixture::Recursive::StringList)
expect(pb.car).to eq "Alpha"
expect(pb.cdr.car).to eq "Bravo"
expect(pb.cdr.cdr.car).to eq "Charlie"
end
end
10 changes: 10 additions & 0 deletions spec/fixtures/recursive_model.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package example.recursive;

option ruby_package = "TestFixture::Recursive";

message StringList {
string car = 1;
StringList cdr = 2;
}
38 changes: 38 additions & 0 deletions spec/fixtures/recursive_model_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9760257

Please sign in to comment.