Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: better ruby from_* support in well_known_types.rb #8254

Conversation

jufemaiz
Copy link
Contributor

@jufemaiz jufemaiz commented Feb 3, 2021

  • Added capability to support from_* requests properly by adding class methods and returning self for instance methods
    • Timestamp.from_time
    • Value.from_ruby

Related PR: #6685 (abandoned by author)


Note

  • Make sure that all tests are passing before approval.
  • Apply the "release notes: yes" label if the pull request's description should be included in the next release (e.g., any new feature / bug fix). Apply the "release notes: no" label if the pull request's description should not be included in the next release (e.g., refactoring changes that does not change behavior, integration from Google internal, updating tests, etc.).
  • Apply the appropriate language label (e.g., C++, Java, Python, etc.) to the pull request. This will make it easier to identify which languages the pull request affects, allowing us to better identify appropriate reviewer, create a better release note, and make it easier to identify issues in the future.

I do not appear to be able to add any labels. CONTRIBUTING.md should be updated if this is the case.

@google-cla google-cla bot added the cla: yes label Feb 3, 2021
* Added capability to support from_* requests properly by adding class methods and returning self for instance methods
    * `Timestamp.from_time`
    * `Value.from_ruby`
@jufemaiz jufemaiz force-pushed the feature/ruby-better-from_-support-well_known_types branch from a8f0c75 to ef70acb Compare February 3, 2021 01:49
Copy link

@DerekStride DerekStride left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a great addition to me!

@jufemaiz
Copy link
Contributor Author

jufemaiz commented Feb 9, 2021

@haberman you seem to be the lead for Ruby, would you mind reviewing and indicating any changes that Google would like to see?

@deannagarcia
Copy link
Member

Sorry for the delay and thanks for your contribution. I just merged #8562 which had a similar fix for Timestamp.from_time. If there's still more here that you would like to add, please resolve the conflicts and I can run the tests again.

@jufemaiz
Copy link
Contributor Author

@deannagarcia can you please review regarding the addition of a class method and the return of self on the instance method (it's not a ! method so I would expect to receive self back a opposed to value of or similar).

@deannagarcia
Copy link
Member

The tests are failing with this message: Failure: test_timestamp(TestWellKnownTypes) /tmp/protobuf/protobuf/ruby/tests/well_known_types_test.rb:36:in test_timestamp 33: time = Time.at(123456, Rational(654321321, 1000)) 34: ts = Google::Protobuf::Timestamp.from_time(time) 35: assert_equal 123456, ts.seconds => 36: assert_equal 654321000, ts.nanos 37: assert_equal time, ts.to_time 38: 39: # Instance method returns the same value as class method <654321000> expected but was <654321321>

@deannagarcia
Copy link
Member

I think tests should pass now, can you add new tests for the from_ruby method and then I can get this merged?

@deannagarcia
Copy link
Member

Thanks for the tests! Getting this error now: Failure: test_from_ruby(TestWellKnownTypes) /tmp/protobuf/protobuf/ruby/tests/well_known_types_test.rb:221:in `test_from_ruby' 218: 219: def test_from_ruby 220: pb = Google::Protobuf::Value.from_ruby(nil) => 221: assert_equal pb.null_value, 0 222: 223: pb = Google::Protobuf::Value.from_ruby(1.23) 224: assert_equal pb.number_value, 1.23 <:NULL_VALUE> expected but was <0>

ruby/tests/well_known_types_test.rb Outdated Show resolved Hide resolved
@deannagarcia
Copy link
Member

Awesome, this is passing all tests now so I'm going to go ahead and merge it. Thank you for your contribution!

@deannagarcia deannagarcia merged commit 85c4bc4 into protocolbuffers:master Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants