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
|
2011-08-08 18:59:48 -04:00
|
|
|
define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string)
|
2010-11-12 15:58:25 -05:00
|
|
|
|
|
|
|
FactoryGirl.define do
|
|
|
|
factory :user do
|
2011-06-29 16:49:45 -04:00
|
|
|
name "John"
|
2011-07-19 10:49:00 -04:00
|
|
|
email { "#{name.downcase}@example.com" }
|
2010-11-12 15:58:25 -05:00
|
|
|
|
2011-06-29 16:49:45 -04:00
|
|
|
factory :admin do
|
2011-07-19 10:49:00 -04:00
|
|
|
name "admin"
|
2011-06-29 16:49:45 -04:00
|
|
|
admin true
|
2011-08-08 18:59:48 -04:00
|
|
|
upper_email { email.upcase }
|
2011-06-29 16:49:45 -04:00
|
|
|
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-07-19 10:49:00 -04:00
|
|
|
describe "the child class redefining parent's static method used by a dynamic method" do
|
2011-08-08 18:59:48 -04:00
|
|
|
subject { FactoryGirl.create(:admin) }
|
|
|
|
it { should be_kind_of(User) }
|
|
|
|
it { should be_admin }
|
|
|
|
its(:name) { should == "admin" }
|
|
|
|
its(:email) { should == "admin@example.com" }
|
|
|
|
its(:upper_email) { should == "ADMIN@EXAMPLE.COM"}
|
2010-11-12 15:58:25 -05:00
|
|
|
end
|
2011-07-13 09:51:51 -04:00
|
|
|
|
2011-07-19 10:49:00 -04:00
|
|
|
describe "the child class redefining parent's dynamic method" do
|
2011-07-13 09:51:51 -04:00
|
|
|
subject { FactoryGirl.create(:guest) }
|
2011-07-19 10:49:00 -04:00
|
|
|
it { should_not be_admin }
|
|
|
|
its(:name) { should == "John" }
|
2011-07-13 09:51:51 -04:00
|
|
|
its(:email) { should eql "John-guest@example.com" }
|
|
|
|
end
|
2010-11-12 15:58:25 -05:00
|
|
|
end
|
|
|
|
|