Sha256: 1f79f270efe1b7bd6647bf480a718a54dbb058e93c4af7b5925308fcc0419812

Contents?: true

Size: 897 Bytes

Versions: 6

Compression:

Stored size: 897 Bytes

Contents

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"

        factory :admin do
          admin true
          email "admin@example.com"
        end
      end
    end
  end

  describe "the parent class" do
    subject     { FactoryGirl.create(:user) }
    it          { should_not be_admin }
    its(:email) { should == "john@example.com" }
  end

  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" }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
factory_girl-2.0.0.rc4 spec/acceptance/parent_spec.rb
factory_girl-2.0.0.rc3 spec/acceptance/parent_spec.rb
factory_girl-2.0.0.rc2 spec/acceptance/parent_spec.rb
factory_girl-2.0.0.rc1 spec/acceptance/parent_spec.rb
factory_girl-2.0.0.beta5 spec/acceptance/parent_spec.rb
factory_girl-2.0.0.beta4 spec/acceptance/parent_spec.rb