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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/test_prof/recipes/rspec/let_it_be.rb', line 173 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 |