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:
parent
38008882ee
commit
9392281bab
2 changed files with 8 additions and 3 deletions
|
@ -154,7 +154,8 @@ module FactoryGirl
|
||||||
@child_factories << [name, options, block]
|
@child_factories << [name, options, block]
|
||||||
end
|
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))
|
@factory.define_attribute_group(AttributeGroup.new(name, &block))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe "an instance generated by a factory with multiple attribute groups" do
|
||||||
factory :user do
|
factory :user do
|
||||||
name "John"
|
name "John"
|
||||||
|
|
||||||
attr_group :admin do
|
attr_group :admin, :factory=>true do
|
||||||
admin true
|
admin true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ describe "an instance generated by a factory with multiple attribute groups" do
|
||||||
gender "Female"
|
gender "Female"
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :admin, :attr_groups => [:admin]
|
|
||||||
factory :male, :attr_groups => [:male]
|
factory :male, :attr_groups => [:male]
|
||||||
factory :female, :attr_groups => [:female] do
|
factory :female, :attr_groups => [:female] do
|
||||||
attr_group :admin 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(:name) { should == "Bill" }
|
||||||
its(:email) { should == "Bill@example.com"}
|
its(:email) { should == "Bill@example.com"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "factory created from attribute group" do
|
||||||
|
subject { FactoryGirl.create(:admin) }
|
||||||
|
it { should be_admin }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue