diff options
Diffstat (limited to 'ruby')
-rw-r--r-- | ruby/README.md | 4 | ||||
-rw-r--r-- | ruby/ext/google/protobuf_c/storage.c | 16 | ||||
-rw-r--r-- | ruby/tests/repeated_field_test.rb | 6 |
3 files changed, 18 insertions, 8 deletions
diff --git a/ruby/README.md b/ruby/README.md index f28e05a7..78e86015 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -16,10 +16,6 @@ install it as you would any other gem: $ gem install [--prerelease] google-protobuf -The `--pre` flag is necessary if we have not yet made a non-alpha/beta release -of the Ruby extension; it allows `gem` to consider these "pre-release" -alpha/beta versions. - Once the gem is installed, you may or may not need `protoc`. If you write your message type descriptions directly in the Ruby DSL, you do not need it. However, if you wish to generate the Ruby DSL from a `.proto` file, you will diff --git a/ruby/ext/google/protobuf_c/storage.c b/ruby/ext/google/protobuf_c/storage.c index 24064dfd..1437c0b5 100644 --- a/ruby/ext/google/protobuf_c/storage.c +++ b/ruby/ext/google/protobuf_c/storage.c @@ -606,12 +606,20 @@ static void check_repeated_field_type(VALUE val, const upb_fielddef* field) { rb_raise(rb_eTypeError, "Repeated field array has wrong element type"); } - if (self->field_type == UPB_TYPE_MESSAGE || - self->field_type == UPB_TYPE_ENUM) { + if (self->field_type == UPB_TYPE_MESSAGE) { if (self->field_type_class != - get_def_obj(upb_fielddef_subdef(field))) { + Descriptor_msgclass(get_def_obj(upb_fielddef_subdef(field)))) { rb_raise(rb_eTypeError, - "Repeated field array has wrong message/enum class"); + "Repeated field array has wrong message class"); + } + } + + + if (self->field_type == UPB_TYPE_ENUM) { + if (self->field_type_class != + EnumDescriptor_enummodule(get_def_obj(upb_fielddef_subdef(field)))) { + rb_raise(rb_eTypeError, + "Repeated field array has wrong enum class"); } } } diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 25727b7b..b64c3991 100644 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -126,6 +126,12 @@ class RepeatedFieldTest < Test::Unit::TestCase assert_equal false, m.repeated_string.empty? end + def test_reassign + m = TestMessage.new + m.repeated_msg = Google::Protobuf::RepeatedField.new(:message, TestMessage2, [TestMessage2.new(:foo => 1)]) + assert_equal m.repeated_msg.first, TestMessage2.new(:foo => 1) + end + def test_array_accessor m = TestMessage.new reference_arr = %w(foo bar baz) |