2010-11-12 15:58:25 -05:00
|
|
|
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
|
|
|
|
|
2011-01-19 19:47:49 -05:00
|
|
|
subject { FactoryGirl.create(:admin) }
|
2010-11-12 15:58:25 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|