Sha256: de27a97e5d58fe1e8214a4213ef385cabb04968eb0133542ca1d8751c23fbe04

Contents?: true

Size: 842 Bytes

Versions: 4

Compression:

Stored size: 842 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" }
      end

      factory :admin, :parent => :user do
        admin { true }
        email { "admin@example.com" }
      end
    end
  end

  subject { FactoryGirl.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

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
factory_girl-2.0.0.beta3 spec/acceptance/parent_spec.rb
factory_girl_kibiz0r-2.0.0.beta3 spec/acceptance/parent_spec.rb
factory_girl_kibiz0r-2.0.0.beta2 spec/acceptance/parent_spec.rb
factory_girl-2.0.0.beta2 spec/acceptance/parent_spec.rb