Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor code cleanup

  • Loading branch information...
commit 852eea84fff19867ce16eadad464aed2f60b16be 1 parent 34c1bf9
@joshuaclayton joshuaclayton authored
View
2  lib/factory_girl/factory.rb
@@ -53,7 +53,7 @@ def human_names
end
def associations
- attributes.associations + parent.associations
+ parent.associations + attributes.associations
end
# Names for this factory, including aliases.
View
2  lib/factory_girl/null_factory.rb
@@ -7,11 +7,11 @@ def initialize
end
delegate :defined_traits, :callbacks, :attributes, :constructor, :to => :definition
+ delegate :associations, :to => :attributes
def compile; end
def class_name; end
def default_strategy; :create; end
def evaluator_class; FactoryGirl::Evaluator; end
- def associations; attributes.map(&:association?); end
end
end
View
11 spec/factory_girl/factory_spec.rb
@@ -49,12 +49,17 @@
end
it "includes associations from the parent factory" do
+ association_on_parent = FactoryGirl::Declaration::Association.new(:association_on_parent, {})
+ association_on_child = FactoryGirl::Declaration::Association.new(:association_on_child, {})
+
factory = FactoryGirl::Factory.new(:post)
- factory.declare_attribute(FactoryGirl::Declaration::Association.new(:author, {}))
+ factory.declare_attribute(association_on_parent)
FactoryGirl.register_factory(factory)
+
child_factory = FactoryGirl::Factory.new(:child_post, :parent => :post)
- child_factory.declare_attribute(FactoryGirl::Declaration::Association.new(:editor, {}))
- child_factory.associations.size.should == 2
+ child_factory.declare_attribute(association_on_child)
+
+ child_factory.associations.map(&:name).should == [:association_on_parent, :association_on_child]
end
describe "when overriding generated attributes with a hash" do
View
1  spec/factory_girl/null_factory_spec.rb
@@ -5,6 +5,7 @@
it { should delegate(:callbacks).to(:definition) }
it { should delegate(:attributes).to(:definition) }
it { should delegate(:constructor).to(:definition) }
+ it { should delegate(:associations).to(:attributes) }
its(:compile) { should be_nil }
its(:class_name) { should be_nil }
Please sign in to comment.
Something went wrong with that request. Please try again.