1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Add ability to create factory from attr_group

This commit is contained in:
Thomas Walpole 2011-08-10 11:17:30 -07:00 committed by Joshua Clayton
parent 38008882ee
commit 9392281bab
2 changed files with 8 additions and 3 deletions

View file

@ -154,7 +154,8 @@ module FactoryGirl
@child_factories << [name, options, block]
end
def attr_group(name, &block)
def attr_group(name, options={}, &block)
factory(name, &block) if options.delete(:factory)
@factory.define_attribute_group(AttributeGroup.new(name, &block))
end
end

View file

@ -9,7 +9,7 @@ describe "an instance generated by a factory with multiple attribute groups" do
factory :user do
name "John"
attr_group :admin do
attr_group :admin, :factory=>true do
admin true
end
@ -23,7 +23,6 @@ describe "an instance generated by a factory with multiple attribute groups" do
gender "Female"
end
factory :admin, :attr_groups => [:admin]
factory :male, :attr_groups => [:male]
factory :female, :attr_groups => [:female] do
attr_group :admin do
@ -113,4 +112,9 @@ describe "an instance generated by a factory with multiple attribute groups" do
its(:name) { should == "Bill" }
its(:email) { should == "Bill@example.com"}
end
context "factory created from attribute group" do
subject { FactoryGirl.create(:admin) }
it { should be_admin }
end
end