Fix embedded factory build and chaos mode support - #66
Merged
BillyRuffian merged 2 commits intoJul 3, 2026
Conversation
added 2 commits
July 3, 2026 17:00
… validation for embedded attributes --fix: chaos attribute leaking to child factories
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.
Bug fixes in
factory.rbformanufacture_from_embedded_factoryandassert_only_known_and_optional_attributes_for_chaosmethodsNoMethodErrorwhen building factories with multiple embedded factoriesmanufacture_from_embedded_factorycalledf.attributes.map(&:name)on embedded factories. When an embedded factory itself contains embedded factories.attributesreturns a mix of Attribute objects and Hash objects. This causedNoMethodError: undefined method 'name' for an instance of Hash.Fix: Use
f.attributes(include_embeddings: false).map(&:name)which guarantees only Attribute objects are returned.NoSuchAttributeErrorwhen using chaos mode with embedded factory attributesassert_only_known_and_optional_attributes_for_chaosdidn't recognise embedded factory attribute names as valid because they are stored inside Hashes rather than as plain symbols inattribute_names.Fix: Extract attribute names from Hashes before comparison which matches the approach in
assert_only_known_attributes_for_override.manufacture_from_embedded_factorypassed thechaos:argument directly to embedded factory builds. When chaos was an array of attribute names (e.g.chaos: [:child_obj]), those parent-specific names were passed to the child factory, which then failed validation because it doesn't have attributes with those names.Fix: Convert chaos to a boolean before passing to embedded factories, so children inherit random chaos behaviour without receiving attribute names that are only relevant to the parent.
Added RSpec test coverage of: