Module: ActiveRecord::TestFixtures::ClassMethods

Defined in:
lib/nested_scenarios/fixtures.rb

Instance Method Summary collapse

Instance Method Details

#fixtures(*table_names) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nested_scenarios/fixtures.rb', line 58

def fixtures(*table_names)
  if table_names.first == :all
    self.root_table_names = self.load_root_fixtures ? load_table_names_in_path(self.fixture_path) : []
    self.scenario_table_names = self.scenario_path ? load_table_names_in_path(self.scenario_path) : []

    table_names = self.root_table_names + self.scenario_table_names
    table_names.uniq!
  else
    table_names = table_names.flatten.map { |n| n.to_s }
  end

  self.fixture_table_names |= table_names

  require_fixture_classes(table_names)
  setup_fixture_accessors(table_names)
end

#scenario(scenario_name = nil, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nested_scenarios/fixtures.rb', line 42

def scenario(scenario_name = nil, options = {})
  case scenario_name
    when Hash
      self.load_root_fixtures = scenario_name.delete(:root) if scenario_name.key? :root
      scenario_name = scenario_name.join('/')
    when Symbol, String
      self.load_root_fixtures = options.delete(:root) if options.key? :root
      scenario_name = scenario_name.to_s
    else
      raise ArgumentError, "Scenario must be a symbol, string or hash. You gave #{scenario_name.class}."
  end

  self.scenario_path = "#{self.fixture_path}/#{scenario_name}" if scenario_name
  self.fixtures(:all)
end