When testing readonly Rails models (those overriding `readonly?` to return true), creating records in tests raises `ActiveRecord::ReadOnlyRecord`. A clean solution is a `with_writable` helper that uses `class_eval` and `alias_method` to temporarily override `readonly?` to return false only within a block, then reverts it. This
Table of contents
The ProblemThe SolutionOther OptionsConclusionIf you enjoyed this post, check out these related articles next:Sort: