mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Added a Railtie for initialization. Automatically load under Rails 2.* and 3.*
This commit is contained in:
parent
c1a8d772c5
commit
3ae597b249
6 changed files with 27 additions and 15 deletions
|
@ -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/**/*']
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ require 'factory_girl/attribute/association'
|
|||
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 @@ require 'factory_girl/aliases'
|
|||
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
|
||||
|
||||
|
|
|
@ -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
Normal file
0
lib/factory_girl/rails.rb
Normal file
22
lib/factory_girl/railtie.rb
Normal file
22
lib/factory_girl/railtie.rb
Normal file
|
@ -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
Normal file
2
rails/init.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
require 'factory_girl/railtie'
|
||||
Factory::Railtie.configure
|
Loading…
Add table
Reference in a new issue