Skip to content

Commit

Permalink
Moved definition loading syntax out of the factory class; moved every…
Browse files Browse the repository at this point in the history
…thing into a FactoryGirl module
  • Loading branch information
jferris committed Jul 7, 2010
1 parent 2a39afe commit 8b4a6a1
Show file tree
Hide file tree
Showing 44 changed files with 652 additions and 660 deletions.
2 changes: 1 addition & 1 deletion factory_girl.gemspec
Expand Up @@ -2,7 +2,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'factory_girl'
Gem::Specification.new do |s|
s.name = %q{factory_girl}
s.version = Factory::VERSION
s.version = FactoryGirl::VERSION
s.summary = %q{factory_girl provides a framework and DSL for defining and
using model instance factories.}
s.description = %q{factory_girl provides a framework and DSL for defining and
Expand Down
3 changes: 2 additions & 1 deletion lib/factory_girl.rb
Expand Up @@ -13,8 +13,9 @@
require 'factory_girl/aliases'
require 'factory_girl/definition_proxy'
require 'factory_girl/syntax/default'
require 'factory_girl/find_definitions'

class Factory
module FactoryGirl
VERSION = "1.3.1"
end

Expand Down
33 changes: 2 additions & 31 deletions lib/factory_girl/aliases.rb
@@ -1,4 +1,4 @@
class Factory
module FactoryGirl

class << self
attr_accessor :aliases #:nodoc:
Expand All @@ -8,35 +8,7 @@ class << self
[/(.*)/, '\1_id']
]

# Defines a new alias for attributes.
#
# Arguments:
# * pattern: +Regexp+
# A pattern that will be matched against attributes when looking for
# aliases. Contents captured in the pattern can be used in the alias.
# * replace: +String+
# The alias that results from the matched pattern. Captured strings can
# be substituted like with +String#sub+.
#
# Example:
#
# Factory.alias /(.*)_confirmation/, '\1'
#
# factory_girl starts with aliases for foreign keys, so that a :user
# association can be overridden by a :user_id parameter:
#
# Factory.define :post do |p|
# p.association :user
# end
#
# # The user association will not be built in this example. The user_id
# # will be used instead.
# Factory(:post, :user_id => 1)
def self.alias (pattern, replace)
self.aliases << [pattern, replace]
end

def self.aliases_for (attribute) #:nodoc:
def self.aliases_for(attribute) #:nodoc:
aliases.collect do |params|
pattern, replace = *params
if pattern.match(attribute.to_s)
Expand All @@ -46,5 +18,4 @@ def self.aliases_for (attribute) #:nodoc:
end
end.compact << attribute
end

end
2 changes: 1 addition & 1 deletion lib/factory_girl/attribute.rb
@@ -1,4 +1,4 @@
class Factory
module FactoryGirl

# Raised when defining an invalid attribute:
# * Defining an attribute which has a name ending in "="
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/attribute/association.rb
@@ -1,4 +1,4 @@
class Factory
module FactoryGirl
class Attribute #:nodoc:

class Association < Attribute #:nodoc:
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/attribute/callback.rb
@@ -1,4 +1,4 @@
class Factory
module FactoryGirl
class Attribute #:nodoc:

class Callback < Attribute #:nodoc:
Expand Down
4 changes: 2 additions & 2 deletions lib/factory_girl/attribute/dynamic.rb
@@ -1,4 +1,4 @@
class Factory
module FactoryGirl
class Attribute #:nodoc:

class Dynamic < Attribute #:nodoc:
Expand All @@ -9,7 +9,7 @@ def initialize(name, block)

def add_to(proxy)
value = @block.arity.zero? ? @block.call : @block.call(proxy)
if Factory::Sequence === value
if FactoryGirl::Sequence === value
raise SequenceAbuseError
end
proxy.set(name, value)
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/attribute/static.rb
@@ -1,4 +1,4 @@
class Factory
module FactoryGirl
class Attribute #:nodoc:

class Static < Attribute #:nodoc:
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/definition_proxy.rb
@@ -1,4 +1,4 @@
class Factory
module FactoryGirl
class DefinitionProxy
instance_methods.each do |method|
undef_method(method) unless method =~ /(^__|^nil\?$|^send$|^object_id$|^extend$|^instance_eval$)/
Expand Down

0 comments on commit 8b4a6a1

Please sign in to comment.