Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

#19: removed ActiveSupport as a dependency

  • Loading branch information...
commit d550e709e448e3b43314f5e9ecc7f2cca09e8dca 1 parent 3eafc97
@jferris jferris authored
View
3  Rakefile
@@ -39,7 +39,7 @@ end
spec = Gem::Specification.new do |s|
s.name = %q{factory_girl}
- s.version = "1.1.4"
+ s.version = "1.1.5"
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
@@ -58,7 +58,6 @@ spec = Gem::Specification.new do |s|
s.email = %q{jferris@thoughtbot.com}
s.platform = Gem::Platform::RUBY
- s.add_dependency(%q<activesupport>, [">= 1.0"])
end
Rake::GemPackageTask.new spec do |pkg|
View
9 factory_girl.gemspec
@@ -2,15 +2,15 @@
Gem::Specification.new do |s|
s.name = %q{factory_girl}
- s.version = "1.1.4"
+ s.version = "1.1.5"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Joe Ferris"]
- s.date = %q{2008-11-28}
+ s.date = %q{2008-12-11}
s.description = %q{factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.}
s.email = %q{jferris@thoughtbot.com}
s.extra_rdoc_files = ["README.textile"]
- s.files = ["Changelog", "LICENSE", "Rakefile", "README.textile", "lib/factory_girl/aliases.rb", "lib/factory_girl/attribute.rb", "lib/factory_girl/attribute_proxy.rb", "lib/factory_girl/factory.rb", "lib/factory_girl/sequence.rb", "lib/factory_girl.rb", "test/aliases_test.rb", "test/attribute_proxy_test.rb", "test/attribute_test.rb", "test/factory_test.rb", "test/integration_test.rb", "test/models.rb", "test/sequence_test.rb", "test/test_helper.rb"]
+ s.files = ["Changelog", "CONTRIBUTION_GUIDELINES.rdoc", "LICENSE", "Rakefile", "README.textile", "lib/factory_girl/aliases.rb", "lib/factory_girl/attribute.rb", "lib/factory_girl/attribute_proxy.rb", "lib/factory_girl/factory.rb", "lib/factory_girl/sequence.rb", "lib/factory_girl.rb", "test/aliases_test.rb", "test/attribute_proxy_test.rb", "test/attribute_test.rb", "test/factory_test.rb", "test/integration_test.rb", "test/models.rb", "test/sequence_test.rb", "test/test_helper.rb"]
s.has_rdoc = true
s.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.textile"]
s.require_paths = ["lib"]
@@ -23,11 +23,8 @@ Gem::Specification.new do |s|
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<activesupport>, [">= 1.0"])
else
- s.add_dependency(%q<activesupport>, [">= 1.0"])
end
else
- s.add_dependency(%q<activesupport>, [">= 1.0"])
end
end
View
4 lib/factory_girl/aliases.rb
@@ -1,6 +1,8 @@
class Factory
- cattr_accessor :aliases #:nodoc:
+ class << self
+ attr_accessor :aliases #:nodoc:
+ end
self.aliases = [
[/(.*)_id/, '\1'],
[/(.*)/, '\1_id']
View
58 lib/factory_girl/factory.rb
@@ -1,13 +1,16 @@
class Factory
- cattr_accessor :factories #:nodoc:
- self.factories = {}
+ class << self
+ attr_accessor :factories #:nodoc:
+
+ # An Array of strings specifying locations that should be searched for
+ # factory definitions. By default, factory_girl will attempt to require
+ # "factories," "test/factories," and "spec/factories." Only the first
+ # existing file will be loaded.
+ attr_accessor :definition_file_paths
+ end
- # An Array of strings specifying locations that should be searched for
- # factory definitions. By default, factory_girl will attempt to require
- # "factories," "test/factories," and "spec/factories." Only the first
- # existing file will be loaded.
- cattr_accessor :definition_file_paths
+ self.factories = {}
self.definition_file_paths = %w(factories test/factories spec/factories)
attr_reader :factory_name
@@ -36,7 +39,7 @@ def build_class #:nodoc:
end
def initialize (name, options = {}) #:nodoc:
- options.assert_valid_keys(:class)
+ assert_valid_options(options)
@factory_name = factory_name_for(name)
@options = options
@attributes = []
@@ -111,7 +114,7 @@ def method_missing (name, *args, &block)
# default use the "user" factory.
def association (name, options = {})
name = name.to_sym
- options = options.symbolize_keys
+ options = symbolize_keys(options)
association_factory = options[:factory] || name
add_attribute(name) {|a| a.association(association_factory) }
@@ -203,7 +206,7 @@ def factory_by_name (name)
private
def build_attributes_hash (values, strategy)
- values = values.symbolize_keys
+ values = symbolize_keys(values)
passed_keys = values.keys.collect {|key| Factory.aliases_for(key) }.flatten
@attributes.each do |attribute|
unless passed_keys.include?(attribute.name)
@@ -225,7 +228,7 @@ def build_instance (override, strategy)
def class_for (class_or_to_s)
if class_or_to_s.respond_to?(:to_sym)
- class_or_to_s.to_s.pluralize.classify.constantize
+ Object.const_get(variable_name_to_class_name(class_or_to_s))
else
class_or_to_s
end
@@ -235,7 +238,7 @@ def factory_name_for (class_or_to_s)
if class_or_to_s.respond_to?(:to_sym)
class_or_to_s.to_sym
else
- class_or_to_s.to_s.underscore.to_sym
+ class_name_to_variable_name(class_or_to_s).to_sym
end
end
@@ -243,4 +246,35 @@ def attribute_defined? (name)
!@attributes.detect {|attr| attr.name == name }.nil?
end
+ def assert_valid_options(options)
+ invalid_keys = options.keys - [:class]
+ unless invalid_keys == []
+ raise ArgumentError, "Unknown arguments: #{invalid_keys.inspect}"
+ end
+ end
+
+ # Based on ActiveSupport's underscore inflector
+ def class_name_to_variable_name(name)
+ name.to_s.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
+
+ # Based on ActiveSupport's camelize inflector
+ def variable_name_to_class_name(name)
+ name.to_s.
+ gsub(/\/(.?)/) { "::#{$1.upcase}" }.
+ gsub(/(?:^|_)(.)/) { $1.upcase }
+ end
+
+ # From ActiveSupport
+ def symbolize_keys(hash)
+ hash.inject({}) do |options, (key, value)|
+ options[(key.to_sym rescue key) || key] = value
+ options
+ end
+ end
+
end
View
4 lib/factory_girl/sequence.rb
@@ -15,7 +15,9 @@ def next
end
- cattr_accessor :sequences #:nodoc:
+ class << self
+ attr_accessor :sequences #:nodoc:
+ end
self.sequences = {}
# Defines a new sequence that can be used to generate unique values in a specific format.
View
2  test/factory_test.rb
@@ -337,7 +337,7 @@ def self.should_instantiate_class
end
- should "raise an ActiveRecord::RecordInvalid error for invalid instances" do
+ should "raise an error for invalid instances" do
assert_raise(ActiveRecord::RecordInvalid) do
@factory.create(:first_name => nil)
end
View
2  test/integration_test.rb
@@ -28,7 +28,7 @@ def setup
end
def teardown
- Factory.send(:class_variable_get, "@@factories").clear
+ Factory.factories.clear
end
context "a generated attributes hash" do

3 comments on commit d550e70

@nbibler

There still appears to be a require dependency for active_support in lib/factory_girl.rb at line 1 (link). Was that intended?

@sickill

I also noticed this require 'active_support' in lib/factory_girl.rb. I'd like to use FG with Merb/DataMapper app and I don't want activesupport (which will probably collide with extlib). Can we remove this require?

@sickill

I've commented out this require and FG loads without problems. Defining simple factory also works. I haven't done more deep tests though.

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