Repository navigation
Add test coverage for ActiveModel::Type::Binary - #58335
Merged
byroot merged 1 commit intoAug 10, 2026
Merged
Conversation
Only `cast` and `serialize` were exercised by Active Model's own suite. Line coverage over `activemodel/test/cases/` showed `type`, `binary?`, the `Data` branch of `cast`, `changed_in_place?`, and `Data#hex` all unreached. Adds coverage for: * `type` and `binary?`. * `serialize` returning `nil` for `nil`, and a `Binary::Data` otherwise. * `cast` unwrapping a `Binary::Data` back to its binary-encoded string. * `changed_in_place?` comparing the deserialized old value. * `Data#hex`, `#to_s`/`#to_str`, and comparison against a raw string. This brings `active_model/type/binary.rb` to full line coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ActiveModel::Type::Binary's own test file coveredcastandserializeonly. Running line coverage overactivemodel/test/cases/showedactive_model/type/binary.rbat 25/31 lines, with these unreached:typeandbinary?Databranch ofcast:changed_in_place?Data#hexTests added
test_type_and_binary_predicate—typeis:binaryandbinary?is true.test_serialize_returns_binary_data—nilpasses through; other values come back wrapped inBinary::Data.test_cast_binary_data_returns_the_underlying_string— round-trips a serialized value back throughcast, asserting theDatabranch returns the binary-encoded string.test_changed_in_place— true when the deserialized old value differs, false when it matches.test_data_hex_and_string_conversion—Data#hexon non-UTF-8 bytes, plusto_s/to_strand comparison against a raw string.No behavior changes — tests only, so no CHANGELOG entry.
active_model/type/binary.rbgoes from 25/31 to full line coverage.activemodel/test/cases/: 1199 runs, 5375 assertions, 0 failures, 0 errors. RuboCop clean.