Class: Pickle::Adapter::FactoryGirl

Inherits:
Pickle::Adapter show all
Defined in:
lib/pickle/adapter.rb

Overview

factory-girl adapter

Instance Attribute Summary

Attributes inherited from Pickle::Adapter

#klass, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pickle::Adapter

column_names, create_model, find_all_models, find_first_model, get_model, model_classes

Constructor Details

#initialize(factory) ⇒ FactoryGirl



118
119
120
121
122
123
124
# File 'lib/pickle/adapter.rb', line 118

def initialize(factory)
  if defined? ::FactoryGirl
    @klass, @name = factory.build_class, factory.name.to_s
  else
    @klass, @name = factory.build_class, factory.factory_name.to_s
  end
end

Class Method Details

.factoriesObject



108
109
110
111
112
113
114
115
116
# File 'lib/pickle/adapter.rb', line 108

def self.factories
  if defined? ::FactoryGirl
    factories = []
    ::FactoryGirl.factories.each {|v| factories << new(v)}
    factories
  else
    (::Factory.factories.values rescue []).map {|factory| new(factory)}
  end
end

Instance Method Details

#create(attrs = {}) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/pickle/adapter.rb', line 126

def create(attrs = {})
  if defined? ::FactoryGirl
    ::FactoryGirl.create(@name, attrs)
  else
    Factory(@name, attrs)
  end
end