Class: Cockroach::FactoryGirl::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/cockroach/fixtures/factory_girl/loader.rb

Overview

Loader class is designed to load the FactoryGirl fixtures, defined in the project.

Class Method Summary collapse

Class Method Details

.loadObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cockroach/fixtures/factory_girl/loader.rb', line 10

def load
  if factory_items.blank?
    old_paths = ::FactoryGirl.definition_file_paths
    if Cockroach.config.fixtures_path
      ::FactoryGirl.definition_file_paths = [Cockroach.config.fixtures_path]
    else
      ::FactoryGirl.definition_file_paths = old_paths.collect { |path| File.join(Cockroach::Config.root, path) }
    end

    # Italiano spagetti
    unless ::FactoryGirl.definition_file_paths.inject(false) { |valid, path| valid || File.exists?("#{path}.rb") || File.directory?(path) }
      raise NoExistingPathError.new("Neither of the paths are valid: #{::FactoryGirl.definition_file_paths.inspect}")
    end

    ::FactoryGirl.find_definitions
    ::FactoryGirl.definition_file_paths = old_paths
  end
end

.load!Object



29
30
31
32
# File 'lib/cockroach/fixtures/factory_girl/loader.rb', line 29

def load!
  factory_items.clear
  load
end