mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Style cleanup
This commit is contained in:
parent
90f0072f84
commit
d8db256664
5 changed files with 25 additions and 32 deletions
|
@ -5,24 +5,6 @@ module FactoryGirl
|
||||||
class Evaluator
|
class Evaluator
|
||||||
class_attribute :attribute_lists
|
class_attribute :attribute_lists
|
||||||
|
|
||||||
def self.attribute_list
|
|
||||||
AttributeList.new.tap do |list|
|
|
||||||
attribute_lists.each do |attribute_list|
|
|
||||||
list.apply_attributes attribute_list.to_a
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.define_attribute(name, &block)
|
|
||||||
define_method(name) do
|
|
||||||
if @cached_attributes.key?(name)
|
|
||||||
@cached_attributes[name]
|
|
||||||
else
|
|
||||||
@cached_attributes[name] = instance_exec(&block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private_instance_methods.each do |method|
|
private_instance_methods.each do |method|
|
||||||
undef_method(method) unless method =~ /^__|initialize/
|
undef_method(method) unless method =~ /^__|initialize/
|
||||||
end
|
end
|
||||||
|
@ -66,5 +48,23 @@ module FactoryGirl
|
||||||
def __override_names__
|
def __override_names__
|
||||||
@overrides.keys
|
@overrides.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.attribute_list
|
||||||
|
AttributeList.new.tap do |list|
|
||||||
|
attribute_lists.each do |attribute_list|
|
||||||
|
list.apply_attributes attribute_list.to_a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.define_attribute(name, &block)
|
||||||
|
define_method(name) do
|
||||||
|
if @cached_attributes.key?(name)
|
||||||
|
@cached_attributes[name]
|
||||||
|
else
|
||||||
|
@cached_attributes[name] = instance_exec(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
module FactoryGirl
|
module FactoryGirl
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# An Array of strings specifying locations that should be searched for
|
# An Array of strings specifying locations that should be searched for
|
||||||
# factory definitions. By default, factory_girl will attempt to require
|
# factory definitions. By default, factory_girl will attempt to require
|
||||||
|
@ -7,6 +6,7 @@ module FactoryGirl
|
||||||
# existing file will be loaded.
|
# existing file will be loaded.
|
||||||
attr_accessor :definition_file_paths
|
attr_accessor :definition_file_paths
|
||||||
end
|
end
|
||||||
|
|
||||||
self.definition_file_paths = %w(factories test/factories spec/factories)
|
self.definition_file_paths = %w(factories test/factories spec/factories)
|
||||||
|
|
||||||
def self.find_definitions #:nodoc:
|
def self.find_definitions #:nodoc:
|
||||||
|
|
|
@ -12,10 +12,6 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
|
|
||||||
class DSL
|
class DSL
|
||||||
def self.run(block)
|
|
||||||
new.instance_eval(&block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def factory(name, options = {}, &block)
|
def factory(name, options = {}, &block)
|
||||||
factory = Factory.new(name, options)
|
factory = Factory.new(name, options)
|
||||||
proxy = FactoryGirl::DefinitionProxy.new(factory.definition)
|
proxy = FactoryGirl::DefinitionProxy.new(factory.definition)
|
||||||
|
@ -36,18 +32,22 @@ module FactoryGirl
|
||||||
def trait(name, &block)
|
def trait(name, &block)
|
||||||
FactoryGirl.register_trait(Trait.new(name, &block))
|
FactoryGirl.register_trait(Trait.new(name, &block))
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
class ModifyDSL
|
|
||||||
def self.run(block)
|
def self.run(block)
|
||||||
new.instance_eval(&block)
|
new.instance_eval(&block)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ModifyDSL
|
||||||
def factory(name, options = {}, &block)
|
def factory(name, options = {}, &block)
|
||||||
factory = FactoryGirl.factory_by_name(name)
|
factory = FactoryGirl.factory_by_name(name)
|
||||||
proxy = FactoryGirl::DefinitionProxy.new(factory.definition.overridable)
|
proxy = FactoryGirl::DefinitionProxy.new(factory.definition.overridable)
|
||||||
proxy.instance_eval(&block)
|
proxy.instance_eval(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.run(block)
|
||||||
|
new.instance_eval(&block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,6 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods #:nodoc:
|
module ClassMethods #:nodoc:
|
||||||
|
|
||||||
def generate(overrides = {}, &block)
|
def generate(overrides = {}, &block)
|
||||||
ActiveSupport::Deprecation.warn "Model.generate is deprecated; use the FactoryGirl.define syntax instead", caller
|
ActiveSupport::Deprecation.warn "Model.generate is deprecated; use the FactoryGirl.define syntax instead", caller
|
||||||
instance = FactoryRunner.new(name.underscore, :build, [overrides]).run
|
instance = FactoryRunner.new(name.underscore, :build, [overrides]).run
|
||||||
|
@ -62,9 +61,7 @@ module FactoryGirl
|
||||||
yield(instance) if block_given?
|
yield(instance) if block_given?
|
||||||
instance
|
instance
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,13 +20,11 @@ module FactoryGirl
|
||||||
# This syntax was derived from Pete Yandell's machinist.
|
# This syntax was derived from Pete Yandell's machinist.
|
||||||
module Make
|
module Make
|
||||||
module ActiveRecord #:nodoc:
|
module ActiveRecord #:nodoc:
|
||||||
|
|
||||||
def self.included(base) # :nodoc:
|
def self.included(base) # :nodoc:
|
||||||
base.extend ClassMethods
|
base.extend ClassMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods #:nodoc:
|
module ClassMethods #:nodoc:
|
||||||
|
|
||||||
def make(overrides = {})
|
def make(overrides = {})
|
||||||
ActiveSupport::Deprecation.warn "Model.make is deprecated; use the FactoryGirl.define syntax instead", caller
|
ActiveSupport::Deprecation.warn "Model.make is deprecated; use the FactoryGirl.define syntax instead", caller
|
||||||
FactoryRunner.new(name.underscore, :build, [overrides]).run
|
FactoryRunner.new(name.underscore, :build, [overrides]).run
|
||||||
|
@ -36,9 +34,7 @@ module FactoryGirl
|
||||||
ActiveSupport::Deprecation.warn "Model.make! is deprecated; use the FactoryGirl.define syntax instead", caller
|
ActiveSupport::Deprecation.warn "Model.make! is deprecated; use the FactoryGirl.define syntax instead", caller
|
||||||
FactoryRunner.new(name.underscore, :create, [overrides]).run
|
FactoryRunner.new(name.underscore, :create, [overrides]).run
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue