FactoryMan.Params (Factory Man v0.5.0)

View Source

Utilities for converting Ecto structs to clean param maps.

These functions are used by the generated params_for_* and string_params_for_* factory functions. You generally don't need to call them directly.

Summary

Functions

Recursively convert atom keys to string keys. Structs and other non-map values are left untouched.

Strip Ecto metadata from a struct, returning a plain map suitable for changesets or API tests.

Functions

stringify_keys(struct)

Recursively convert atom keys to string keys. Structs and other non-map values are left untouched.

strip(record)

Strip Ecto metadata from a struct, returning a plain map suitable for changesets or API tests.

Specifically:

  • Removes __meta__ and autogenerated IDs
  • Removes belongs_to association structs (but sets FK if the association is persisted)
  • Recursively strips nested has_one/has_many associations and embeds
  • Removes Ecto.Association.NotLoaded values