mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
39 lines
838 B
Ruby
39 lines
838 B
Ruby
require 'spec_helper'
|
|
require 'acceptance/acceptance_helper'
|
|
|
|
describe "an instance generated by a factory that inherits from another factory" do
|
|
before do
|
|
define_model("User", :name => :string, :admin => :boolean, :email => :string)
|
|
|
|
FactoryGirl.define do
|
|
factory :user do
|
|
name { "John" }
|
|
email { "john@example.com" }
|
|
end
|
|
|
|
factory :admin, :parent => :user do
|
|
admin { true }
|
|
email { "admin@example.com" }
|
|
end
|
|
end
|
|
end
|
|
|
|
subject { Factory.create(:admin) }
|
|
|
|
it "uses the parent build class" do
|
|
subject.should be_kind_of(User)
|
|
end
|
|
|
|
it "inherits attributes" do
|
|
subject.name.should == 'John'
|
|
end
|
|
|
|
it "has its own attributes" do
|
|
subject.should be_admin
|
|
end
|
|
|
|
it "overrides attributes" do
|
|
subject.email.should == 'admin@example.com'
|
|
end
|
|
end
|
|
|