Sha256: 071e60a4817771b3131b13729f1a94b61b4ca6e04f930f4f56732fab16335510

Contents?: true

Size: 1.34 KB

Versions: 16

Compression:

Stored size: 1.34 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
    expect(FactoryGirl.build(:male_user).gender).to eq "Male"
  end

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

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

    expect(FactoryGirl.build(:male_user).gender).to eq "Male"
    expect(FactoryGirl.build(:male_user).age).to eq 20
    expect(FactoryGirl.build(:male_user).admin).to eq true
  end
end

Version data entries

16 entries across 13 versions & 5 rubygems

Version Path
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/factory_girl-4.5.0/spec/acceptance/modify_inherited_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/modify_inherited_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/modify_inherited_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/modify_inherited_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/spec/acceptance/modify_inherited_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/spec/acceptance/modify_inherited_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/spec/acceptance/modify_inherited_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/spec/acceptance/modify_inherited_spec.rb
factory_girl-4.5.0 spec/acceptance/modify_inherited_spec.rb
factory_girl-4.4.0 spec/acceptance/modify_inherited_spec.rb
factory_girl-4.3.0 spec/acceptance/modify_inherited_spec.rb
challah-1.0.0 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/modify_inherited_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/modify_inherited_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/modify_inherited_spec.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/modify_inherited_spec.rb
factory_girl-4.2.0 spec/acceptance/modify_inherited_spec.rb