Sha256: 4440b7e7c03724274a3851b81c15511db77d70c14fa46b7d6190edcea61d97ef

Contents?: true

Size: 1.31 KB

Versions: 201

Compression:

Stored size: 1.31 KB

Contents

require "spec_helper"

describe "modifying inherited factories with traits" do
  before do
    define_model('User', gender: :string, admin: :boolean, age: :integer)
    FactoryGirl.define do
      factory :user do
        trait(:female) { gender "Female" }
        trait(:male)   { gender "Male" }

        trait(:young_admin) do
          admin true
          age   17
        end

        female
        young_admin

        factory :female_user do
          gender "Female"
          age 25
        end

        factory :male_user do
          gender "Male"
        end
      end
    end
  end

  it "returns the correct value for overridden attributes from traits" do
    FactoryGirl.build(:male_user).gender.should == "Male"
  end

  it "returns the correct value for overridden attributes from traits defining multiple attributes" do
    FactoryGirl.build(:female_user).gender.should == "Female"
    FactoryGirl.build(:female_user).age.should == 25
    FactoryGirl.build(:female_user).admin.should == true
  end

  it "allows modification of attributes created via traits" do
    FactoryGirl.modify do
      factory :male_user do
        age 20
      end
    end

    FactoryGirl.build(:male_user).gender.should == "Male"
    FactoryGirl.build(:male_user).age.should == 20
    FactoryGirl.build(:male_user).admin.should == true
  end
end

Version data entries

201 entries across 93 versions & 7 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/modify_inherited_spec.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/modify_inherited_spec.rb
challah-0.9.1.beta.3 vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/modify_inherited_spec.rb