Module: TestProf::LetItBe::Freezer
- Defined in:
- lib/test_prof/recipes/rspec/let_it_be.rb
Defined Under Namespace
Modules: Stoplist
Class Method Summary collapse
-
.deep_freeze(record) ⇒ Object
Rerucsively freezes the object to detect modifications.
Class Method Details
.deep_freeze(record) ⇒ Object
Rerucsively freezes the object to detect modifications
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/test_prof/recipes/rspec/let_it_be.rb', line 192 def deep_freeze(record) return if record.frozen? return if Stoplist.stop?(record) record.freeze # Support `let_it_be` with `create_list` return record.each { |rec| deep_freeze(rec) } if record.respond_to?(:each) # Freeze associations as well. return unless defined?(::ActiveRecord::Base) return unless record.is_a?(::ActiveRecord::Base) record.class.reflections.keys.each do |reflection| # But only if they are already loaded. If not yet loaded, they weren't # created by factories, and it's ok to mutate them. next unless record.association(reflection.to_sym).loaded? target = record.association(reflection.to_sym).target deep_freeze(target) if target.is_a?(::ActiveRecord::Base) || target.respond_to?(:each) end end |