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, factory_name) ⇒ FactoryGirl

Returns a new instance of FactoryGirl.



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

def initialize(factory, factory_name)
  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



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

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

Instance Method Details

#build(attrs = {}) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/pickle/adapter.rb', line 134

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

#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