Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Feb 8, 2012
1 parent 34c1bf9 commit 852eea8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/factory_girl/factory.rb
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/null_factory.rb
Expand Up @@ -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
11 changes: 8 additions & 3 deletions spec/factory_girl/factory_spec.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/factory_girl/null_factory_spec.rb
Expand Up @@ -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 }
Expand Down

0 comments on commit 852eea8

Please sign in to comment.