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
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/test_prof/recipes/rspec/let_it_be.rb', line 160 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 |