From 115378350bdd3ec03bd696a08d4f68252bf56b81 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Fri, 7 Oct 2011 16:15:15 -0400 Subject: [PATCH] More Factory reorganization and cleanup --- lib/factory_girl.rb | 9 +++++++++ lib/factory_girl/factory.rb | 38 +++++++++++++------------------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/factory_girl.rb b/lib/factory_girl.rb index cc8260104..b8ce7b6cb 100644 --- a/lib/factory_girl.rb +++ b/lib/factory_girl.rb @@ -34,6 +34,15 @@ end module FactoryGirl + # Raised when a factory is defined that attempts to instantiate itself. + class AssociationDefinitionError < RuntimeError; end + + # Raised when a callback is defined that has an invalid name + class InvalidCallbackNameError < RuntimeError; end + + # Raised when a factory is defined with the same name as a previously-defined factory. + class DuplicateDefinitionError < RuntimeError; end + def self.factories @factories ||= Registry.new end diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index 6a10ea2c0..019f09037 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -2,34 +2,9 @@ require "active_support/inflector" module FactoryGirl - # Raised when a factory is defined that attempts to instantiate itself. - class AssociationDefinitionError < RuntimeError - end - - # Raised when a callback is defined that has an invalid name - class InvalidCallbackNameError < RuntimeError - end - - # Raised when a factory is defined with the same name as a previously-defined factory. - class DuplicateDefinitionError < RuntimeError - end - class Factory attr_reader :name #:nodoc: - def factory_name - puts "WARNING: factory.factory_name is deprecated. Use factory.name instead." - name - end - - def build_class #:nodoc: - @build_class ||= class_name.to_s.camelize.constantize - end - - def default_strategy #:nodoc: - @default_strategy || (parent && parent.default_strategy) || :create - end - def initialize(name, options = {}) #:nodoc: assert_valid_options(options) @name = name.to_s.underscore.to_sym @@ -44,6 +19,19 @@ def initialize(name, options = {}) #:nodoc: @compiled = false end + def factory_name + puts "WARNING: factory.factory_name is deprecated. Use factory.name instead." + name + end + + def build_class #:nodoc: + @build_class ||= class_name.to_s.camelize.constantize + end + + def default_strategy #:nodoc: + @default_strategy || (parent && parent.default_strategy) || :create + end + def allow_overrides @compiled = false @attribute_list.overridable