Module: FrozenRecord::TestHelper

Defined in:
lib/frozen_record/test_helper.rb

Constant Summary collapse

NoFixturesLoaded =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.load_fixture(model_class, alternate_base_path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/frozen_record/test_helper.rb', line 8

def load_fixture(model_class, alternate_base_path)
  @cache ||= {}

  ensure_model_class_is_frozenrecord(model_class)

  return if @cache.key?(model_class)

  @cache[model_class] = base_path_if_file_present(model_class)

  model_class.base_path = alternate_base_path
  model_class.load_records(force: true)
end

.unload_fixture(model_class) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/frozen_record/test_helper.rb', line 21

def unload_fixture(model_class)
  return unless defined?(@cache) && @cache

  ensure_model_class_is_frozenrecord(model_class)

  return unless @cache.key?(model_class)

  old_base_path = @cache[model_class]
  if old_base_path
    model_class.base_path = old_base_path
    model_class.load_records(force: true)
  end
  @cache.delete(model_class)
end

.unload_fixturesObject



36
37
38
39
40
# File 'lib/frozen_record/test_helper.rb', line 36

def unload_fixtures
  return unless defined?(@cache) && @cache

  @cache.keys.each { |model_class| unload_fixture(model_class) }
end