Let Cucumber steps use inherited associations.
By making Factory#associations include the parent's associations. https://github.com/thoughtbot/factory_girl/issues/292
This commit is contained in:
parent
13129b04e1
commit
34c1bf9b70
|
@ -60,6 +60,14 @@ Feature: Use step definitions generated by factories
|
|||
| a title | 123 |
|
||||
And there should be 1 user
|
||||
|
||||
Scenario: create a titled post with a new author (inherited association)
|
||||
Given the following titled post exists:
|
||||
| Title | Author |
|
||||
| A Post with a Title | ID: 123 |
|
||||
Then I should find the following for the last post:
|
||||
| title | author_id |
|
||||
| A Post with a Title | 123 |
|
||||
|
||||
Scenario: create post with and without a category association
|
||||
Given the following users exist:
|
||||
| ID | Name |
|
||||
|
|
|
@ -99,6 +99,10 @@ FactoryGirl.define do
|
|||
category
|
||||
end
|
||||
|
||||
factory :titled_post, :parent => :post do
|
||||
title 'A Post with a Title'
|
||||
end
|
||||
|
||||
factory :tag do
|
||||
post
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def associations
|
||||
attributes.associations
|
||||
attributes.associations + parent.associations
|
||||
end
|
||||
|
||||
# Names for this factory, including aliases.
|
||||
|
|
|
@ -12,5 +12,6 @@ module FactoryGirl
|
|||
def class_name; end
|
||||
def default_strategy; :create; end
|
||||
def evaluator_class; FactoryGirl::Evaluator; end
|
||||
def associations; attributes.map(&:association?); end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,6 +48,15 @@ describe FactoryGirl::Factory do
|
|||
factory.associations.size.should == 3
|
||||
end
|
||||
|
||||
it "includes associations from the parent factory" do
|
||||
factory = FactoryGirl::Factory.new(:post)
|
||||
factory.declare_attribute(FactoryGirl::Declaration::Association.new(:author, {}))
|
||||
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
|
||||
end
|
||||
|
||||
describe "when overriding generated attributes with a hash" do
|
||||
before do
|
||||
@name = :name
|
||||
|
|
|
@ -10,5 +10,6 @@ describe FactoryGirl::NullFactory do
|
|||
its(:class_name) { should be_nil }
|
||||
its(:default_strategy) { should == :create }
|
||||
its(:attributes) { should be_an_instance_of(FactoryGirl::AttributeList) }
|
||||
its(:associations) { should be_empty }
|
||||
its(:evaluator_class) { should == FactoryGirl::Evaluator }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue