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
|
2011-06-29 16:49:45 -04:00
|
|
|
name "John"
|
|
|
|
email "john@example.com"
|
2010-11-12 15:58:25 -05:00
|
|
|
|
2011-06-29 16:49:45 -04:00
|
|
|
factory :admin do
|
|
|
|
admin true
|
|
|
|
email "admin@example.com"
|
|
|
|
end
|
2011-07-13 09:51:51 -04:00
|
|
|
|
|
|
|
factory :guest do
|
|
|
|
email { "#{name}-guest@example.com" }
|
|
|
|
end
|
2010-11-12 15:58:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 16:49:45 -04:00
|
|
|
describe "the parent class" do
|
|
|
|
subject { FactoryGirl.create(:user) }
|
|
|
|
it { should_not be_admin }
|
|
|
|
its(:email) { should == "john@example.com" }
|
2010-11-12 15:58:25 -05:00
|
|
|
end
|
|
|
|
|
2011-06-29 16:49:45 -04:00
|
|
|
describe "the child class" do
|
|
|
|
subject { FactoryGirl.create(:admin) }
|
|
|
|
it { should be_kind_of(User) }
|
|
|
|
it { should be_admin }
|
|
|
|
its(:name) { should == "John" }
|
|
|
|
its(:email) { should == "admin@example.com" }
|
2010-11-12 15:58:25 -05:00
|
|
|
end
|
2011-07-13 09:51:51 -04:00
|
|
|
|
|
|
|
describe "the child class with parent attribute" do
|
|
|
|
subject { FactoryGirl.create(:guest) }
|
|
|
|
its(:email) { should eql "John-guest@example.com" }
|
|
|
|
end
|
2010-11-12 15:58:25 -05:00
|
|
|
end
|
|
|
|
|