mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Add AttributeList#associations
This commit is contained in:
parent
7a8dcd2c37
commit
7254a81072
4 changed files with 24 additions and 2 deletions
|
@ -54,7 +54,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def association_names
|
||||
@attribute_list.select(&:association?).map(&:name)
|
||||
@attribute_list.associations.map(&:name)
|
||||
end
|
||||
|
||||
def override_names
|
||||
|
|
|
@ -18,6 +18,10 @@ module FactoryGirl
|
|||
@attributes.each(&block)
|
||||
end
|
||||
|
||||
def associations
|
||||
@attributes.select(&:association?)
|
||||
end
|
||||
|
||||
def apply_attributes(attributes_to_apply)
|
||||
attributes_to_apply.each {|attribute| add_attribute(attribute) }
|
||||
end
|
||||
|
|
|
@ -50,7 +50,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def associations
|
||||
attributes.select {|attribute| attribute.association? }
|
||||
attributes.associations
|
||||
end
|
||||
|
||||
# Names for this factory, including aliases.
|
||||
|
|
|
@ -58,3 +58,21 @@ describe FactoryGirl::AttributeList, "#apply_attributes" do
|
|||
subject.to_a.should == [full_name_attribute, login_attribute, city_attribute, email_attribute]
|
||||
end
|
||||
end
|
||||
|
||||
describe FactoryGirl::AttributeList, "#associations" do
|
||||
let(:full_name_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value", false) }
|
||||
let(:email_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, lambda {|u| "#{u.full_name}@example.com" }) }
|
||||
let(:author_attribute) { FactoryGirl::Attribute::Association.new(:author, :user, {}) }
|
||||
let(:profile_attribute) { FactoryGirl::Attribute::Association.new(:profile, :profile, {}) }
|
||||
|
||||
before do
|
||||
subject.define_attribute(full_name_attribute)
|
||||
subject.define_attribute(email_attribute)
|
||||
subject.define_attribute(author_attribute)
|
||||
subject.define_attribute(profile_attribute)
|
||||
end
|
||||
|
||||
it "returns associations" do
|
||||
subject.associations.should == [author_attribute, profile_attribute]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue