Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a Railtie for initialization. Automatically load under Rails 2.…

…* and 3.*
  • Loading branch information...
commit 3ae597b2490837658f2903c9250eba96a4027abb 1 parent c1a8d77
Jon Yurek jyurek authored
2  factory_girl.gemspec
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
using factories - less error-prone, more explicit, and
all-around easier to work with than fixtures.}
- s.files = Dir['[A-Z]*', 'lib/**/*.rb', 'spec/**/*.rb', 'features/**/*']
+ s.files = Dir['[A-Z]*', 'lib/**/*.rb', 'spec/**/*.rb', 'features/**/*', 'rails/**/*']
s.require_path = 'lib'
s.test_files = Dir['spec/**/*_spec.rb', 'features/**/*']
14 lib/factory_girl.rb
View
@@ -11,6 +11,7 @@
require 'factory_girl/attribute/callback'
require 'factory_girl/sequence'
require 'factory_girl/aliases'
+require 'factory_girl/railtie'
# Shortcut for Factory.default_strategy.
#
@@ -19,16 +20,3 @@
def Factory (name, attrs = {})
Factory.default_strategy(name, attrs)
end
-
-if defined? Rails.configuration
- Rails.configuration.after_initialize do
- Factory.definition_file_paths = [
- File.join(Rails.root, 'test', 'factories'),
- File.join(Rails.root, 'spec', 'factories')
- ]
- Factory.find_definitions
- end
-else
- Factory.find_definitions
-end
-
2  lib/factory_girl/factory.rb
View
@@ -1,5 +1,5 @@
class Factory
- VERSION = "1.2.4"
+ VERSION = "1.2.5.beta1"
# Raised when a factory is defined that attempts to instantiate itself.
class AssociationDefinitionError < RuntimeError
0  lib/factory_girl/rails.rb
View
No changes.
22 lib/factory_girl/railtie.rb
View
@@ -0,0 +1,22 @@
+require 'factory_girl'
+
+class Factory
+ if defined? Rails::Railtie
+ require 'rails'
+ class Railtie < Rails::Railtie
+ config.after_initialize do
+ Factory::Railtie.configure
+ end
+ end
+ end
+
+ class Railtie
+ def self.configure
+ Factory.definition_file_paths = [
+ File.join(Rails.root, 'test', 'factories'),
+ File.join(Rails.root, 'spec', 'factories')
+ ]
+ Factory.find_definitions
+ end
+ end
+end
2  rails/init.rb
View
@@ -0,0 +1,2 @@
+require 'factory_girl/railtie'
+Factory::Railtie.configure

2 comments on commit 3ae597b

Alexander Sviridov

Hello!
Excuse me for lame question... does this code mean that Factory.find_definitions will run in production environment as well as in test?
Thank you!

Jon Yurek
Admin

It will run if the gem is included, so if you include factory_girl in your production environment yes. You shouldn't, though.

Please sign in to comment.
Something went wrong with that request. Please try again.