mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
initial spec for attribute groups feature
This commit is contained in:
parent
40d08eeb64
commit
e39d6e6897
1 changed files with 87 additions and 0 deletions
87
spec/acceptance/attribute_groups_spec.rb
Normal file
87
spec/acceptance/attribute_groups_spec.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
require "spec_helper"
|
||||
require "acceptance/acceptance_helper"
|
||||
|
||||
describe "an instance generated by a factory with multiple attribute groups" do
|
||||
before do
|
||||
define_model("User", :name => :string, :admin => :boolean, :gender => :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
name "John"
|
||||
|
||||
attr_group :admin do
|
||||
admin true
|
||||
end
|
||||
|
||||
attr_group :male do
|
||||
gender "Male"
|
||||
end
|
||||
|
||||
attr_group :female do
|
||||
name "Jane"
|
||||
gender "Female"
|
||||
end
|
||||
|
||||
factory :admin, :attr_groups => [:admin]
|
||||
factory :male, :attr_groups => [:male]
|
||||
factory :female, :attr_groups => [:female]
|
||||
factory :female_admin, :attr_groups => [:female, :admin]
|
||||
factory :female_after_male_admin, :attr_groups => [:male, :female, :admin]
|
||||
factory :male_after_female_admin, :attr_groups => [:female, :male, :admin]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "the parent class" do
|
||||
subject { FactoryGirl.create(:user) }
|
||||
its(:name) { should == "John" }
|
||||
its(:gender) { should be_nil }
|
||||
it { should_not be_admin }
|
||||
end
|
||||
|
||||
context "the child class with one attribute group" do
|
||||
subject { FactoryGirl.create(:admin) }
|
||||
its(:name) { should == "John" }
|
||||
its(:gender) { should be_nil }
|
||||
it { should be_admin }
|
||||
end
|
||||
|
||||
context "the other child class with one attribute group" do
|
||||
subject { FactoryGirl.create(:female) }
|
||||
its(:name) { should == "Jane" }
|
||||
its(:gender) { should == "Female" }
|
||||
it { should_not be_admin }
|
||||
end
|
||||
|
||||
context "the child with multiple attribute groups" do
|
||||
subject { FactoryGirl.create(:female_admin) }
|
||||
its(:name) { should == "Jane" }
|
||||
its(:gender) { should == "Female" }
|
||||
it { should be_admin }
|
||||
end
|
||||
|
||||
context "the child with multiple attribute groups and overridden attributes" do
|
||||
subject { FactoryGirl.create(:female_admin, :name => "Jill", :gender => nil) }
|
||||
its(:name) { should == "Jill" }
|
||||
its(:gender) { should be_nil }
|
||||
it { should be_admin }
|
||||
end
|
||||
|
||||
context "the child with multiple attribute groups who override the same attribute" do
|
||||
context "when the male assigns name after female" do
|
||||
subject { FactoryGirl.create(:male_after_female_admin) }
|
||||
|
||||
its(:name) { should == "John" }
|
||||
its(:gender) { should == "Male" }
|
||||
it { should be_admin }
|
||||
end
|
||||
|
||||
context "when the female assigns name after male" do
|
||||
subject { FactoryGirl.create(:female_after_male_admin) }
|
||||
|
||||
its(:name) { should == "Jane" }
|
||||
its(:gender) { should == "Female" }
|
||||
it { should be_admin }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue